webapp/src/pages/feed.page.tsx

59 lines
1.6 KiB
TypeScript
Raw Normal View History

import { createEffect, Match, on, onCleanup, Switch } from 'solid-js'
2023-02-17 09:21:02 +00:00
import { PageLayout } from '../components/_shared/PageLayout'
import { AuthGuard } from '../components/AuthGuard'
import { Feed } from '../components/Views/Feed'
import { useLocalize } from '../context/localize'
2023-02-17 09:21:02 +00:00
import { ReactionsProvider } from '../context/reactions'
2023-11-28 13:18:25 +00:00
import { LoadShoutsOptions } from '../graphql/schema/core.gen'
import { useRouter } from '../stores/router'
import { loadMyFeed, loadShouts, resetSortedArticles } from '../stores/zine/articles'
2023-02-17 09:21:02 +00:00
2023-11-04 15:37:28 +00:00
const handleFeedLoadShouts = (options: LoadShoutsOptions) => {
return loadShouts({
...options,
2023-11-29 12:42:48 +00:00
filters: { published: false },
2023-11-04 15:37:28 +00:00
})
}
const handleMyFeedLoadShouts = (options: LoadShoutsOptions) => {
return loadMyFeed(options)
}
2023-02-17 09:21:02 +00:00
export const FeedPage = () => {
const { t } = useLocalize()
2023-02-17 09:21:02 +00:00
onCleanup(() => resetSortedArticles())
const { page } = useRouter()
createEffect(
on(
() => page().route,
() => {
resetSortedArticles()
},
{ defer: true },
),
)
2023-02-17 09:21:02 +00:00
return (
<PageLayout title={t('Feed')}>
2023-02-17 09:21:02 +00:00
<ReactionsProvider>
<Switch fallback={<Feed loadShouts={handleFeedLoadShouts} />}>
<Match when={page().route === 'feed'}>
<Feed loadShouts={handleFeedLoadShouts} />
</Match>
<Match when={page().route === 'feedMy'}>
<AuthGuard>
<Feed loadShouts={handleMyFeedLoadShouts} />
</AuthGuard>
</Match>
</Switch>
2023-02-17 09:21:02 +00:00
</ReactionsProvider>
</PageLayout>
)
}
export const Page = FeedPage