2022-10-07 19:35:53 +00:00
|
|
|
import { createEffect, createMemo, 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-09-22 09:37:49 +00:00
|
|
|
import { Icon } from '../Nav/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-09-22 09:37:49 +00:00
|
|
|
import { handleClientRouteLinkClick, useRouter } from '../../stores/router'
|
2022-09-30 14:22:33 +00:00
|
|
|
import { useAuthStore } from '../../stores/auth'
|
2022-09-09 11:53:35 +00:00
|
|
|
import '../../styles/AllTopics.scss'
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
type AllAuthorsPageSearchParams = {
|
|
|
|
by: '' | 'name' | 'shouts' | 'rating'
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
authors: Author[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const AllAuthorsView = (props: Props) => {
|
2022-10-05 11:13:15 +00:00
|
|
|
const { sortedAuthors } = useAuthorsStore({ authors: props.authors })
|
2022-09-30 14:22:33 +00:00
|
|
|
|
|
|
|
const { session } = useAuthStore()
|
|
|
|
|
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-10-05 15:56:59 +00:00
|
|
|
// log.debug(getSearchParams())
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="all-topics-page">
|
2022-09-28 20:16:44 +00:00
|
|
|
<Show when={sortedAuthors().length > 0}>
|
2022-09-09 11:53:35 +00:00
|
|
|
<div class="wide-container">
|
|
|
|
<div class="shift-content">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-9 page-header">
|
|
|
|
<h1>{t('Authors')}</h1>
|
|
|
|
<p>{t('Subscribe who you like to tune your personal feed')}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col">
|
|
|
|
<ul class="view-switcher">
|
2022-10-21 18:17:04 +00:00
|
|
|
<li classList={{ selected: searchParams().by === 'shouts' }}>
|
2022-09-14 11:28:43 +00:00
|
|
|
<a href="/authors?by=shouts" onClick={handleClientRouteLinkClick}>
|
2022-09-09 11:53:35 +00:00
|
|
|
{t('By shouts')}
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-10-21 18:17:04 +00:00
|
|
|
<li classList={{ selected: searchParams().by === 'rating' }}>
|
2022-09-14 11:28:43 +00:00
|
|
|
<a href="/authors?by=rating" onClick={handleClientRouteLinkClick}>
|
2022-09-09 11:53:35 +00:00
|
|
|
{t('By rating')}
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-10-21 18:17:04 +00:00
|
|
|
<li classList={{ selected: !searchParams().by || searchParams().by === 'name' }}>
|
2022-09-14 11:28:43 +00:00
|
|
|
<a href="/authors" onClick={handleClientRouteLinkClick}>
|
2022-09-09 11:53:35 +00:00
|
|
|
{t('By alphabet')}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li class="view-switcher__search">
|
|
|
|
<a href="/authors/search">
|
|
|
|
<Icon name="search" />
|
|
|
|
{t('Search author')}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<Show
|
2022-10-21 18:17:04 +00:00
|
|
|
when={!searchParams().by || searchParams().by === 'name'}
|
2022-09-09 11:53:35 +00:00
|
|
|
fallback={() => (
|
|
|
|
<div class="stats">
|
|
|
|
<For each={sortedAuthors()}>
|
2022-10-05 11:13:15 +00:00
|
|
|
{(author) => (
|
2022-09-09 11:53:35 +00:00
|
|
|
<AuthorCard
|
|
|
|
author={author}
|
|
|
|
compact={false}
|
|
|
|
hasLink={true}
|
|
|
|
subscribed={subscribed(author.slug)}
|
2022-10-19 21:40:50 +00:00
|
|
|
noSocialButtons={true}
|
2022-09-09 11:53:35 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<For each={sortedKeys()}>
|
2022-10-05 11:13:15 +00:00
|
|
|
{(letter) => (
|
2022-09-09 11:53:35 +00:00
|
|
|
<div class="group">
|
|
|
|
<h2>{letter}</h2>
|
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
2022-10-05 15:56:59 +00:00
|
|
|
<For each={byLetter()[letter]}>
|
2022-09-09 11:53:35 +00:00
|
|
|
{(author: Author) => (
|
|
|
|
<div class="topic col-sm-6 col-md-3">
|
|
|
|
<div class="topic-title">
|
|
|
|
<a href={`/author/${author.slug}`}>{author.name}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|