From: sam365724 Date: Fri, 30 Sep 2022 20:26:32 +0000 (+0200) Subject: Avoid browser warning about leaving page, handle delete image fail and add user filen... X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%7B?a=commitdiff_plain;h=f2a4ebd92accc05d5a5c0ebebe6da9ce0b90c8d8;p=lemmy-ui.git Avoid browser warning about leaving page, handle delete image fail and add user filenames to messages. --- diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index e369f8f..b453acc 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -367,8 +367,9 @@ export class MarkdownTextArea extends Component< let textarea: any = document.getElementById(i.id); autosize.update(textarea); pictrsDeleteToast( - i18n.t("click_to_delete_picture"), - i18n.t("picture_deleted"), + i18n.t("click_to_delete_picture").concat('\n(', file.name,')'), + i18n.t("picture_deleted").concat('\n(', file.name,')'), + 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,