2024-02-04 11:25:21 +00:00
|
|
|
import { Show, Suspense, createMemo, createSignal, lazy, onMount } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
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'
|
2023-11-14 15:10:00 +00:00
|
|
|
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'
|
2024-03-05 13:01:47 +00:00
|
|
|
import { router } from '../stores/router'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-11-14 10:45:44 +00:00
|
|
|
import { LayoutType } from './types'
|
2024-03-05 13:01:47 +00:00
|
|
|
import { redirectPage } from "@nanostores/router";
|
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()
|
2023-11-14 10:45:44 +00:00
|
|
|
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 () => {
|
2024-03-05 13:01:47 +00:00
|
|
|
const loadedShout = await apiClient.getMyShout(shoutId())
|
|
|
|
console.log(loadedShout)
|
|
|
|
if (loadedShout) {
|
|
|
|
setShout(loadedShout)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
redirectPage(router, 'drafts')
|
|
|
|
}
|
2023-04-11 13:57:48 +00:00
|
|
|
})
|
|
|
|
|
2023-11-14 10:45:44 +00:00
|
|
|
const title = createMemo(() => {
|
|
|
|
if (!shout()) {
|
|
|
|
return t('Create post')
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (shout().layout as LayoutType) {
|
2023-11-28 13:18:25 +00:00
|
|
|
case 'audio': {
|
2023-11-14 10:45:44 +00:00
|
|
|
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 (
|
2023-11-14 10:45:44 +00:00
|
|
|
<PageLayout title={title()}>
|
2023-09-21 11:38:22 +00:00
|
|
|
<AuthGuard>
|
|
|
|
<Show when={shout()}>
|
|
|
|
<Suspense fallback={<Loading />}>
|
2024-02-13 13:09:44 +00:00
|
|
|
<EditView shout={shout()} />
|
2023-09-21 11:38:22 +00:00
|
|
|
</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
|