Merge remote-tracking branch 'origin/dev' into refactoing-catch-up
# Conflicts: # src/components/Views/Search.tsx
This commit is contained in:
commit
e6ca25fffa
|
@ -30,7 +30,11 @@ export const AuthorCard = (props: AuthorCardProps) => {
|
||||||
() => session()?.news?.authors?.some((u) => u === props.author.slug) || false
|
() => session()?.news?.authors?.some((u) => u === props.author.slug) || false
|
||||||
)
|
)
|
||||||
const canFollow = createMemo(() => !props.hideFollow && session()?.user?.slug !== props.author.slug)
|
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.textContent || t('Our regular contributor')
|
||||||
|
}
|
||||||
const name = () => {
|
const name = () => {
|
||||||
return props.author.name === 'Дискурс' && locale() !== 'ru'
|
return props.author.name === 'Дискурс' && locale() !== 'ru'
|
||||||
? 'Discours'
|
? 'Discours'
|
||||||
|
|
|
@ -120,15 +120,6 @@ export const TopicCard = (props: TopicProps) => {
|
||||||
{/* </span>*/}
|
{/* </span>*/}
|
||||||
{/*</Show>*/}
|
{/*</Show>*/}
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
{/*
|
|
||||||
<span class='topic-details__item'>
|
|
||||||
{subscribers().toString() + ' ' + t('follower') + plural(
|
|
||||||
subscribers(),
|
|
||||||
locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's']
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
*/}
|
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
@ -136,7 +127,6 @@ export const TopicCard = (props: TopicProps) => {
|
||||||
class={styles.controlContainer}
|
class={styles.controlContainer}
|
||||||
classList={{ 'col-md-3': !props.compact && !props.subscribeButtonBottom }}
|
classList={{ 'col-md-3': !props.compact && !props.subscribeButtonBottom }}
|
||||||
>
|
>
|
||||||
{}
|
|
||||||
<Show
|
<Show
|
||||||
when={subscribed()}
|
when={subscribed()}
|
||||||
fallback={
|
fallback={
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { useRouter } from '../../stores/router'
|
||||||
import styles from '../../styles/AllTopics.module.scss'
|
import styles from '../../styles/AllTopics.module.scss'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { useSession } from '../../context/session'
|
import { useSession } from '../../context/session'
|
||||||
|
import { locale } from '../../stores/ui'
|
||||||
|
|
||||||
type AllAuthorsPageSearchParams = {
|
type AllAuthorsPageSearchParams = {
|
||||||
by: '' | 'name' | 'shouts' | 'rating'
|
by: '' | 'name' | 'shouts' | 'rating'
|
||||||
|
@ -35,18 +36,10 @@ export const AllAuthorsView = (props: Props) => {
|
||||||
|
|
||||||
const byLetter = createMemo<{ [letter: string]: Author[] }>(() => {
|
const byLetter = createMemo<{ [letter: string]: Author[] }>(() => {
|
||||||
return sortedAuthors().reduce((acc, author) => {
|
return sortedAuthors().reduce((acc, author) => {
|
||||||
if (!author.name) {
|
let letter = author.name.trim().split(' ').pop().at(0).toUpperCase()
|
||||||
// name === null for new users
|
if (!/[А-я]/i.test(letter) && locale() === 'ru') letter = '@'
|
||||||
return acc
|
if (!acc[letter]) acc[letter] = []
|
||||||
}
|
|
||||||
|
|
||||||
const letter = author.name[0].toUpperCase()
|
|
||||||
if (!acc[letter]) {
|
|
||||||
acc[letter] = []
|
|
||||||
}
|
|
||||||
|
|
||||||
acc[letter].push(author)
|
acc[letter].push(author)
|
||||||
|
|
||||||
return acc
|
return acc
|
||||||
}, {} as { [letter: string]: Author[] })
|
}, {} as { [letter: string]: Author[] })
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,9 +5,11 @@ import { t } from '../../utils/intl'
|
||||||
import { setTopicsSort, useTopicsStore } from '../../stores/zine/topics'
|
import { setTopicsSort, useTopicsStore } from '../../stores/zine/topics'
|
||||||
import { useRouter } from '../../stores/router'
|
import { useRouter } from '../../stores/router'
|
||||||
import { TopicCard } from '../Topic/Card'
|
import { TopicCard } from '../Topic/Card'
|
||||||
import styles from '../../styles/AllTopics.module.scss'
|
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { useSession } from '../../context/session'
|
import { useSession } from '../../context/session'
|
||||||
|
import { locale } from '../../stores/ui'
|
||||||
|
import { translit } from '../../utils/ru2en'
|
||||||
|
import styles from '../../styles/AllTopics.module.scss'
|
||||||
|
|
||||||
type AllTopicsPageSearchParams = {
|
type AllTopicsPageSearchParams = {
|
||||||
by: 'shouts' | 'authors' | 'title' | ''
|
by: 'shouts' | 'authors' | 'title' | ''
|
||||||
|
@ -37,13 +39,10 @@ export const AllTopicsView = (props: AllTopicsViewProps) => {
|
||||||
|
|
||||||
const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => {
|
const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => {
|
||||||
return sortedTopics().reduce((acc, topic) => {
|
return sortedTopics().reduce((acc, topic) => {
|
||||||
const letter = topic.title[0].toUpperCase()
|
let letter = topic.title[0].toUpperCase()
|
||||||
if (!acc[letter]) {
|
if (!/[А-я]/i.test(letter) && locale() === 'ru') letter = '#'
|
||||||
acc[letter] = []
|
if (!acc[letter]) acc[letter] = []
|
||||||
}
|
|
||||||
|
|
||||||
acc[letter].push(topic)
|
acc[letter].push(topic)
|
||||||
|
|
||||||
return acc
|
return acc
|
||||||
}, {} as { [letter: string]: Topic[] })
|
}, {} as { [letter: string]: Topic[] })
|
||||||
})
|
})
|
||||||
|
@ -57,66 +56,78 @@ export const AllTopicsView = (props: AllTopicsViewProps) => {
|
||||||
const subscribed = (s) => Boolean(session()?.news?.topics && session()?.news?.topics?.includes(s || ''))
|
const subscribed = (s) => Boolean(session()?.news?.topics && session()?.news?.topics?.includes(s || ''))
|
||||||
|
|
||||||
const showMore = () => setLimit((oldLimit) => oldLimit + PAGE_SIZE)
|
const showMore = () => setLimit((oldLimit) => oldLimit + PAGE_SIZE)
|
||||||
|
let searchEl: HTMLInputElement
|
||||||
|
const [searchResults, setSearchResults] = createSignal<Topic[]>([])
|
||||||
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||||
|
const searchTopics = () => {
|
||||||
|
/* very stupid search algorithm with no deps */
|
||||||
|
let q = searchEl.value.toLowerCase()
|
||||||
|
if (q.length > 0) {
|
||||||
|
console.debug(q)
|
||||||
|
setSearchResults([])
|
||||||
|
|
||||||
return (
|
if (locale() === 'ru') q = translit(q, 'ru')
|
||||||
<div class={clsx(styles.allTopicsPage, 'container')}>
|
const ttt: Topic[] = []
|
||||||
<Show when={sortedTopics().length > 0}>
|
sortedTopics().forEach((topic) => {
|
||||||
<div class="shift-content">
|
let flag = false
|
||||||
|
topic.slug.split('-').forEach((w) => {
|
||||||
|
if (w.startsWith(q)) flag = true
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
let wrds: string = topic.title.toLowerCase()
|
||||||
|
if (locale() === 'ru') wrds = translit(wrds, 'ru')
|
||||||
|
wrds.split(' ').forEach((w: string) => {
|
||||||
|
if (w.startsWith(q)) flag = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag && !ttt.includes(topic)) ttt.push(topic)
|
||||||
|
})
|
||||||
|
|
||||||
|
setSearchResults((sr: Topic[]) => [...sr, ...ttt])
|
||||||
|
changeSearchParam('by', '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const AllTopicsHead = () => (
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class={clsx(styles.pageHeader, 'col-lg-10 col-xl-9')}>
|
<div class={clsx(styles.pageHeader, 'col-lg-10 col-xl-9')}>
|
||||||
<h1>{t('Topics')}</h1>
|
<h1>{t('Topics')}</h1>
|
||||||
<p>{t('Subscribe what you like to tune your personal feed')}</p>
|
<p>{t('Subscribe what you like to tune your personal feed')}</p>
|
||||||
|
|
||||||
<ul class={clsx(styles.viewSwitcher, 'view-switcher')}>
|
<ul class={clsx(styles.viewSwitcher, 'view-switcher')}>
|
||||||
<li classList={{ selected: searchParams().by === 'shouts' || !searchParams().by }}>
|
<li classList={{ selected: searchParams().by === 'shouts' }}>
|
||||||
<a href="/topics?by=shouts">{t('By shouts')}</a>
|
<a href="/topics?by=shouts">{t('By shouts')}</a>
|
||||||
</li>
|
</li>
|
||||||
<li classList={{ selected: searchParams().by === 'authors' }}>
|
<li classList={{ selected: searchParams().by === 'authors' }}>
|
||||||
<a href="/topics?by=authors">{t('By authors')}</a>
|
<a href="/topics?by=authors">{t('By authors')}</a>
|
||||||
</li>
|
</li>
|
||||||
<li classList={{ selected: searchParams().by === 'title' }}>
|
<li classList={{ selected: searchParams().by === 'title' }}>
|
||||||
<a
|
<a href="/topics?by=title">{t('By alphabet')}</a>
|
||||||
href="/topics?by=title"
|
|
||||||
onClick={(ev) => {
|
|
||||||
// just an example
|
|
||||||
ev.preventDefault()
|
|
||||||
changeSearchParam('by', 'title')
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('By alphabet')}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
<li class="view-switcher__search">
|
<li class="search-switcher">
|
||||||
<a href="/topic/search">
|
|
||||||
<Icon name="search" />
|
<Icon name="search" />
|
||||||
{t('Search topic')}
|
<input
|
||||||
</a>
|
class="search-input"
|
||||||
|
ref={searchEl}
|
||||||
|
onChange={searchTopics}
|
||||||
|
onInput={searchTopics}
|
||||||
|
onFocus={() => (searchEl.innerHTML = '')}
|
||||||
|
placeholder={t('Search')}
|
||||||
|
/>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
<div class={clsx(styles.allTopicsPage, 'container')}>
|
||||||
|
<AllTopicsHead />
|
||||||
|
|
||||||
<Show
|
<div class="shift-content">
|
||||||
when={searchParams().by === 'title'}
|
<Show when={sortedTopics().length > 0 || searchResults().length > 0}>
|
||||||
fallback={() => (
|
<Show when={searchParams().by === 'title'}>
|
||||||
<>
|
|
||||||
<For each={sortedTopics().slice(0, limit())}>
|
|
||||||
{(topic) => (
|
|
||||||
<TopicCard topic={topic} compact={false} subscribed={subscribed(topic.slug)} />
|
|
||||||
)}
|
|
||||||
</For>
|
|
||||||
<Show when={sortedTopics().length > limit()}>
|
|
||||||
<div class="row">
|
|
||||||
<div class={clsx(styles.loadMoreContainer, 'col-12 col-md-10')}>
|
|
||||||
<button class={clsx('button', styles.loadMoreButton)} onClick={showMore}>
|
|
||||||
{t('Load more')}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Show>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<For each={sortedKeys()}>
|
<For each={sortedKeys()}>
|
||||||
{(letter) => (
|
{(letter) => (
|
||||||
<div class={clsx(styles.group, 'group')}>
|
<div class={clsx(styles.group, 'group')}>
|
||||||
|
@ -142,8 +153,57 @@ export const AllTopicsView = (props: AllTopicsViewProps) => {
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
|
<Show when={searchResults().length > 1}>
|
||||||
|
<For each={searchResults().slice(0, limit())}>
|
||||||
|
{(topic) => (
|
||||||
|
<TopicCard
|
||||||
|
topic={topic}
|
||||||
|
compact={false}
|
||||||
|
subscribed={subscribed(topic.slug)}
|
||||||
|
showPublications={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<Show when={searchParams().by === 'authors'}>
|
||||||
|
<For each={sortedTopics().slice(0, limit())}>
|
||||||
|
{(topic) => (
|
||||||
|
<TopicCard
|
||||||
|
topic={topic}
|
||||||
|
compact={false}
|
||||||
|
subscribed={subscribed(topic.slug)}
|
||||||
|
showPublications={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<Show when={searchParams().by === 'shouts'}>
|
||||||
|
<For each={sortedTopics().slice(0, limit())}>
|
||||||
|
{(topic) => (
|
||||||
|
<TopicCard
|
||||||
|
topic={topic}
|
||||||
|
compact={false}
|
||||||
|
subscribed={subscribed(topic.slug)}
|
||||||
|
showPublications={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<Show when={sortedTopics().length > limit()}>
|
||||||
|
<div class="row">
|
||||||
|
<div class={clsx(styles.loadMoreContainer, 'col-12 col-md-10')}>
|
||||||
|
<button class={clsx('button', styles.loadMoreButton)} onClick={showMore}>
|
||||||
|
{t('Load more')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import RowShort from '../Feed/RowShort'
|
||||||
import Slider from '../Feed/Slider'
|
import Slider from '../Feed/Slider'
|
||||||
import Group from '../Feed/Group'
|
import Group from '../Feed/Group'
|
||||||
import type { Shout, Topic } from '../../graphql/types.gen'
|
import type { Shout, Topic } from '../../graphql/types.gen'
|
||||||
import { Icon } from '../_shared/Icon'
|
|
||||||
import { t } from '../../utils/intl'
|
import { t } from '../../utils/intl'
|
||||||
import { useTopicsStore } from '../../stores/zine/topics'
|
import { useTopicsStore } from '../../stores/zine/topics'
|
||||||
import { loadShouts, useArticlesStore } from '../../stores/zine/articles'
|
import { loadShouts, useArticlesStore } from '../../stores/zine/articles'
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type { Shout } from '../../graphql/types.gen'
|
||||||
import { ArticleCard } from '../Feed/Card'
|
import { ArticleCard } from '../Feed/Card'
|
||||||
import { t } from '../../utils/intl'
|
import { t } from '../../utils/intl'
|
||||||
import { loadShouts, useArticlesStore } from '../../stores/zine/articles'
|
import { loadShouts, useArticlesStore } from '../../stores/zine/articles'
|
||||||
|
import { restoreScrollPosition, saveScrollPosition } from '../../utils/scroll'
|
||||||
import { useRouter } from '../../stores/router'
|
import { useRouter } from '../../stores/router'
|
||||||
|
|
||||||
type SearchPageSearchParams = {
|
type SearchPageSearchParams = {
|
||||||
|
@ -15,31 +16,49 @@ type Props = {
|
||||||
results: Shout[]
|
results: Shout[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LOAD_MORE_PAGE_SIZE = 50
|
||||||
|
|
||||||
export const SearchView = (props: Props) => {
|
export const SearchView = (props: Props) => {
|
||||||
const { sortedArticles } = useArticlesStore({ shouts: props.results })
|
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<SearchPageSearchParams>()
|
const { searchParams, handleClientRouteLinkClick } = useRouter<SearchPageSearchParams>()
|
||||||
|
let searchEl: HTMLInputElement
|
||||||
const handleQueryChange = (ev) => {
|
const handleQueryChange = (_ev) => {
|
||||||
setQuery(ev.target.value)
|
setQuery(searchEl.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = (_ev) => {
|
const loadMore = async () => {
|
||||||
// TODO page
|
saveScrollPosition()
|
||||||
// TODO sort
|
const { hasMore } = await loadShouts({
|
||||||
loadShouts({ filters: { title: getQuery(), body: getQuery() }, limit: 50 })
|
filters: {
|
||||||
|
title: query(),
|
||||||
|
body: query()
|
||||||
|
},
|
||||||
|
offset: offset(),
|
||||||
|
limit: LOAD_MORE_PAGE_SIZE
|
||||||
|
})
|
||||||
|
setIsLoadMoreButtonVisible(hasMore)
|
||||||
|
setOffset(offset() + LOAD_MORE_PAGE_SIZE)
|
||||||
|
restoreScrollPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="search-page wide-container">
|
<div class="search-page wide-container">
|
||||||
<form action="/search" class="search-form row">
|
<form action="/search" class="search-form row">
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
{/*FIXME t*/}
|
<input
|
||||||
<input type="search" name="q" onChange={handleQueryChange} placeholder="Введите текст..." />
|
type="search"
|
||||||
|
name="q"
|
||||||
|
ref={searchEl}
|
||||||
|
onInput={handleQueryChange}
|
||||||
|
placeholder={t('Enter text') + '...'}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<button class="button" type="submit" onClick={handleSubmit}>
|
<button class="button" type="submit" onClick={loadMore}>
|
||||||
{t('Search')}
|
{t('Search')}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -51,14 +70,18 @@ export const SearchView = (props: Props) => {
|
||||||
selected: searchParams().by === 'relevance'
|
selected: searchParams().by === 'relevance'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<a href="?by=relevance">{t('By relevance')}</a>
|
<a href="?by=relevance" onClick={handleClientRouteLinkClick}>
|
||||||
|
{t('By relevance')}
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
classList={{
|
classList={{
|
||||||
selected: searchParams().by === 'rating'
|
selected: searchParams().by === 'rating'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<a href="?by=rating">{t('Top rated')}</a>
|
<a href="?by=rating" onClick={handleClientRouteLinkClick}>
|
||||||
|
{t('Top rated')}
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -83,9 +106,13 @@ export const SearchView = (props: Props) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>{t('Topics')}</h3>
|
<Show when={isLoadMoreButtonVisible()}>
|
||||||
|
<p class="load-more-container">
|
||||||
<h3>{t('Authors')}</h3>
|
<button class="button" onClick={loadMore}>
|
||||||
|
{t('Load more')}
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</Show>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
@ -176,5 +176,6 @@
|
||||||
"Video": "Видео",
|
"Video": "Видео",
|
||||||
"Literature": "Литература",
|
"Literature": "Литература",
|
||||||
"We can't find you, check email or": "Не можем вас найти, проверьте адрес электронной почты или",
|
"We can't find you, check email or": "Не можем вас найти, проверьте адрес электронной почты или",
|
||||||
"register": "зарегистрируйтесь"
|
"register": "зарегистрируйтесь",
|
||||||
|
"Enter text": "Введите текст"
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,11 @@
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: auto;
|
width: auto;
|
||||||
|
|
||||||
|
.search-input {
|
||||||
|
display: inline-block;
|
||||||
|
width: 100px !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user