2022-09-09 13:30:25 +00:00
|
|
|
import { createEffect, 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'
|
|
|
|
import { byFirstChar, sortBy } from '../../utils/sortby'
|
|
|
|
import { groupByName } from '../../utils/groupby'
|
|
|
|
import Icon from '../Nav/Icon'
|
|
|
|
import { t } from '../../utils/intl'
|
|
|
|
import { useAuthorsStore } from '../../stores/zine/authors'
|
2022-09-14 11:28:43 +00:00
|
|
|
import { params as paramsStore, handleClientRouteLinkClick } from '../../stores/router'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { session } from '../../stores/auth'
|
|
|
|
import { useStore } from '@nanostores/solid'
|
|
|
|
import '../../styles/AllTopics.scss'
|
|
|
|
|
|
|
|
export const AllAuthorsPage = (props: any) => {
|
|
|
|
const { getSortedAuthors: authorslist } = useAuthorsStore(props.authors)
|
|
|
|
const [sortedAuthors, setSortedAuthors] = createSignal<Author[]>([])
|
|
|
|
const [sortedKeys, setSortedKeys] = createSignal<string[]>([])
|
|
|
|
const [abc, setAbc] = createSignal([])
|
|
|
|
const auth = useStore(session)
|
|
|
|
const subscribed = (s) => Boolean(auth()?.info?.authors && auth()?.info?.authors?.includes(s || ''))
|
2022-09-14 11:28:43 +00:00
|
|
|
|
2022-09-09 13:30:25 +00:00
|
|
|
const params = useStore(paramsStore)
|
2022-09-14 11:28:43 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
createEffect(() => {
|
2022-09-09 13:30:25 +00:00
|
|
|
if ((!params()['by'] || params()['by'] === 'abc') && abc().length === 0) {
|
2022-09-09 11:53:35 +00:00
|
|
|
console.log('[authors] default grouping by abc')
|
|
|
|
const grouped = { ...groupByName(authorslist()) }
|
|
|
|
grouped['A-Z'] = sortBy(grouped['A-Z'], byFirstChar)
|
|
|
|
setAbc(grouped)
|
|
|
|
const keys = Object.keys(abc)
|
|
|
|
keys.sort()
|
|
|
|
setSortedKeys(keys as string[])
|
|
|
|
} else {
|
2022-09-09 13:30:25 +00:00
|
|
|
console.log('[authors] sorting by ' + params()['by'])
|
|
|
|
setSortedAuthors(sortBy(authorslist(), params()['by']))
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
2022-09-09 13:30:25 +00:00
|
|
|
}, [authorslist(), params()])
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="all-topics-page">
|
|
|
|
<Show when={sortedAuthors()}>
|
|
|
|
<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-09-09 13:30:25 +00:00
|
|
|
<li classList={{ selected: params()['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-09-09 13:30:25 +00:00
|
|
|
<li classList={{ selected: params()['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-09-09 13:30:25 +00:00
|
|
|
<li classList={{ selected: !params()['by'] || params()['by'] === 'abc' }}>
|
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-09-09 13:30:25 +00:00
|
|
|
when={!params()['by'] || params()['by'] === 'abc'}
|
2022-09-09 11:53:35 +00:00
|
|
|
fallback={() => (
|
|
|
|
<div class="stats">
|
|
|
|
<For each={sortedAuthors()}>
|
|
|
|
{(author: Author) => (
|
|
|
|
<AuthorCard
|
|
|
|
author={author}
|
|
|
|
compact={false}
|
|
|
|
hasLink={true}
|
|
|
|
subscribed={subscribed(author.slug)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<For each={sortedKeys()}>
|
|
|
|
{(letter: string) => (
|
|
|
|
<div class="group">
|
|
|
|
<h2>{letter}</h2>
|
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
|
|
|
<For each={abc()[letter]}>
|
|
|
|
{(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>
|
|
|
|
)
|
|
|
|
}
|