import type { Topic } from '../../../graphql/schema/core.gen' import { Meta } from '@solidjs/meta' import { clsx } from 'clsx' import { For, Show, createEffect, createMemo, createSignal } from 'solid-js' import { useLocalize } from '../../../context/localize' import { useRouter } from '../../../stores/router' import { setTopicsSort, useTopicsStore } from '../../../stores/zine/topics' import { capitalize } from '../../../utils/capitalize' 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 { TopicBadge } from '../../Topic/TopicBadge' import styles from './AllTopics.module.scss' type AllTopicsPageSearchParams = { by: 'shouts' | 'authors' | 'title' | '' } type Props = { topics: Topic[] isLoaded: boolean } export const PAGE_SIZE = 20 export const AllTopics = (props: Props) => { const { t, lang } = useLocalize() const { searchParams, changeSearchParams } = useRouter() const [limit, setLimit] = createSignal(PAGE_SIZE) const ALPHABET = lang() === 'ru' ? [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#'] : [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ#'] const { sortedTopics } = useTopicsStore({ topics: props.topics, sortBy: searchParams().by || 'shouts', }) createEffect(() => { if (!searchParams().by) { changeSearchParams({ by: 'shouts', }) } }) createEffect(() => { setTopicsSort(searchParams().by || 'shouts') }) const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => { return sortedTopics().reduce( (acc, topic) => { let letter = lang() === 'en' ? topic.slug[0].toUpperCase() : topic.title[0].toUpperCase() if (/[^ËА-яё]/.test(letter) && lang() === 'ru') letter = '#' if (/[^A-z]/.test(letter) && lang() === 'en') 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 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) => ( )}
{(topic) => ( <> )}
limit() && searchParams().by !== 'title'}>
) }