webapp/src/components/Feed/Sidebar.tsx

126 lines
3.5 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-09 11:53:35 +00:00
import { useAuthorsStore } from '../../stores/zine/authors'
import { t } from '../../utils/intl'
2022-11-14 17:41:05 +00:00
import { Icon } from '../_shared/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-11-14 10:02:08 +00:00
import { useSession } from '../../context/session'
2023-01-25 22:13:01 +00:00
import styles from './Sidebar.module.scss'
2022-09-09 11:53:35 +00:00
type FeedSidebarProps = {
authors: Author[]
}
export const FeedSidebar = (props: FeedSidebarProps) => {
2022-11-14 17:41:05 +00:00
const { seen } = useSeenStore()
2022-11-14 10:02:08 +00:00
const { session } = useSession()
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 (
2023-01-30 23:09:33 +00:00
<div class={styles.sidebar}>
2022-09-09 11:53:35 +00:00
<ul>
<li>
<a href="#">
2023-01-25 22:13:01 +00:00
<Icon name="feed-all" class={styles.icon} />
<strong>общая лента</strong>
2022-09-09 11:53:35 +00:00
</a>
</li>
<li>
<a href="#">
2023-01-25 22:13:01 +00:00
<Icon name="feed-my" class={styles.icon} />
моя лента
2022-09-09 11:53:35 +00:00
</a>
</li>
2023-01-25 22:13:01 +00:00
</ul>
<ul>
<li>
<a href="#">
<Icon name="feed-collaborate" class={styles.icon} />
соучастие
</a>
<span class={styles.counter}>7</span>
</li>
2022-09-09 11:53:35 +00:00
<li>
2023-01-25 22:13:01 +00:00
<a href="#">
<Icon name="feed-discussion" class={styles.icon} />
дискуссии
</a>
<span class={styles.counter}>18</span>
2022-09-09 11:53:35 +00:00
</li>
<li>
2023-01-25 22:13:01 +00:00
<a href="#">
<Icon name="feed-drafts" class={styles.icon} />
черновики
</a>
<span class={styles.counter}>283</span>
2022-09-09 11:53:35 +00:00
</li>
<li>
2023-01-25 22:13:01 +00:00
<a href="#">
<Icon name="bookmark" class={styles.icon} />
закладки
</a>
2022-09-09 11:53:35 +00:00
</li>
<li>
2023-01-25 22:13:01 +00:00
<a href="#">
<Icon name="feed-notifications" class={styles.icon} />
уведомления
</a>
2023-01-30 23:09:33 +00:00
<span class={styles.counter}>283</span>
2022-09-09 11:53:35 +00:00
</li>
</ul>
2023-01-25 22:13:01 +00:00
2022-09-09 11:53:35 +00:00
<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>
2023-01-25 22:13:01 +00:00
<a
href={`/author/${authorSlug}`}
classList={{ [styles.unread]: checkAuthorIsSeen(authorSlug) }}
>
2022-09-13 09:59:04 +00:00
<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>
2023-01-25 22:13:01 +00:00
<a href={`/author/${topicSlug}`} classList={{ [styles.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>
2023-01-25 22:13:01 +00:00
<div class={styles.settings}>
2022-09-09 11:53:35 +00:00
<a href="/feed/settings">
2023-01-25 22:13:01 +00:00
<Icon name="settings" class={styles.icon} />
{t('Feed settings')}
2022-09-09 11:53:35 +00:00
</a>
2022-10-25 21:45:37 +00:00
</div>
2023-01-30 23:09:33 +00:00
</div>
2022-09-09 11:53:35 +00:00
)
}