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

index e369f8fbb41ba842917bcb12dd5b12855cc4e735..b453acc3ce2383f6d635545b19a16d5d3e9d5927 100644 (file)
@@ -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 {
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,