2024-03-07 10:03:19 +00:00
|
|
|
import { Show, Suspense, createEffect, createMemo, createSignal, lazy, on, 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
|
|
|
|
2024-03-05 13:07:14 +00:00
|
|
|
import { redirectPage } from '@nanostores/router'
|
|
|
|
import { useSnackbar } from '../context/snackbar'
|
2023-11-14 10:45:44 +00:00
|
|
|
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()
|
2024-03-05 13:07:14 +00:00
|
|
|
const snackbar = useSnackbar()
|
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)
|
|
|
|
|
2024-03-07 10:03:19 +00:00
|
|
|
createEffect(
|
|
|
|
on(shoutId, async (shout_id) => {
|
|
|
|
const { shout: loadedShout, error } = await apiClient.getMyShout(shout_id)
|
|
|
|
console.log(loadedShout)
|
|
|
|
if (error) {
|
|
|
|
await snackbar?.showSnackbar({ type: 'error', body: t('This content is not published yet') })
|
|
|
|
redirectPage(router, 'drafts')
|
|
|
|
} else {
|
|
|
|
setShout(loadedShout)
|
|
|
|
}
|
2024-03-07 10:14:22 +00:00
|
|
|
}, { defer: true }),
|
2024-03-07 10:03:19 +00:00
|
|
|
)
|
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
|