webapp/src/components/Feed/Sidebar.tsx

98 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-09-09 11:53:35 +00:00
import { useStore } from '@nanostores/solid'
2022-09-13 09:59:04 +00:00
import { For } from 'solid-js'
import type { Author } from '../../graphql/types.gen'
2022-09-09 11:53:35 +00:00
import { session } from '../../stores/auth'
import { useAuthorsStore } from '../../stores/zine/authors'
import { t } from '../../utils/intl'
2022-09-22 09:37:49 +00:00
import { Icon } from '../Nav/Icon'
2022-09-13 09:59:04 +00:00
import { useTopicsStore } from '../../stores/zine/topics'
import { useArticlesStore } from '../../stores/zine/articles'
import { useSeenStore } from '../../stores/zine/seen'
2022-09-09 11:53:35 +00:00
type FeedSidebarProps = {
authors: Author[]
}
export const FeedSidebar = (props: FeedSidebarProps) => {
2022-09-13 09:59:04 +00:00
const { getSeen: seen } = useSeenStore()
2022-09-09 11:53:35 +00:00
const auth = useStore(session)
2022-09-13 09:59:04 +00:00
const { getSortedAuthors: authors } = useAuthorsStore({ authors: props.authors })
const { getArticlesByTopic } = useArticlesStore()
const { getTopicEntities } = useTopicsStore()
2022-09-09 11:53:35 +00:00
2022-09-13 09:59:04 +00:00
const checkTopicIsSeen = (topicSlug: string) => {
return getArticlesByTopic()[topicSlug].every((article) => Boolean(seen()[article.slug]))
}
const checkAuthorIsSeen = (authorSlug: string) => {
return Boolean(seen()[authorSlug])
}
2022-09-09 11:53:35 +00:00
return (
<>
<ul>
<li>
<a href="#">
<strong>Мои дискуссии</strong>
</a>
</li>
<li>
<a href="#">
<strong>Помощь сообществу</strong>
</a>
</li>
<li>
<a href="#">Редактирование</a>
<span class="counter">7</span>
</li>
<li>
<a href="#">Поделиться историей</a>
<span class="counter">18</span>
</li>
<li>
<a href="#">Проголосовать</a>
<span class="counter">283</span>
</li>
<li>
<a href="#">Подписки на форуме</a>
</li>
</ul>
<ul>
<li>
<a href="/feed?by=subscribed">
<strong>{t('My subscriptions')}</strong>
</a>
</li>
2022-09-13 09:59:04 +00:00
<For each={auth()?.info?.authors}>
{(authorSlug) => (
<li>
<a href={`/author/${authorSlug}`} classList={{ unread: checkAuthorIsSeen(authorSlug) }}>
<small>@{authorSlug}</small>
{authors()[authorSlug].name}
</a>
</li>
)}
</For>
<For each={auth()?.info?.topics}>
{(topicSlug) => (
<li>
<a href={`/author/${topicSlug}`} classList={{ unread: checkTopicIsSeen(topicSlug) }}>
{getTopicEntities()[topicSlug]?.title}
</a>
</li>
)}
</For>
2022-09-09 11:53:35 +00:00
</ul>
<p class="settings">
<a href="/feed/settings">
<strong>{t('Feed settings')}</strong>
</a>
<Icon name="settings" />
</p>
</>
)
}