2023-11-14 15:10:00 +00:00
|
|
|
import { createEffect, Match, on, onCleanup, Switch } from 'solid-js'
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
import { PageLayout } from '../components/_shared/PageLayout'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { AuthGuard } from '../components/AuthGuard'
|
2023-12-14 18:45:50 +00:00
|
|
|
import { Feed } from '../components/Views/Feed'
|
2023-11-14 15:10:00 +00:00
|
|
|
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'
|
2023-11-14 15:10:00 +00:00
|
|
|
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 = () => {
|
2023-11-14 10:45:44 +00:00
|
|
|
const { t } = useLocalize()
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2023-09-29 12:48:58 +00:00
|
|
|
const { page } = useRouter()
|
|
|
|
|
2023-11-01 11:17:31 +00:00
|
|
|
createEffect(
|
|
|
|
on(
|
|
|
|
() => page().route,
|
|
|
|
() => {
|
|
|
|
resetSortedArticles()
|
|
|
|
},
|
2023-11-14 15:10:00 +00:00
|
|
|
{ defer: true },
|
|
|
|
),
|
2023-11-01 11:17:31 +00:00
|
|
|
)
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
return (
|
2023-11-14 10:45:44 +00:00
|
|
|
<PageLayout title={t('Feed')}>
|
2023-02-17 09:21:02 +00:00
|
|
|
<ReactionsProvider>
|
2023-12-14 18:45:50 +00:00
|
|
|
<Switch fallback={<Feed loadShouts={handleFeedLoadShouts} />}>
|
2023-09-29 12:48:58 +00:00
|
|
|
<Match when={page().route === 'feed'}>
|
2023-12-14 18:45:50 +00:00
|
|
|
<Feed loadShouts={handleFeedLoadShouts} />
|
2023-09-29 12:48:58 +00:00
|
|
|
</Match>
|
|
|
|
<Match when={page().route === 'feedMy'}>
|
|
|
|
<AuthGuard>
|
2023-12-14 18:45:50 +00:00
|
|
|
<Feed loadShouts={handleMyFeedLoadShouts} />
|
2023-09-29 12:48:58 +00:00
|
|
|
</AuthGuard>
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
2023-02-17 09:21:02 +00:00
|
|
|
</ReactionsProvider>
|
|
|
|
</PageLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Page = FeedPage
|