webapp/src/pages/edit.page.tsx

52 lines
1.5 KiB
TypeScript
Raw Normal View History

import { createEffect, 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 { useSession } from '../context/session'
import { Shout } from '../graphql/types.gen'
import { useRouter } from '../stores/router'
import { apiClient } from '../utils/apiClient'
import { useLocalize } from '../context/localize'
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 { t } = useLocalize()
2023-04-11 13:57:48 +00:00
const { isAuthenticated, isSessionLoaded } = useSession()
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>
<Show when={isSessionLoaded()}>
2023-05-10 20:20:53 +00:00
<Show
when={isAuthenticated()}
fallback={
<div class="wide-container">
<div class="row">
<div class="col-md-19 col-lg-18 col-xl-16 offset-md-5">{t("Let's log in")}</div>
2023-05-10 20:20:53 +00:00
</div>
</div>
}
>
2023-04-11 13:57:48 +00:00
<Show when={shout()}>
<Suspense fallback={<Loading />}>
<Edit shout={shout()} />
2023-04-11 13:57:48 +00:00
</Suspense>
</Show>
</Show>
</Show>
</PageLayout>
)
}
export const Page = EditPage