From e39414d975b82ddd963f4147b41085c87fe636a8 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Fri, 18 Nov 2022 02:20:40 +0300 Subject: [PATCH] search-wip, bio fix --- src/components/Author/Card.tsx | 6 +++- src/components/Views/Search.tsx | 59 ++++++++++++++++++++++++--------- src/locales/ru.json | 3 +- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/components/Author/Card.tsx b/src/components/Author/Card.tsx index 7cd3131a..670ddcbe 100644 --- a/src/components/Author/Card.tsx +++ b/src/components/Author/Card.tsx @@ -30,7 +30,11 @@ export const AuthorCard = (props: AuthorCardProps) => { () => session()?.news?.authors?.some((u) => u === props.author.slug) || false ) const canFollow = createMemo(() => !props.hideFollow && session()?.user?.slug !== props.author.slug) - const bio = () => props.author.bio || t('Our regular contributor') + const bio = () => { + const d = document.createElement('div') + d.innerHTML = props.author.bio + return d.innerText || t('Our regular contributor') + } const name = () => { return props.author.name === 'Дискурс' && locale() !== 'ru' ? 'Discours' diff --git a/src/components/Views/Search.tsx b/src/components/Views/Search.tsx index a3bbfd1f..062076c9 100644 --- a/src/components/Views/Search.tsx +++ b/src/components/Views/Search.tsx @@ -4,6 +4,7 @@ import type { Shout } from '../../graphql/types.gen' import { ArticleCard } from '../Feed/Card' import { t } from '../../utils/intl' import { useArticlesStore, loadShoutsBy } from '../../stores/zine/articles' +import { restoreScrollPosition, saveScrollPosition } from '../../utils/scroll' import { useRouter } from '../../stores/router' type SearchPageSearchParams = { @@ -15,31 +16,49 @@ type Props = { results: Shout[] } +const LOAD_MORE_PAGE_SIZE = 50 + export const SearchView = (props: Props) => { const { sortedArticles } = useArticlesStore({ shouts: props.results }) - const [getQuery, setQuery] = createSignal(props.query) + const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) + const [query, setQuery] = createSignal(props.query) + const [offset, setOffset] = createSignal(0) const { searchParams, handleClientRouteLinkClick } = useRouter() - - const handleQueryChange = (ev) => { - setQuery(ev.target.value) + let searchEl: HTMLInputElement + const handleQueryChange = (_ev) => { + setQuery(searchEl.value) } - const handleSubmit = (_ev) => { - // TODO page - // TODO sort - loadShoutsBy({ by: { title: getQuery(), body: getQuery() }, limit: 50 }) + const loadMore = async () => { + saveScrollPosition() + const { hasMore } = await loadShoutsBy({ + by: { + title: query(), + body: query() + }, + offset: offset(), + limit: LOAD_MORE_PAGE_SIZE + }) + setIsLoadMoreButtonVisible(hasMore) + setOffset(offset() + LOAD_MORE_PAGE_SIZE) + restoreScrollPosition() } return (
- {/*FIXME t*/} - +
-
@@ -51,14 +70,18 @@ export const SearchView = (props: Props) => { selected: searchParams().by === 'relevance' }} > - {t('By relevance')} + + {t('By relevance')} +
  • - {t('Top rated')} + + {t('Top rated')} +
  • @@ -83,9 +106,13 @@ export const SearchView = (props: Props) => {
    -

    {t('Topics')}

    - -

    {t('Authors')}

    + +

    + +

    +
    ) diff --git a/src/locales/ru.json b/src/locales/ru.json index 900d6684..b71cdec3 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -176,5 +176,6 @@ "Video": "Видео", "Literature": "Литература", "We can't find you, check email or": "Не можем вас найти, проверьте адрес электронной почты или", - "register": "зарегистрируйтесь" + "register": "зарегистрируйтесь", + "Enter text": "Введите текст" }