webapp/src/components/Pages/LayoutShoutsPage.tsx

50 lines
1.3 KiB
TypeScript
Raw Normal View History

import { PageWrap } from '../Wraps/PageWrap'
2022-11-13 09:25:31 +00:00
import { LayoutType, LayoutView } from '../Views/LayoutView'
2022-11-12 18:59:29 +00:00
import type { PageProps } from '../types'
import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js'
import { resetSortedArticles } from '../../stores/zine/articles'
import { useRouter } from '../../stores/router'
2022-11-13 09:25:31 +00:00
import { loadRecentLayoutShouts } from '../../stores/zine/layouts'
2022-11-12 18:59:29 +00:00
import { Loading } from '../Loading'
const PER_PAGE = 50
export const LayoutShoutsPage = (props: PageProps) => {
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.shouts))
2022-11-13 09:25:31 +00:00
const layout = createMemo<LayoutType>(() => {
2022-11-12 18:59:29 +00:00
const { page: getPage } = useRouter()
const page = getPage()
2022-11-13 06:47:17 +00:00
if (page.route !== 'expo') {
2022-11-12 18:59:29 +00:00
throw new Error('ts guard')
}
2022-11-13 09:25:31 +00:00
return page.params.layout as LayoutType
2022-11-12 18:59:29 +00:00
})
onMount(async () => {
if (isLoaded()) {
return
}
2022-11-13 09:25:31 +00:00
await loadRecentLayoutShouts({ layout: layout(), amount: PER_PAGE, offset: 0 })
2022-11-12 18:59:29 +00:00
setIsLoaded(true)
})
onCleanup(() => resetSortedArticles())
return (
<PageWrap>
2022-11-12 18:59:29 +00:00
<Show when={isLoaded()} fallback={<Loading />}>
2022-11-13 09:25:31 +00:00
<LayoutView layout={layout() as LayoutType} shouts={props.shouts} />
2022-11-12 18:59:29 +00:00
</Show>
</PageWrap>
2022-11-12 18:59:29 +00:00
)
}
// for lazy loading
export default LayoutShoutsPage