2023-06-16 14:47:24 +00:00
|
|
|
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'
|
2023-09-21 11:38:22 +00:00
|
|
|
import { AuthGuard } from '../components/AuthGuard'
|
2023-04-11 13:57:48 +00:00
|
|
|
|
2023-06-10 14:10:05 +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>
|
2023-09-21 11:38:22 +00:00
|
|
|
<AuthGuard>
|
|
|
|
<Show when={shout()}>
|
|
|
|
<Suspense fallback={<Loading />}>
|
|
|
|
<Edit shout={shout()} />
|
|
|
|
</Suspense>
|
2023-04-11 13:57:48 +00:00
|
|
|
</Show>
|
2023-09-21 11:38:22 +00:00
|
|
|
</AuthGuard>
|
2023-04-11 13:57:48 +00:00
|
|
|
</PageLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Page = EditPage
|