import type { Topic } from '../../graphql/types.gen' import { Meta } from '@solidjs/meta' import { clsx } from 'clsx' import { createEffect, createMemo, createSignal, For, Show } from 'solid-js' import { useLocalize } from '../../context/localize' import { useSession } from '../../context/session' import { useRouter } from '../../stores/router' import { setTopicsSort, useTopicsStore } from '../../stores/zine/topics' import { dummyFilter } from '../../utils/dummyFilter' import { getImageUrl } from '../../utils/getImageUrl' import { scrollHandler } from '../../utils/scroll' import { Loading } from '../_shared/Loading' import { SearchField } from '../_shared/SearchField' import { TopicCard } from '../Topic/Card' import styles from './AllTopics.module.scss' type AllTopicsPageSearchParams = { by: 'shouts' | 'authors' | 'title' | '' } type Props = { topics: Topic[] isLoaded: boolean } const PAGE_SIZE = 20 const ALPHABET = [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#'] export const AllTopicsView = (props: Props) => { 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')}

) const ogImage = getImageUrl('production/image/logo_image.png') const ogTitle = t('Themes and plots') const description = t( 'Thematic table of contents of the magazine. Here you can find all the topics that the community authors wrote about', ) 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'}>
) }