import type { Author } from '../../graphql/schema/core.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 { useRouter } from '../../stores/router' import { setAuthorsSort, useAuthorsStore } from '../../stores/zine/authors' 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 { AuthorBadge } from '../Author/AuthorBadge' import styles from './AllAuthors.module.scss' type AllAuthorsPageSearchParams = { by: '' | 'name' | 'shouts' | 'followers' } type Props = { authors: Author[] isLoaded: boolean } const PAGE_SIZE = 20 const ALPHABET = [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ@'] export const AllAuthorsView = (props: Props) => { const { t, lang } = useLocalize() const [limit, setLimit] = createSignal(PAGE_SIZE) const { searchParams, changeSearchParams } = useRouter() const { sortedAuthors } = useAuthorsStore({ authors: props.authors, sortBy: searchParams().by || 'name', }) const [searchQuery, setSearchQuery] = createSignal('') createEffect(() => { if (!searchParams().by) { changeSearchParams({ by: 'name', }) } }) createEffect(() => { setAuthorsSort(searchParams().by || 'name') }) const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { return sortedAuthors().reduce( (acc, author) => { let letter = '' if (author && author.name) { const nameParts = author.name.trim().split(' ') const lastName = nameParts.pop() if (lastName && lastName.length > 0) { letter = lastName[0].toUpperCase() } } if (/[^ËА-яё]/.test(letter) && lang() === '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() keys.push(keys.shift()) return keys }) const filteredAuthors = createMemo(() => { return dummyFilter(sortedAuthors(), searchQuery(), lang()) }) const showMore = () => setLimit((oldLimit) => oldLimit + PAGE_SIZE) const ogImage = getImageUrl('production/image/logo_image.png') const ogTitle = t('Authors') const description = t('List of authors of the open editorial community') return (
}>

{t('Authors')}

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

0}> {(letter) => (

{letter}

{(author) => (
{author.name} {author.stat.shouts}
)}
)}
{(author) => (
)}
limit() && searchParams().by !== 'name'}>
) }