webapp/src/pages/edit.page.tsx

66 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-02-04 11:25:21 +00:00
import { Show, Suspense, createMemo, createSignal, lazy, onMount } from 'solid-js'
2024-02-04 11:25:21 +00:00
import { AuthGuard } from '../components/AuthGuard'
2023-04-11 13:57:48 +00:00
import { Loading } from '../components/_shared/Loading'
import { PageLayout } from '../components/_shared/PageLayout'
import { useLocalize } from '../context/localize'
2023-11-28 13:18:25 +00:00
import { apiClient } from '../graphql/client/core'
import { Shout } from '../graphql/schema/core.gen'
2023-04-11 13:57:48 +00:00
import { useRouter } from '../stores/router'
import { LayoutType } from './types'
2023-04-11 13:57:48 +00:00
2024-02-13 13:09:44 +00:00
const EditView = lazy(() => import('../components/Views/EditView/EditView'))
2023-04-11 13:57:48 +00:00
export const EditPage = () => {
const { page } = useRouter()
const { t } = useLocalize()
2023-04-11 13:57:48 +00:00
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)
})
const title = createMemo(() => {
if (!shout()) {
return t('Create post')
}
switch (shout().layout as LayoutType) {
2023-11-28 13:18:25 +00:00
case 'audio': {
return t('Publish Album')
}
case 'image': {
return t('Create gallery')
}
case 'video': {
return t('Create video')
}
case 'literature': {
return t('New literary work')
}
default: {
return t('Write an article')
}
}
})
2023-04-11 13:57:48 +00:00
return (
<PageLayout title={title()}>
<AuthGuard>
<Show when={shout()}>
<Suspense fallback={<Loading />}>
2024-02-13 13:09:44 +00:00
<EditView 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