2024-06-24 17:50:27 +00:00
|
|
|
import { Meta } from '@solidjs/meta'
|
2024-07-03 17:38:43 +00:00
|
|
|
import { useSearchParams } from '@solidjs/router'
|
2024-02-22 07:29:52 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-07-06 00:59:01 +00:00
|
|
|
import { For, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { Loading } from '~/components/_shared/Loading'
|
|
|
|
import { SearchField } from '~/components/_shared/SearchField'
|
2024-07-05 19:40:54 +00:00
|
|
|
import { useAuthors } from '~/context/authors'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { useLocalize } from '~/context/localize'
|
|
|
|
import type { Author } from '~/graphql/schema/core.gen'
|
2024-07-05 14:08:12 +00:00
|
|
|
import enKeywords from '~/intl/locales/en/keywords.json'
|
|
|
|
import ruKeywords from '~/intl/locales/ru/keywords.json'
|
|
|
|
import { authorLetterReduce, translateAuthor } from '~/intl/translate'
|
2024-07-07 13:48:53 +00:00
|
|
|
import { dummyFilter } from '~/lib/dummyFilter'
|
2024-07-05 14:08:12 +00:00
|
|
|
import { getImageUrl } from '~/lib/getImageUrl'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { scrollHandler } from '~/utils/scroll'
|
2024-02-22 07:29:52 +00:00
|
|
|
import { AuthorsList } from '../../AuthorsList'
|
|
|
|
import styles from './AllAuthors.module.scss'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
authors: Author[]
|
2024-02-29 20:46:15 +00:00
|
|
|
topFollowedAuthors?: Author[]
|
|
|
|
topWritingAuthors?: Author[]
|
2024-02-22 07:29:52 +00:00
|
|
|
isLoaded: boolean
|
|
|
|
}
|
2024-07-03 07:02:46 +00:00
|
|
|
export const AUTHORS_PER_PAGE = 20
|
|
|
|
export const ABC = {
|
|
|
|
ru: 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#',
|
|
|
|
en: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ#'
|
|
|
|
}
|
2024-02-22 07:29:52 +00:00
|
|
|
|
2024-07-07 13:48:53 +00:00
|
|
|
// useAuthors sorted from context, set filter/sort
|
|
|
|
|
2024-02-22 07:29:52 +00:00
|
|
|
export const AllAuthors = (props: Props) => {
|
|
|
|
const { t, lang } = useLocalize()
|
2024-07-03 07:02:46 +00:00
|
|
|
const alphabet = createMemo(() => ABC[lang()] || ABC['ru'])
|
2024-07-06 00:59:01 +00:00
|
|
|
const [searchParams, changeSearchParams] = useSearchParams<{ by?: string }>()
|
2024-07-07 13:48:53 +00:00
|
|
|
const { authorsSorted, setAuthorsSort } = useAuthors()
|
|
|
|
const authors = createMemo(() => props.authors || authorsSorted())
|
2024-07-06 00:59:01 +00:00
|
|
|
|
2024-07-07 13:48:53 +00:00
|
|
|
// filter
|
|
|
|
const [searchQuery, setSearchQuery] = createSignal('')
|
|
|
|
const [filteredAuthors, setFilteredAuthors] = createSignal<Author[]>([])
|
2024-07-07 14:07:11 +00:00
|
|
|
createEffect(
|
|
|
|
() =>
|
|
|
|
authors() &&
|
|
|
|
setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[])
|
2024-07-07 13:48:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// sort by
|
2024-07-06 00:59:01 +00:00
|
|
|
onMount(() => !searchParams?.by && changeSearchParams({ by: 'name' }))
|
|
|
|
createEffect(on(() => searchParams?.by || 'name', setAuthorsSort || ((_) => null), {}))
|
2024-02-22 07:29:52 +00:00
|
|
|
|
2024-07-07 13:48:53 +00:00
|
|
|
// store by first char
|
2024-02-25 07:31:11 +00:00
|
|
|
const byLetterFiltered = createMemo<{ [letter: string]: Author[] }>(() => {
|
2024-07-07 13:48:53 +00:00
|
|
|
console.debug('[components.AllAuthors] byLetterFiltered')
|
2024-07-05 19:40:54 +00:00
|
|
|
return (
|
|
|
|
filteredAuthors()?.reduce(
|
|
|
|
(acc, author: Author) => authorLetterReduce(acc, author, lang()),
|
|
|
|
{} as { [letter: string]: Author[] }
|
|
|
|
) || {}
|
2024-02-22 07:29:52 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
const sortedKeys = createMemo<string[]>(() => {
|
2024-07-05 08:12:17 +00:00
|
|
|
const keys = Object.keys(byLetterFiltered() || {})
|
2024-02-22 07:29:52 +00:00
|
|
|
keys.sort()
|
2024-06-24 17:50:27 +00:00
|
|
|
const fk = keys.shift() || ''
|
|
|
|
fk && keys.push(fk)
|
2024-02-22 07:29:52 +00:00
|
|
|
return keys
|
|
|
|
})
|
|
|
|
|
2024-07-01 15:30:45 +00:00
|
|
|
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'))
|
2024-02-22 07:29:52 +00:00
|
|
|
|
|
|
|
return (
|
2024-07-07 13:48:53 +00:00
|
|
|
<div class={clsx([styles.allAuthorsPage, 'wide-container'])}>
|
2024-07-05 08:11:57 +00:00
|
|
|
<Meta name="descprition" content={description() || ''} />
|
2024-07-03 17:38:43 +00:00
|
|
|
<Meta name="keywords" content={lang() === 'ru' ? ruKeywords[''] : enKeywords['']} />
|
2024-02-22 07:29:52 +00:00
|
|
|
<Meta name="og:type" content="article" />
|
2024-07-05 08:11:57 +00:00
|
|
|
<Meta name="og:title" content={ogTitle() || ''} />
|
|
|
|
<Meta name="og:image" content={ogImage() || ''} />
|
|
|
|
<Meta name="twitter:image" content={ogImage() || ''} />
|
|
|
|
<Meta name="og:description" content={description() || ''} />
|
2024-02-22 07:29:52 +00:00
|
|
|
<Meta name="twitter:card" content="summary_large_image" />
|
2024-07-05 08:11:57 +00:00
|
|
|
<Meta name="twitter:title" content={ogTitle() || ''} />
|
|
|
|
<Meta name="twitter:description" content={description() || ''} />
|
2024-02-22 07:29:52 +00:00
|
|
|
<Show when={props.isLoaded} fallback={<Loading />}>
|
|
|
|
<div class="offset-md-5">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-20 col-xl-18">
|
|
|
|
<h1>{t('Authors')}</h1>
|
|
|
|
<p>{t('Subscribe who you like to tune your personal feed')}</p>
|
|
|
|
<ul class={clsx(styles.viewSwitcher, 'view-switcher')}>
|
|
|
|
<li
|
|
|
|
class={clsx({
|
2024-06-26 08:22:05 +00:00
|
|
|
['view-switcher__item--selected']: !searchParams?.by || searchParams?.by === 'shouts'
|
2024-02-22 07:29:52 +00:00
|
|
|
})}
|
|
|
|
>
|
2024-07-03 21:25:03 +00:00
|
|
|
<a href="/author?by=shouts">{t('By shouts')}</a>
|
2024-02-22 07:29:52 +00:00
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
class={clsx({
|
2024-06-26 08:22:05 +00:00
|
|
|
['view-switcher__item--selected']: searchParams?.by === 'followers'
|
2024-02-22 07:29:52 +00:00
|
|
|
})}
|
|
|
|
>
|
2024-07-03 21:25:03 +00:00
|
|
|
<a href="/author?by=followers">{t('By popularity')}</a>
|
2024-02-22 07:29:52 +00:00
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
class={clsx({
|
2024-06-26 08:22:05 +00:00
|
|
|
['view-switcher__item--selected']: searchParams?.by === 'name'
|
2024-02-22 07:29:52 +00:00
|
|
|
})}
|
|
|
|
>
|
2024-07-03 21:25:03 +00:00
|
|
|
<a href="/author?by=name">{t('By name')}</a>
|
2024-02-22 07:29:52 +00:00
|
|
|
</li>
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={searchParams?.by === 'name'}>
|
2024-02-22 07:29:52 +00:00
|
|
|
<li class="view-switcher__search">
|
|
|
|
<SearchField onChange={(value) => setSearchQuery(value)} />
|
|
|
|
</li>
|
|
|
|
</Show>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={searchParams?.by === 'name'}>
|
2024-02-22 07:29:52 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-20 col-xl-18">
|
|
|
|
<ul class={clsx('nodash', styles.alphabet)}>
|
2024-07-05 13:35:13 +00:00
|
|
|
<For each={[...(alphabet() || [])]}>
|
2024-02-22 07:29:52 +00:00
|
|
|
{(letter, index) => (
|
|
|
|
<li>
|
2024-02-25 07:31:11 +00:00
|
|
|
<Show when={letter in byLetterFiltered()} fallback={letter}>
|
2024-02-22 07:29:52 +00:00
|
|
|
<a
|
2024-07-03 21:25:03 +00:00
|
|
|
href={`/author?by=name#letter-${index()}`}
|
2024-02-22 07:29:52 +00:00
|
|
|
onClick={(event) => {
|
|
|
|
event.preventDefault()
|
|
|
|
scrollHandler(`letter-${index()}`)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{letter}
|
|
|
|
</a>
|
|
|
|
</Show>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-07-05 13:34:19 +00:00
|
|
|
<For each={sortedKeys() || []}>
|
2024-02-22 07:29:52 +00:00
|
|
|
{(letter) => (
|
|
|
|
<div class={clsx(styles.group, 'group')}>
|
2024-07-05 13:35:13 +00:00
|
|
|
<h2 id={`letter-${alphabet()?.indexOf(letter) || ''}`}>{letter}</h2>
|
2024-02-22 07:29:52 +00:00
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-20">
|
|
|
|
<div class="row">
|
2024-07-05 13:34:19 +00:00
|
|
|
<For each={byLetterFiltered()?.[letter] || []}>
|
2024-02-22 07:29:52 +00:00
|
|
|
{(author) => (
|
|
|
|
<div class={clsx(styles.topic, 'topic col-sm-12 col-md-8')}>
|
|
|
|
<div class="topic-title">
|
|
|
|
<a href={`/author/${author.slug}`}>{translateAuthor(author, lang())}</a>
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={author.stat?.shouts || 0}>
|
|
|
|
<span class={styles.articlesCounter}>{author.stat?.shouts || 0}</span>
|
2024-02-22 07:29:52 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Show>
|
2024-07-07 13:48:53 +00:00
|
|
|
<Show when={authors().length && searchParams?.by !== 'name' && props.isLoaded}>
|
2024-02-25 07:31:11 +00:00
|
|
|
<AuthorsList
|
2024-07-07 13:48:53 +00:00
|
|
|
allAuthorsLength={authors().length}
|
2024-02-25 07:31:11 +00:00
|
|
|
searchQuery={searchQuery()}
|
2024-06-24 17:50:27 +00:00
|
|
|
query={searchParams?.by === 'followers' ? 'followers' : 'shouts'}
|
2024-02-25 07:31:11 +00:00
|
|
|
/>
|
2024-02-22 07:29:52 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|