webapp/src/components/Feed/Sidebar.tsx

97 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-09-13 09:59:04 +00:00
import { For } from 'solid-js'
import type { Author } from '../../graphql/types.gen'
2022-09-30 14:22:33 +00:00
import { useAuthStore } from '../../stores/auth'
2022-09-09 11:53:35 +00:00
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'
2022-11-13 06:47:17 +00:00
import { seen } from '../../stores/zine/seen'
2022-09-09 11:53:35 +00:00
type FeedSidebarProps = {
authors: Author[]
}
export const FeedSidebar = (props: FeedSidebarProps) => {
2022-11-13 06:47:17 +00:00
const getSeen = seen
2022-09-30 14:22:33 +00:00
const { session } = useAuthStore()
2022-09-28 20:16:44 +00:00
const { authorEntities } = useAuthorsStore({ authors: props.authors })
const { articlesByTopic } = useArticlesStore()
const { topicEntities } = useTopicsStore()
2022-09-09 11:53:35 +00:00
2022-09-13 09:59:04 +00:00
const checkTopicIsSeen = (topicSlug: string) => {
2022-09-28 20:16:44 +00:00
return articlesByTopic()[topicSlug].every((article) => Boolean(seen()[article.slug]))
2022-09-13 09:59:04 +00:00
}
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-10-04 12:16:07 +00:00
<For each={session()?.news?.authors}>
{(authorSlug: string) => (
2022-09-13 09:59:04 +00:00
<li>
<a href={`/author/${authorSlug}`} classList={{ unread: checkAuthorIsSeen(authorSlug) }}>
<small>@{authorSlug}</small>
2022-09-28 20:16:44 +00:00
{authorEntities()[authorSlug].name}
2022-09-13 09:59:04 +00:00
</a>
</li>
)}
</For>
2022-10-04 12:16:07 +00:00
<For each={session()?.news?.topics}>
{(topicSlug: string) => (
2022-09-13 09:59:04 +00:00
<li>
<a href={`/author/${topicSlug}`} classList={{ unread: checkTopicIsSeen(topicSlug) }}>
2022-09-28 20:16:44 +00:00
{topicEntities()[topicSlug]?.title}
2022-09-13 09:59:04 +00:00
</a>
</li>
)}
</For>
2022-09-09 11:53:35 +00:00
</ul>
2022-10-25 21:45:37 +00:00
<div class="settings">
2022-09-09 11:53:35 +00:00
<a href="/feed/settings">
<strong>{t('Feed settings')}</strong>
2022-10-25 21:45:37 +00:00
<Icon name="settings" />
2022-09-09 11:53:35 +00:00
</a>
2022-10-25 21:45:37 +00:00
</div>
2022-09-09 11:53:35 +00:00
</>
)
}