new-draft-store-fix

This commit is contained in:
Untone 2024-09-24 10:59:54 +03:00
parent c959a2bba4
commit 7288725480
2 changed files with 16 additions and 3 deletions

View File

@ -73,7 +73,7 @@ export const EditView = (props: Props) => {
const [isLeadVisible, setIsLeadVisible] = createSignal(Boolean(form.lead))
const [isScrolled, setIsScrolled] = createSignal(false)
const [shoutTopics, setShoutTopics] = createSignal<Topic[]>([])
const [draft, setDraft] = createSignal<Shout>()
const [draft, setDraft] = createSignal<Shout>(props.shout)
const [mediaItems, setMediaItems] = createSignal<MediaItem[]>([])
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))

View File

@ -6,6 +6,7 @@ import { Button } from '~/components/_shared/Button'
import { Icon } from '~/components/_shared/Icon'
import { PageLayout } from '~/components/_shared/PageLayout'
import { coreApiUrl } from '~/config'
import { useEditorContext } from '~/context/editor'
import { useLocalize } from '~/context/localize'
import { useSession } from '~/context/session'
import { useSnackbar } from '~/context/ui'
@ -17,6 +18,7 @@ import { LayoutType } from '~/types/common'
export default () => {
const { t } = useLocalize()
const { session } = useSession()
const { saveDraftToLocalStorage } = useEditorContext()
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
const { showSnackbar } = useSnackbar()
@ -29,12 +31,23 @@ export default () => {
if (result) {
console.debug(result)
const { shout, error } = result.data.create_shout
if (error)
if (error) {
showSnackbar({
body: `${t('Error')}: ${t(error)}`,
type: 'error'
})
if (shout?.id) navigate(`/edit/${shout.id}`)
return
}
if (shout?.id) {
saveDraftToLocalStorage({
shoutId: shout.id,
selectedTopics: shout.topics,
slug: shout.slug,
title: '',
body: ''
})
navigate(`/edit/${shout.id}`)
}
}
}
return (