소스 검색

convert save json to download

AykutSarac 3 년 전
부모
커밋
4d50410e32
1개의 변경된 파일6개의 추가작업 그리고 2개의 파일을 삭제
  1. 6 2
      src/components/Sidebar/index.tsx

+ 6 - 2
src/components/Sidebar/index.tsx

@@ -140,8 +140,12 @@ export const Sidebar: React.FC = () => {
   const [clearVisible, setClearVisible] = React.useState(false);
 
   const handleSave = () => {
-    localStorage.setItem("json", json);
-    toast.success("Saved JSON successfully!");
+    const a = document.createElement("a");
+    const file = new Blob([json], { type: "text/plain" });
+
+    a.href = window.URL.createObjectURL(file);
+    a.download = "jsonvisio.json";
+    a.click();
   };
 
   const toggleExpandCollapse = () => {