From c08d4240e10d6b416210303222d5c08e4109ded5 Mon Sep 17 00:00:00 2001 From: sam365724 Date: Fri, 30 Sep 2022 22:26:32 +0200 Subject: [PATCH] Avoid browser warning about leaving page, handle delete image fail. --- src/shared/components/common/markdown-textarea.tsx | 1 + src/shared/utils.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index e369f8f..1bb52a3 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -369,6 +369,7 @@ export class MarkdownTextArea extends Component< pictrsDeleteToast( i18n.t("click_to_delete_picture"), i18n.t("picture_deleted"), + i18n.t("fail_picture_deleted").concat('\n(', file.name,')'), deleteUrl ); } else { diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 19b48c1..8fa399e 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -543,6 +543,7 @@ export function toast(text: string, background = "success") { export function pictrsDeleteToast( clickToDeleteText: string, deletePictureText: string, + failedDeletePictureText: string, deleteUrl: string ) { if (isBrowser()) { @@ -555,9 +556,16 @@ export function pictrsDeleteToast( duration: 10000, onClick: () => { if (toast) { - window.location.replace(deleteUrl); - alert(deletePictureText); - toast.hideToast(); + fetch(deleteUrl, {}) + .then( res => { + console.log(res) + toast.hideToast(); + if (res.ok === true){ + alert(deletePictureText); + } else{ + alert(failedDeletePictureText); + } + }) } }, close: true, -- 2.44.1