catch-response-on-update

This commit is contained in:
Untone 2024-02-17 18:03:01 +03:00
parent 3a6faa65a8
commit 0dd2736dd5
3 changed files with 30 additions and 13 deletions

View File

@ -70,10 +70,10 @@ export const PublishSettings = (props: Props) => {
return {
coverImageUrl: props.form?.coverImageUrl,
mainTopic: props.form?.mainTopic || EMPTY_TOPIC,
slug: props.form?.slug,
title: props.form?.title,
subtitle: props.form?.subtitle,
description: composeDescription(),
slug: props.form?.slug || '',
title: props.form?.title || '',
subtitle: props.form?.subtitle || '',
description: composeDescription() || '',
selectedTopics: [],
}
})

View File

@ -161,7 +161,11 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
}
try {
const shout = await updateShout(formToSave, { publish: false })
const { shout, error } = await updateShout(formToSave, { publish: false })
if (error) {
snackbar?.showSnackbar({ type: 'error', body: localize?.t(error) || '' })
return
}
removeDraftFromLocalStorage(formToSave.shoutId)
if (shout?.published_at) {
@ -176,24 +180,33 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
}
const saveDraft = async (draftForm: ShoutForm) => {
await updateShout(draftForm, { publish: false })
const { error } = await updateShout(draftForm, { publish: false })
if (error) {
snackbar?.showSnackbar({ type: 'error', body: localize?.t(error) || '' })
return
}
}
const publishShout = async (formToPublish: ShoutForm) => {
if (isEditorPanelVisible()) {
const editorPanelVisible = isEditorPanelVisible()
const pageRoute = page()?.route
if (editorPanelVisible) {
toggleEditorPanel()
}
if (page()?.route === 'edit') {
if (pageRoute === 'edit') {
if (!validate()) {
return
}
await updateShout(formToPublish, { publish: false })
const slug = slugify(form.title)
setForm('slug', slug)
openPage(router, 'editSettings', { shoutId: form.shoutId.toString() })
const { error } = await updateShout(formToPublish, { publish: false })
if (error) {
snackbar?.showSnackbar({ type: 'error', body: localize?.t(error) || '' })
}
return
}
@ -202,7 +215,11 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
}
try {
await updateShout(formToPublish, { publish: true })
const { error } = await updateShout(formToPublish, { publish: true })
if (error) {
snackbar?.showSnackbar({ type: 'error', body: localize?.t(error) || '' })
return
}
openPage(router, 'feed')
} catch (error) {
console.error('[publishShout]', error)

View File

@ -157,12 +157,12 @@ export const apiClient = {
shout_id: number
shout_input?: ShoutInput
publish: boolean
}): Promise<Shout> => {
}): Promise<CommonResult> => {
const response = await apiClient.private
.mutation(updateArticle, { shout_id, shout_input, publish })
.toPromise()
console.debug('[graphql.client.core] updateArticle:', response.data)
return response.data.update_shout.shout
return response.data.update_shout
},
deleteShout: async (params: MutationDelete_ShoutArgs): Promise<void> => {
const response = await apiClient.private.mutation(deleteShout, params).toPromise()