import { Meta } from '@solidjs/meta' import { useSearchParams } from '@solidjs/router' import { clsx } from 'clsx' import { For, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js' import { Loading } from '~/components/_shared/Loading' import { SearchField } from '~/components/_shared/SearchField' import { useAuthors } from '~/context/authors' import { useLocalize } from '~/context/localize' import type { Author } from '~/graphql/schema/core.gen' import enKeywords from '~/intl/locales/en/keywords.json' import ruKeywords from '~/intl/locales/ru/keywords.json' import { authorLetterReduce, translateAuthor } from '~/intl/translate' import { dummyFilter } from '~/lib/dummyFilter' import { getImageUrl } from '~/lib/getImageUrl' import { scrollHandler } from '~/utils/scroll' import { AuthorsList } from '../../AuthorsList' import styles from './AllAuthors.module.scss' type Props = { authors: Author[] topFollowedAuthors?: Author[] topWritingAuthors?: Author[] isLoaded: boolean } export const AUTHORS_PER_PAGE = 20 export const ABC = { ru: 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#', en: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ#' } // useAuthors sorted from context, set filter/sort export const AllAuthors = (props: Props) => { const { t, lang } = useLocalize() const alphabet = createMemo(() => ABC[lang()] || ABC['ru']) const [searchParams, changeSearchParams] = useSearchParams<{ by?: string }>() const { authorsSorted, setAuthorsSort } = useAuthors() const authors = createMemo(() => props.authors || authorsSorted()) // filter const [searchQuery, setSearchQuery] = createSignal('') const [filteredAuthors, setFilteredAuthors] = createSignal([]) createEffect( () => authors() && setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[]) ) // sort by onMount(() => !searchParams?.by && changeSearchParams({ by: 'name' })) createEffect(on(() => searchParams?.by || 'name', setAuthorsSort || ((_) => null), {})) // store by first char const byLetterFiltered = createMemo<{ [letter: string]: Author[] }>(() => { console.debug('[components.AllAuthors] byLetterFiltered') return ( filteredAuthors()?.reduce( (acc, author: Author) => authorLetterReduce(acc, author, lang()), {} as { [letter: string]: Author[] } ) || {} ) }) const sortedKeys = createMemo(() => { const keys = Object.keys(byLetterFiltered() || {}) keys.sort() const fk = keys.shift() || '' fk && keys.push(fk) return keys }) const ogImage = createMemo(() => getImageUrl('production/image/logo_image.png')) const ogTitle = createMemo(() => t('Authors')) const description = createMemo(() => t('List of authors of the open editorial community')) return (
}>

{t('Authors')}

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

{(letter) => (

{letter}

{(author) => (
{translateAuthor(author, lang())} {author.stat?.shouts || 0}
)}
)}
) }