2023-11-14 15:10:00 +00:00
|
|
|
import { getPagePath } from '@nanostores/router'
|
|
|
|
import { clsx } from 'clsx'
|
2024-02-04 11:25:21 +00:00
|
|
|
import { For, Show, createSignal } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
import { useFollowing } from '../../../context/following'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2024-05-06 23:43:23 +00:00
|
|
|
import { useSeen } from '../../../context/seen'
|
2024-01-31 12:34:15 +00:00
|
|
|
import { Author } from '../../../graphql/schema/core.gen'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { router, useRouter } from '../../../stores/router'
|
2023-04-29 13:43:50 +00:00
|
|
|
import { useArticlesStore } from '../../../stores/zine/articles'
|
2023-08-11 16:42:41 +00:00
|
|
|
import { Userpic } from '../../Author/Userpic'
|
2024-02-04 11:25:21 +00:00
|
|
|
import { Icon } from '../../_shared/Icon'
|
2023-11-14 15:10:00 +00:00
|
|
|
import styles from './Sidebar.module.scss'
|
2023-04-29 13:43:50 +00:00
|
|
|
|
2023-10-23 11:15:19 +00:00
|
|
|
export const Sidebar = () => {
|
2023-04-29 13:43:50 +00:00
|
|
|
const { t } = useLocalize()
|
2024-05-06 23:43:23 +00:00
|
|
|
const { seen } = useSeen()
|
2024-01-31 12:34:15 +00:00
|
|
|
const { subscriptions } = useFollowing()
|
2023-07-07 16:53:01 +00:00
|
|
|
const { page } = useRouter()
|
2023-04-29 13:43:50 +00:00
|
|
|
const { articlesByTopic } = useArticlesStore()
|
2023-06-06 21:16:40 +00:00
|
|
|
const [isSubscriptionsVisible, setSubscriptionsVisible] = createSignal(true)
|
2023-04-29 13:43:50 +00:00
|
|
|
|
|
|
|
const checkTopicIsSeen = (topicSlug: string) => {
|
|
|
|
return articlesByTopic()[topicSlug]?.every((article) => Boolean(seen()[article.slug]))
|
|
|
|
}
|
|
|
|
|
|
|
|
const checkAuthorIsSeen = (authorSlug: string) => {
|
|
|
|
return Boolean(seen()[authorSlug])
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div class={styles.sidebar}>
|
2023-09-14 21:29:17 +00:00
|
|
|
<ul class={styles.feedFilters}>
|
2023-07-07 16:53:01 +00:00
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href={getPagePath(router, 'feed')}
|
|
|
|
class={clsx({
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.selected]: page().route === 'feed',
|
2023-07-07 16:53:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span class={styles.sidebarItemName}>
|
|
|
|
<Icon name="feed-all" class={styles.icon} />
|
2023-10-30 11:20:33 +00:00
|
|
|
{t('All')}
|
2023-07-07 16:53:01 +00:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href={getPagePath(router, 'feedMy')}
|
|
|
|
class={clsx({
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.selected]: page().route === 'feedMy',
|
2023-07-07 16:53:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span class={styles.sidebarItemName}>
|
|
|
|
<Icon name="feed-my" class={styles.icon} />
|
|
|
|
{t('My feed')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href={getPagePath(router, 'feedCollaborations')}
|
|
|
|
class={clsx({
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.selected]: page().route === 'feedCollaborations',
|
2023-07-07 16:53:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span class={styles.sidebarItemName}>
|
|
|
|
<Icon name="feed-collaborate" class={styles.icon} />
|
2023-10-30 11:20:33 +00:00
|
|
|
{t('Participation')}
|
2023-07-07 16:53:01 +00:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href={getPagePath(router, 'feedDiscussions')}
|
|
|
|
class={clsx({
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.selected]: page().route === 'feedDiscussions',
|
2023-07-07 16:53:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span class={styles.sidebarItemName}>
|
|
|
|
<Icon name="feed-discussion" class={styles.icon} />
|
|
|
|
{t('Discussions')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href={getPagePath(router, 'feedBookmarks')}
|
|
|
|
class={clsx({
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.selected]: page().route === 'feedBookmarks',
|
2023-07-07 16:53:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span class={styles.sidebarItemName}>
|
|
|
|
<Icon name="bookmark" class={styles.icon} />
|
|
|
|
{t('Bookmarks')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href={getPagePath(router, 'feedNotifications')}
|
|
|
|
class={clsx({
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.selected]: page().route === 'feedNotifications',
|
2023-07-07 16:53:01 +00:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span class={styles.sidebarItemName}>
|
|
|
|
<Icon name="feed-notifications" class={styles.icon} />
|
|
|
|
{t('Notifications')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
2023-04-29 13:43:50 +00:00
|
|
|
</ul>
|
2023-05-11 11:52:56 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
<Show when={subscriptions.authors.length > 0 || subscriptions.topics.length > 0}>
|
2023-05-11 11:52:56 +00:00
|
|
|
<h4
|
|
|
|
classList={{ [styles.opened]: isSubscriptionsVisible() }}
|
|
|
|
onClick={() => {
|
|
|
|
setSubscriptionsVisible(!isSubscriptionsVisible())
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('My subscriptions')}
|
2024-04-30 17:22:44 +00:00
|
|
|
<Icon name="toggle-arrow" class={styles.icon} />
|
2023-05-11 11:52:56 +00:00
|
|
|
</h4>
|
2023-06-06 21:16:40 +00:00
|
|
|
|
|
|
|
<ul class={clsx(styles.subscriptions, { [styles.hidden]: !isSubscriptionsVisible() })}>
|
2024-01-31 12:34:15 +00:00
|
|
|
<For each={subscriptions.authors}>
|
|
|
|
{(a: Author) => (
|
2023-05-11 11:52:56 +00:00
|
|
|
<li>
|
2024-01-31 12:34:15 +00:00
|
|
|
<a href={`/author/${a.slug}`} classList={{ [styles.unread]: checkAuthorIsSeen(a.slug) }}>
|
2023-06-06 21:16:40 +00:00
|
|
|
<div class={styles.sidebarItemName}>
|
2024-01-31 12:34:15 +00:00
|
|
|
<Userpic name={a.name} userpic={a.pic} size="XS" class={styles.userpic} />
|
|
|
|
<div class={styles.sidebarItemNameLabel}>{a.name}</div>
|
2023-06-06 21:16:40 +00:00
|
|
|
</div>
|
2023-05-11 11:52:56 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
2024-01-31 12:34:15 +00:00
|
|
|
<For each={subscriptions.topics}>
|
2023-10-19 15:05:22 +00:00
|
|
|
{(topic) => (
|
2023-05-11 11:52:56 +00:00
|
|
|
<li>
|
|
|
|
<a
|
2023-10-19 15:05:22 +00:00
|
|
|
href={`/topic/${topic.slug}`}
|
|
|
|
classList={{ [styles.unread]: checkTopicIsSeen(topic.slug) }}
|
2023-05-11 11:52:56 +00:00
|
|
|
>
|
2023-06-06 21:16:40 +00:00
|
|
|
<div class={styles.sidebarItemName}>
|
|
|
|
<Icon name="hash" class={styles.icon} />
|
2023-11-15 20:27:43 +00:00
|
|
|
<div class={styles.sidebarItemNameLabel}>{topic.title}</div>
|
2023-06-06 21:16:40 +00:00
|
|
|
</div>
|
2023-05-11 11:52:56 +00:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</Show>
|
|
|
|
|
2023-04-29 13:43:50 +00:00
|
|
|
<div class={styles.settings}>
|
2023-09-21 17:16:07 +00:00
|
|
|
<a href="/profile/subscriptions">
|
2023-04-29 13:43:50 +00:00
|
|
|
<Icon name="settings" class={styles.icon} />
|
2023-09-19 21:02:42 +00:00
|
|
|
<span class={styles.settingsLabel}>{t('Feed settings')}</span>
|
2023-04-29 13:43:50 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|