webapp/src/components/Views/AllTopics.tsx

130 lines
4.8 KiB
TypeScript
Raw Normal View History

2022-09-22 09:37:49 +00:00
import { createEffect, For, Show } from 'solid-js'
2022-09-09 11:53:35 +00:00
import type { Topic } from '../../graphql/types.gen'
2022-09-22 09:37:49 +00:00
import { Icon } from '../Nav/Icon'
2022-09-09 11:53:35 +00:00
import { t } from '../../utils/intl'
2022-09-22 09:37:49 +00:00
import { setSortAllTopicsBy, useTopicsStore } from '../../stores/zine/topics'
import { handleClientRouteLinkClick, useRouter } from '../../stores/router'
2022-09-09 11:53:35 +00:00
import { TopicCard } from '../Topic/Card'
import { session } from '../../stores/auth'
import { useStore } from '@nanostores/solid'
import '../../styles/AllTopics.scss'
2022-09-22 09:37:49 +00:00
type AllTopicsPageSearchParams = {
by: 'shouts' | 'authors' | 'title' | ''
}
2022-09-14 11:28:43 +00:00
2022-09-22 09:37:49 +00:00
type Props = {
topics: Topic[]
}
export const AllTopicsView = (props: Props) => {
const { getSearchParams, changeSearchParam } = useRouter<AllTopicsPageSearchParams>()
2022-09-14 11:28:43 +00:00
2022-09-22 09:37:49 +00:00
const { getSortedTopics } = useTopicsStore({
topics: props.topics,
sortBy: getSearchParams().by || 'shouts'
})
const auth = useStore(session)
2022-09-14 11:28:43 +00:00
2022-09-09 11:53:35 +00:00
createEffect(() => {
2022-09-22 09:37:49 +00:00
setSortAllTopicsBy(getSearchParams().by || 'shouts')
})
const subscribed = (s) => Boolean(auth()?.info?.topics && auth()?.info?.topics?.includes(s || ''))
2022-09-09 11:53:35 +00:00
return (
2022-09-14 11:28:43 +00:00
<div class="all-topics-page">
<Show when={getSortedTopics().length > 0}>
<div class="wide-container">
<div class="shift-content">
<div class="row">
<div class="col-md-9 page-header">
<h1>{t('Topics')}</h1>
<p>{t('Subscribe what you like to tune your personal feed')}</p>
2022-09-09 11:53:35 +00:00
</div>
2022-09-14 11:28:43 +00:00
</div>
2022-09-09 11:53:35 +00:00
2022-09-14 11:28:43 +00:00
<div class="row">
<div class="col">
<ul class="view-switcher">
2022-09-22 09:37:49 +00:00
<li classList={{ selected: getSearchParams().by === 'shouts' || !getSearchParams().by }}>
2022-09-14 11:28:43 +00:00
<a href="/topics?by=shouts" onClick={handleClientRouteLinkClick}>
{t('By shouts')}
</a>
</li>
2022-09-22 09:37:49 +00:00
<li classList={{ selected: getSearchParams().by === 'authors' }}>
2022-09-14 11:28:43 +00:00
<a href="/topics?by=authors" onClick={handleClientRouteLinkClick}>
{t('By authors')}
</a>
</li>
2022-09-22 09:37:49 +00:00
<li classList={{ selected: getSearchParams().by === 'title' }}>
<a
href="/topics?by=title"
onClick={(ev) => {
// just an example
ev.preventDefault()
changeSearchParam('by', 'title')
}}
>
2022-09-14 11:28:43 +00:00
{t('By alphabet')}
</a>
</li>
<li class="view-switcher__search">
<a href="/topic/search">
<Icon name="search" />
{t('Search topic')}
</a>
</li>
</ul>
2022-09-09 11:53:35 +00:00
2022-09-14 11:28:43 +00:00
<div class="stats">
<For each={getSortedTopics()}>
{(topic) => (
<TopicCard topic={topic} compact={false} subscribed={subscribed(topic.slug)} />
2022-09-09 11:53:35 +00:00
)}
2022-09-14 11:28:43 +00:00
</For>
2022-09-09 11:53:35 +00:00
</div>
2022-09-14 11:28:43 +00:00
{/*FIXME*/}
{/*<Show*/}
{/* when={params()['by'] === 'abc'}*/}
{/* fallback={() => (*/}
{/* <div class="stats">*/}
{/* <For each={getSortedTopics()}>*/}
{/* {(topic: Topic) => (*/}
{/* <TopicCard topic={topic} compact={false} subscribed={subscribed(topic.slug)} />*/}
{/* )}*/}
{/* </For>*/}
{/* </div>*/}
{/* )}*/}
{/*>*/}
{/* <For each={sortedKeys() || []}>*/}
{/* {(letter: string) => (*/}
{/* <div class="group">*/}
{/* <h2>{letter}</h2>*/}
{/* <div class="container">*/}
{/* <div class="row">*/}
{/* <For each={abc()[letter]}>*/}
{/* {(topic: Partial<Topic>) => (*/}
{/* <div class="topic col-sm-6 col-md-3">*/}
{/* <div class="topic-title">*/}
{/* <a href={`/topic/${topic.slug}`}>{topic.title}</a>*/}
{/* </div>*/}
{/* </div>*/}
{/* )}*/}
{/* </For>*/}
{/* </div>*/}
{/* </div>*/}
{/* </div>*/}
{/* )}*/}
{/* </For>*/}
{/*</Show>*/}
2022-09-09 11:53:35 +00:00
</div>
</div>
</div>
2022-09-14 11:28:43 +00:00
</div>
</Show>
</div>
2022-09-09 11:53:35 +00:00
)
}