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'
|
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'
|
|
|
|
import { useAuthorsStore } 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-10-05 11:13:15 +00:00
|
|
|
import { getLogger } from '../../utils/logger'
|
2022-09-09 11:53:35 +00:00
|
|
|
import '../../styles/AllTopics.scss'
|
|
|
|
|
2022-10-05 11:13:15 +00:00
|
|
|
const log = getLogger('AllAuthorsView')
|
|
|
|
|
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-09 11:53:35 +00:00
|
|
|
const [sortedKeys, setSortedKeys] = createSignal<string[]>([])
|
|
|
|
const [abc, setAbc] = createSignal([])
|
2022-09-30 14:22:33 +00:00
|
|
|
|
|
|
|
const { session } = useAuthStore()
|
|
|
|
|
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-09-22 09:37:49 +00:00
|
|
|
const { getSearchParams } = useRouter<AllAuthorsPageSearchParams>()
|
2022-09-14 11:28:43 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
createEffect(() => {
|
2022-09-22 09:37:49 +00:00
|
|
|
if ((!getSearchParams().by || getSearchParams().by === 'name') && abc().length === 0) {
|
2022-09-09 11:53:35 +00:00
|
|
|
console.log('[authors] default grouping by abc')
|
2022-10-05 11:13:15 +00:00
|
|
|
const grouped = { ...groupByName(sortedAuthors()) }
|
2022-09-09 11:53:35 +00:00
|
|
|
grouped['A-Z'] = sortBy(grouped['A-Z'], byFirstChar)
|
|
|
|
setAbc(grouped)
|
|
|
|
const keys = Object.keys(abc)
|
|
|
|
keys.sort()
|
2022-10-05 11:13:15 +00:00
|
|
|
setSortedKeys(keys)
|
2022-09-09 11:53:35 +00:00
|
|
|
} else {
|
2022-09-22 09:37:49 +00:00
|
|
|
console.log('[authors] sorting by ' + getSearchParams().by)
|
2022-10-05 11:13:15 +00:00
|
|
|
///setSortedAuthors(sortBy(authorList(), getSearchParams().by))
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
2022-10-05 11:13:15 +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-09-22 09:37:49 +00:00
|
|
|
<li classList={{ selected: getSearchParams().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-22 09:37:49 +00:00
|
|
|
<li classList={{ selected: getSearchParams().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-22 09:37:49 +00:00
|
|
|
<li classList={{ selected: !getSearchParams().by || getSearchParams().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-09-22 09:37:49 +00:00
|
|
|
when={!getSearchParams().by || getSearchParams().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)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</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">
|
|
|
|
<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>
|
|
|
|
)
|
|
|
|
}
|