diff --git a/src/components/App.tsx b/src/components/App.tsx index ce095fa..6d8de3c 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useEffect, useState } from "react" import copy from "copy-to-clipboard" import RetakesConfig from "../types/RetakesConfig" import AllDecks from "./AllDecks" @@ -10,6 +10,19 @@ const App: React.FC = () => { const [showExport,setShowExport] = useState(false) const [exportText,setExportText] = useState("") + useEffect(()=>{ + // Load saved config + const retakesJSON = window.localStorage.getItem("retakesJSON") + if (retakesJSON){ + try{ + const parsedConfig: RetakesConfig = JSON.parse(retakesJSON) + setRetakesConfig(parsedConfig) + }catch(err){ + window.localStorage.removeItem("retakesJSON") + } + } + },[]) + return (
{ setExportText(JSON.stringify(retakesConfig)) setShowExport(true) }} + onSave={()=>{ + const jsonString = JSON.stringify(retakesConfig) + window.localStorage.setItem("retakesJSON",jsonString) + // TODO: user feedback that config was saved + }} /> setRetakesConfig(newConfig)} /> diff --git a/src/components/MenuBar.tsx b/src/components/MenuBar.tsx index e961767..ec4b9ca 100644 --- a/src/components/MenuBar.tsx +++ b/src/components/MenuBar.tsx @@ -3,9 +3,10 @@ import React from "react" interface Props { onExport?: ()=>void onExportJson?: ()=>void + onSave?:()=>void } -const MenuBar: React.FC = ({onExport,onExportJson}) => { +const MenuBar: React.FC = ({onExport,onExportJson,onSave}) => { return (
@@ -13,6 +14,9 @@ const MenuBar: React.FC = ({onExport,onExportJson}) => {
Export to JSON +
+
+ Save