webapp/src/pages/edit.page.tsx

37 lines
1.0 KiB
TypeScript
Raw Normal View History

import { createMemo, createSignal, lazy, onMount, Show, Suspense } from 'solid-js'
2023-04-11 13:57:48 +00:00
import { PageLayout } from '../components/_shared/PageLayout'
import { Loading } from '../components/_shared/Loading'
import { Shout } from '../graphql/types.gen'
import { useRouter } from '../stores/router'
import { apiClient } from '../utils/apiClient'
import { AuthGuard } from '../components/AuthGuard'
2023-04-11 13:57:48 +00:00
const Edit = lazy(() => import('../components/Views/Edit'))
2023-04-11 13:57:48 +00:00
export const EditPage = () => {
const { page } = useRouter()
2023-05-08 17:21:06 +00:00
const shoutId = createMemo(() => Number((page().params as Record<'shoutId', string>).shoutId))
2023-04-11 13:57:48 +00:00
const [shout, setShout] = createSignal<Shout>(null)
onMount(async () => {
2023-05-08 17:21:06 +00:00
const loadedShout = await apiClient.getShoutById(shoutId())
2023-04-11 13:57:48 +00:00
setShout(loadedShout)
})
return (
<PageLayout>
<AuthGuard>
<Show when={shout()}>
<Suspense fallback={<Loading />}>
<Edit shout={shout()} />
</Suspense>
2023-04-11 13:57:48 +00:00
</Show>
</AuthGuard>
2023-04-11 13:57:48 +00:00
</PageLayout>
)
}
export const Page = EditPage