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 { useSession } from '../context/session'
|
|
|
|
import { Shout } from '../graphql/types.gen'
|
|
|
|
import { useRouter } from '../stores/router'
|
|
|
|
import { apiClient } from '../utils/apiClient'
|
2023-06-10 14:10:05 +00:00
|
|
|
import { useLocalize } from '../context/localize'
|
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 = () => {
|
2023-06-10 14:10:05 +00:00
|
|
|
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">
|
2023-06-10 14:10:05 +00:00
|
|
|
<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 />}>
|
2023-06-10 14:10:05 +00:00
|
|
|
<Edit shout={shout()} />
|
2023-04-11 13:57:48 +00:00
|
|
|
</Suspense>
|
|
|
|
</Show>
|
|
|
|
</Show>
|
|
|
|
</Show>
|
|
|
|
</PageLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Page = EditPage
|