2022-11-13 19:35:57 +00:00
|
|
|
import { createEffect, createMemo, createSignal, For, Show } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
import type { Author } from '../../graphql/types.gen'
|
|
|
|
import { AuthorCard } from '../Author/Card'
|
2022-11-14 17:41:05 +00:00
|
|
|
import { Icon } from '../_shared/Icon'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { t } from '../../utils/intl'
|
2022-10-21 18:17:04 +00:00
|
|
|
import { useAuthorsStore, setAuthorsSort } from '../../stores/zine/authors'
|
2022-11-15 16:16:31 +00:00
|
|
|
import { useRouter } from '../../stores/router'
|
2022-11-09 19:02:12 +00:00
|
|
|
import styles from '../../styles/AllTopics.module.scss'
|
|
|
|
import { clsx } from 'clsx'
|
2022-11-14 10:02:08 +00:00
|
|
|
import { useSession } from '../../context/session'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
type AllAuthorsPageSearchParams = {
|
|
|
|
by: '' | 'name' | 'shouts' | 'rating'
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
authors: Author[]
|
|
|
|
}
|
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
const PAGE_SIZE = 20
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
export const AllAuthorsView = (props: Props) => {
|
2022-10-05 11:13:15 +00:00
|
|
|
const { sortedAuthors } = useAuthorsStore({ authors: props.authors })
|
2022-11-13 19:35:57 +00:00
|
|
|
const [limit, setLimit] = createSignal(PAGE_SIZE)
|
2022-09-30 14:22:33 +00:00
|
|
|
|
2022-11-14 10:02:08 +00:00
|
|
|
const { session } = useSession()
|
2022-09-30 14:22:33 +00:00
|
|
|
|
2022-10-05 15:56:59 +00:00
|
|
|
createEffect(() => {
|
2022-10-21 18:17:04 +00:00
|
|
|
setAuthorsSort(searchParams().by || 'shouts')
|
2022-10-05 15:56:59 +00:00
|
|
|
})
|
|
|
|
|
2022-10-04 12:16:07 +00:00
|
|
|
const subscribed = (s) => Boolean(session()?.news?.authors && session()?.news?.authors?.includes(s || ''))
|
2022-09-14 11:28:43 +00:00
|
|
|
|
2022-10-21 18:17:04 +00:00
|
|
|
const { searchParams } = useRouter<AllAuthorsPageSearchParams>()
|
2022-09-14 11:28:43 +00:00
|
|
|
|
2022-10-05 15:56:59 +00:00
|
|
|
const byLetter = createMemo<{ [letter: string]: Author[] }>(() => {
|
|
|
|
return sortedAuthors().reduce((acc, author) => {
|
2022-10-19 14:26:49 +00:00
|
|
|
if (!author.name) {
|
|
|
|
// name === null for new users
|
|
|
|
return acc
|
|
|
|
}
|
|
|
|
|
2022-10-05 17:26:47 +00:00
|
|
|
const letter = author.name[0].toUpperCase()
|
2022-10-05 15:56:59 +00:00
|
|
|
if (!acc[letter]) {
|
|
|
|
acc[letter] = []
|
|
|
|
}
|
|
|
|
|
|
|
|
acc[letter].push(author)
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}, {} as { [letter: string]: Author[] })
|
|
|
|
})
|
|
|
|
|
|
|
|
const sortedKeys = createMemo<string[]>(() => {
|
|
|
|
const keys = Object.keys(byLetter())
|
|
|
|
keys.sort()
|
|
|
|
return keys
|
2022-10-05 11:13:15 +00:00
|
|
|
})
|
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
const showMore = () => setLimit((oldLimit) => oldLimit + PAGE_SIZE)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
return (
|
2022-11-11 10:22:07 +00:00
|
|
|
<div class={clsx(styles.allTopicsPage, 'container')}>
|
2022-09-28 20:16:44 +00:00
|
|
|
<Show when={sortedAuthors().length > 0}>
|
2022-11-11 10:22:07 +00:00
|
|
|
<div class="shift-content">
|
|
|
|
<div class="row">
|
2022-11-14 21:58:33 +00:00
|
|
|
<div class={clsx(styles.pageHeader, 'col-lg-10 col-xl-9')}>
|
2022-11-11 10:22:07 +00:00
|
|
|
<h1>{t('Authors')}</h1>
|
|
|
|
<p>{t('Subscribe who you like to tune your personal feed')}</p>
|
2022-11-14 21:58:33 +00:00
|
|
|
|
2022-11-11 10:22:07 +00:00
|
|
|
<ul class={clsx(styles.viewSwitcher, 'view-switcher')}>
|
|
|
|
<li classList={{ selected: searchParams().by === 'shouts' }}>
|
2022-11-15 16:16:31 +00:00
|
|
|
<a href="/authors?by=shouts">{t('By shouts')}</a>
|
2022-11-11 10:22:07 +00:00
|
|
|
</li>
|
|
|
|
<li classList={{ selected: searchParams().by === 'rating' }}>
|
2022-11-15 16:16:31 +00:00
|
|
|
<a href="/authors?by=rating">{t('By rating')}</a>
|
2022-11-11 10:22:07 +00:00
|
|
|
</li>
|
|
|
|
<li classList={{ selected: !searchParams().by || searchParams().by === 'name' }}>
|
2022-11-15 16:16:31 +00:00
|
|
|
<a href="/authors">{t('By alphabet')}</a>
|
2022-11-11 10:22:07 +00:00
|
|
|
</li>
|
|
|
|
<li class="view-switcher__search">
|
|
|
|
<a href="/authors/search">
|
|
|
|
<Icon name="search" />
|
|
|
|
{t('Search author')}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-11-14 21:58:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Show
|
|
|
|
when={!searchParams().by || searchParams().by === 'name'}
|
|
|
|
fallback={() => (
|
|
|
|
<div class={styles.stats}>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-10 col-xl-9">
|
2022-11-13 19:35:57 +00:00
|
|
|
<For each={sortedAuthors().slice(0, limit())}>
|
2022-11-11 10:22:07 +00:00
|
|
|
{(author) => (
|
|
|
|
<AuthorCard
|
|
|
|
author={author}
|
|
|
|
compact={false}
|
|
|
|
hasLink={true}
|
|
|
|
subscribed={subscribed(author.slug)}
|
|
|
|
noSocialButtons={true}
|
|
|
|
isAuthorsList={true}
|
2022-11-16 21:08:04 +00:00
|
|
|
truncateBio={true}
|
2022-11-11 10:22:07 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
2022-11-14 21:58:33 +00:00
|
|
|
</div>
|
|
|
|
<Show when={sortedAuthors().length > limit()}>
|
|
|
|
<div class="row">
|
|
|
|
<div class={clsx(styles.loadMoreContainer, 'col-12 col-md-10')}>
|
|
|
|
<button class={clsx('button', styles.loadMoreButton)} onClick={showMore}>
|
2022-11-16 21:15:01 +00:00
|
|
|
{t('Load more')}
|
2022-11-14 21:58:33 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<For each={sortedKeys()}>
|
|
|
|
{(letter) => (
|
|
|
|
<div class={clsx(styles.group, 'group')}>
|
|
|
|
<h2>{letter}</h2>
|
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-10">
|
2022-11-11 10:22:07 +00:00
|
|
|
<div class="row">
|
|
|
|
<For each={byLetter()[letter]}>
|
|
|
|
{(author: Author) => (
|
2022-11-14 21:58:33 +00:00
|
|
|
<div class={clsx(styles.topic, 'topic col-sm-6 col-md-4')}>
|
2022-11-11 10:22:07 +00:00
|
|
|
<div class="topic-title">
|
|
|
|
<a href={`/author/${author.slug}`}>{author.name}</a>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
2022-11-11 10:22:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-11 10:22:07 +00:00
|
|
|
</div>
|
2022-11-14 21:58:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|