import { createEffect, createMemo, createSignal, For, onMount, Show } from 'solid-js' import type { Topic } from '../../graphql/types.gen' import { setTopicsSort, useTopicsStore } from '../../stores/zine/topics' import { useRouter } from '../../stores/router' import { TopicCard } from '../Topic/Card' import { clsx } from 'clsx' import { useSession } from '../../context/session' import { SearchField } from '../_shared/SearchField' import { scrollHandler } from '../../utils/scroll' import { useLocalize } from '../../context/localize' import { dummyFilter } from '../../utils/dummyFilter' import styles from './AllTopics.module.scss' type AllTopicsPageSearchParams = { by: 'shouts' | 'authors' | 'title' | '' } type AllTopicsViewProps = { topics: Topic[] } const PAGE_SIZE = 20 const ALPHABET = [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#'] export const AllTopicsView = (props: AllTopicsViewProps) => { const { t, lang } = useLocalize() const { searchParams, changeSearchParam } = useRouter() const [limit, setLimit] = createSignal(PAGE_SIZE) const { sortedTopics } = useTopicsStore({ topics: props.topics, sortBy: searchParams().by || 'shouts' }) const { subscriptions } = useSession() createEffect(() => { if (!searchParams().by) { changeSearchParam({ by: 'shouts' }) } }) createEffect(() => { setTopicsSort(searchParams().by || 'shouts') }) const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => { return sortedTopics().reduce( (acc, topic) => { let letter = topic.title[0].toUpperCase() if (/[^ËА-яё]/.test(letter) && lang() === 'ru') letter = '#' if (!acc[letter]) acc[letter] = [] acc[letter].push(topic) return acc }, {} as { [letter: string]: Topic[] } ) }) const sortedKeys = createMemo(() => { const keys = Object.keys(byLetter()) keys.sort() keys.push(keys.shift()) return keys }) const subscribed = (topicSlug: string) => subscriptions().topics.some((topic) => topic.slug === topicSlug) const showMore = () => setLimit((oldLimit) => oldLimit + PAGE_SIZE) const [searchQuery, setSearchQuery] = createSignal('') const filteredResults = createMemo(() => { return dummyFilter(sortedTopics(), searchQuery(), lang()) }) const AllTopicsHead = () => (

{t('Topics')}

{t('Subscribe what you like to tune your personal feed')}

) return (
0}> {(letter) => (

{letter}

{(topic) => (
{topic.title} {topic.stat.shouts}
)}
)}
{(topic) => ( <>
{t('shoutsWithCount', { count: topic.stat.shouts })} {t('authorsWithCount', { count: topic.stat.authors })} {t('followersWithCount', { count: topic.stat.followers })}
)}
limit() && searchParams().by !== 'title'}>
) }