]> Untitled Git - lemmy-ui.git/commitdiff
Avoid browser warning about leaving page, handle delete image fail.
authorsam365724 <samsnight@gmail.com>
Fri, 30 Sep 2022 20:26:32 +0000 (22:26 +0200)
committersam365724 <samsnight@gmail.com>
Fri, 30 Sep 2022 20:26:32 +0000 (22:26 +0200)
src/shared/components/common/markdown-textarea.tsx
src/shared/utils.ts

index e369f8fbb41ba842917bcb12dd5b12855cc4e735..1bb52a36de9939e711ba41e744236eb7dd935c7b 100644 (file)
@@ -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 {
index 19b48c1945700410520f2e15e1fc9e21eb2833df..8fa399eb30859402c0601543d60d611c8964f63f 100644 (file)
@@ -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,