import { createEffect, createMemo, createSignal, For, Show } from 'solid-js' import type { Author } from '../../graphql/types.gen' import { AuthorCard } from '../Author/Card' import { Icon } from '../_shared/Icon' import { t } from '../../utils/intl' import { useAuthorsStore, setAuthorsSort } from '../../stores/zine/authors' import { useRouter } from '../../stores/router' import styles from '../../styles/AllTopics.module.scss' import { clsx } from 'clsx' import { useSession } from '../../context/session' import { locale } from '../../stores/ui' import { translit } from '../../utils/ru2en' import { SearchField } from '../_shared/SearchField' type AllAuthorsPageSearchParams = { by: '' | 'name' | 'shouts' | 'rating' } type Props = { authors: Author[] } const PAGE_SIZE = 20 const ALPHABET = Array.from('@АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ') export const AllAuthorsView = (props: Props) => { const { sortedAuthors } = useAuthorsStore({ authors: props.authors }) const [limit, setLimit] = createSignal(PAGE_SIZE) const { session } = useSession() createEffect(() => { setAuthorsSort(searchParams().by || 'shouts') }) const subscribed = (s) => Boolean(session()?.news?.authors && session()?.news?.authors?.includes(s || '')) const { searchParams, changeSearchParam } = useRouter() const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { return sortedAuthors().reduce((acc, author) => { let letter = author.name.trim().split(' ').pop().at(0).toUpperCase() if (!/[А-я]/i.test(letter) && locale() === 'ru') letter = '@' if (!acc[letter]) acc[letter] = [] acc[letter].push(author) return acc }, {} as { [letter: string]: Author[] }) }) const sortedKeys = createMemo(() => { const keys = Object.keys(byLetter()) keys.sort() return keys }) const showMore = () => setLimit((oldLimit) => oldLimit + PAGE_SIZE) const AllAuthorsHead = () => (

{t('Authors')}

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

) const scrollHandler = (elemId) => { const anchor = document.querySelector('#' + elemId) // console.debug(elemId) if (anchor) { window.scrollTo({ top: anchor.getBoundingClientRect().top - 100, behavior: 'smooth' }) } } const [searchResults, setSearchResults] = createSignal([]) // eslint-disable-next-line sonarjs/cognitive-complexity const searchAuthors = (value) => { /* very stupid search algorithm with no deps */ let q = value.toLowerCase() if (q.length > 0) { console.debug(q) setSearchResults([]) if (locale() === 'ru') q = translit(q, 'ru') const aaa: Author[] = [] sortedAuthors().forEach((a) => { let flag = false a.slug.split('-').forEach((w) => { if (w.startsWith(q)) flag = true }) if (!flag) { let wrds: string = a.name.toLowerCase() if (locale() === 'ru') wrds = translit(wrds, 'ru') wrds.split(' ').forEach((w: string) => { if (w.startsWith(q)) flag = true }) } if (flag && !aaa.includes(a)) aaa.push(a) }) setSearchResults((sr: Author[]) => [...sr, ...aaa]) changeSearchParam('by', '') } } return (
0 || searchResults().length > 0}>
{(letter, index) => (

{letter}

{(author) => (
{author.name} {author.stat.shouts}
)}
)}
0}> {(author) => ( )}
{(author) => ( )}
limit()}>
) }