diff --git a/src/components/Views/EditView/EditView.tsx b/src/components/Views/EditView/EditView.tsx index 751f8182..26d78db7 100644 --- a/src/components/Views/EditView/EditView.tsx +++ b/src/components/Views/EditView/EditView.tsx @@ -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([]) - const [draft, setDraft] = createSignal() + const [draft, setDraft] = createSignal(props.shout) const [mediaItems, setMediaItems] = createSignal([]) const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token)) diff --git a/src/routes/edit/new.tsx b/src/routes/edit/new.tsx index 5ae69fdb..7646d0c5 100644 --- a/src/routes/edit/new.tsx +++ b/src/routes/edit/new.tsx @@ -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 (