浏览代码

fix failed fetch toast loading

AykutSarac 3 年之前
父节点
当前提交
9a6bcd3718
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      src/containers/ImportModal/index.tsx

+ 3 - 3
src/containers/ImportModal/index.tsx

@@ -65,7 +65,7 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
     if (url) {
       setJsonFile(null);
 
-      const toastId = toast.loading("Loading...");
+      toast.loading("Loading...", { id: "toastFetch" });
       return fetch(url)
         .then((res) => res.json())
         .then((json) => {
@@ -74,10 +74,10 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
             payload: JSON.stringify(json),
           });
 
-          toast.dismiss(toastId);
           setVisible(false);
         })
-        .catch(() => toast.error("Failed to fetch JSON!"));
+        .catch(() => toast.error("Failed to fetch JSON!"))
+        .finally(() => toast.dismiss("toastFetch"));
     }
 
     if (jsonFile) {