webapp/src/components/Views/Author.tsx

117 lines
4.2 KiB
TypeScript
Raw Normal View History

2022-09-13 08:05:11 +00:00
import { Show, createMemo } from 'solid-js'
2022-09-22 09:37:49 +00:00
import type { Author, Shout } from '../../graphql/types.gen'
2022-09-09 11:53:35 +00:00
import Row2 from '../Feed/Row2'
import Row3 from '../Feed/Row3'
2022-09-22 09:37:49 +00:00
// import Beside from '../Feed/Beside'
2022-09-09 11:53:35 +00:00
import AuthorFull from '../Author/Full'
import { t } from '../../utils/intl'
import { useAuthorsStore } from '../../stores/zine/authors'
import { useArticlesStore } from '../../stores/zine/articles'
import '../../styles/Topic.scss'
2022-10-09 10:56:39 +00:00
import { useTopicsStore } from '../../stores/zine/topics'
2022-09-22 09:37:49 +00:00
import { useRouter } from '../../stores/router'
2022-10-09 10:56:39 +00:00
import Beside from '../Feed/Beside'
2022-09-09 11:53:35 +00:00
2022-09-13 13:38:26 +00:00
// TODO: load reactions on client
2022-09-09 11:53:35 +00:00
type AuthorProps = {
authorArticles: Shout[]
author: Author
2022-10-05 15:11:14 +00:00
authorSlug: string
2022-09-13 13:38:26 +00:00
// FIXME author topics fro server
// topics: Topic[]
2022-09-09 11:53:35 +00:00
}
2022-09-22 09:37:49 +00:00
type AuthorPageSearchParams = {
by: '' | 'viewed' | 'rating' | 'commented' | 'recent'
}
export const AuthorView = (props: AuthorProps) => {
2022-09-28 20:16:44 +00:00
const { sortedArticles } = useArticlesStore({
2022-09-09 11:53:35 +00:00
sortedArticles: props.authorArticles
})
2022-09-28 20:16:44 +00:00
const { authorEntities } = useAuthorsStore({ authors: [props.author] })
2022-10-09 10:56:39 +00:00
const { topicsByAuthor } = useTopicsStore()
2022-09-13 09:59:04 +00:00
2022-10-05 15:11:14 +00:00
const author = createMemo(() => authorEntities()[props.authorSlug])
2022-09-22 09:37:49 +00:00
const { getSearchParams, changeSearchParam } = useRouter<AuthorPageSearchParams>()
2022-09-13 09:59:04 +00:00
2022-09-09 11:53:35 +00:00
const title = createMemo(() => {
2022-09-22 09:37:49 +00:00
const m = getSearchParams().by
2022-09-09 11:53:35 +00:00
if (m === 'viewed') return t('Top viewed')
if (m === 'rating') return t('Top rated')
if (m === 'commented') return t('Top discussed')
return t('Top recent')
})
return (
<div class="container author-page">
<Show when={author()} fallback={<div class="center">{t('Loading')}</div>}>
<AuthorFull author={author()} />
<div class="row group__controls">
<div class="col-md-8">
<ul class="view-switcher">
2022-09-22 09:37:49 +00:00
<li classList={{ selected: !getSearchParams().by || getSearchParams().by === 'recent' }}>
<button type="button" onClick={() => changeSearchParam('by', 'recent')}>
2022-09-09 11:53:35 +00:00
{t('Recent')}
</button>
</li>
2022-10-09 10:56:39 +00:00
{/*TODO: server sort*/}
{/*<li classList={{ selected: getSearchParams().by === 'rating' }}>*/}
{/* <button type="button" onClick={() => changeSearchParam('by', 'rating')}>*/}
{/* {t('Popular')}*/}
{/* </button>*/}
{/*</li>*/}
{/*<li classList={{ selected: getSearchParams().by === 'viewed' }}>*/}
{/* <button type="button" onClick={() => changeSearchParam('by', 'viewed')}>*/}
{/* {t('Views')}*/}
{/* </button>*/}
{/*</li>*/}
{/*<li classList={{ selected: getSearchParams().by === 'commented' }}>*/}
{/* <button type="button" onClick={() => changeSearchParam('by', 'commented')}>*/}
{/* {t('Discussing')}*/}
{/* </button>*/}
{/*</li>*/}
2022-09-09 11:53:35 +00:00
</ul>
</div>
<div class="col-md-4">
<div class="mode-switcher">
{`${t('Show')} `}
<span class="mode-switcher__control">{t('All posts')}</span>
</div>
</div>
</div>
<h3 class="col-12">{title()}</h3>
<div class="row">
<Show when={sortedArticles().length > 0}>
<Beside
title={t('Topics which supported by author')}
values={topicsByAuthor()[author().slug].slice(0, 5)}
beside={sortedArticles()[0]}
wrapper={'topic'}
topicShortDescription={true}
isTopicCompact={true}
isTopicInRow={true}
iconButton={true}
/>
<Row3 articles={sortedArticles().slice(1, 4)} />
<Show when={sortedArticles().length > 4}>
2022-09-28 20:16:44 +00:00
<Row2 articles={sortedArticles().slice(4, 6)} />
</Show>
<Show when={sortedArticles().length > 6}>
2022-10-05 15:11:14 +00:00
<Row3 articles={sortedArticles().slice(6, 9)} />
</Show>
<Show when={sortedArticles().length > 9}>
2022-10-05 15:11:14 +00:00
<Row3 articles={sortedArticles().slice(9, 12)} />
2022-09-09 11:53:35 +00:00
</Show>
</Show>
2022-09-09 11:53:35 +00:00
</div>
</Show>
</div>
)
}