implemented save

This commit is contained in:
Djeeberjr 2021-11-16 01:13:59 +01:00
parent 7cc9fd7722
commit 9e7b456400
2 changed files with 24 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import React, { useState } from "react" import React, { useEffect, useState } from "react"
import copy from "copy-to-clipboard" import copy from "copy-to-clipboard"
import RetakesConfig from "../types/RetakesConfig" import RetakesConfig from "../types/RetakesConfig"
import AllDecks from "./AllDecks" import AllDecks from "./AllDecks"
@ -10,6 +10,19 @@ const App: React.FC = () => {
const [showExport,setShowExport] = useState(false) const [showExport,setShowExport] = useState(false)
const [exportText,setExportText] = useState("") 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 ( return (
<div className="text-white"> <div className="text-white">
<MenuBar <MenuBar
@ -21,6 +34,11 @@ const App: React.FC = () => {
setExportText(JSON.stringify(retakesConfig)) setExportText(JSON.stringify(retakesConfig))
setShowExport(true) setShowExport(true)
}} }}
onSave={()=>{
const jsonString = JSON.stringify(retakesConfig)
window.localStorage.setItem("retakesJSON",jsonString)
// TODO: user feedback that config was saved
}}
/> />
<AllDecks retakesConfig={retakesConfig} onChange={(newConfig)=>setRetakesConfig(newConfig)} /> <AllDecks retakesConfig={retakesConfig} onChange={(newConfig)=>setRetakesConfig(newConfig)} />

View File

@ -3,9 +3,10 @@ import React from "react"
interface Props { interface Props {
onExport?: ()=>void onExport?: ()=>void
onExportJson?: ()=>void onExportJson?: ()=>void
onSave?:()=>void
} }
const MenuBar: React.FC<Props> = ({onExport,onExportJson}) => { const MenuBar: React.FC<Props> = ({onExport,onExportJson,onSave}) => {
return ( return (
<div className="bg-gray-800 h-10 m-1 p-1 flex"> <div className="bg-gray-800 h-10 m-1 p-1 flex">
<div className="bg-gray-700 button" onClick={onExport}> <div className="bg-gray-700 button" onClick={onExport}>
@ -13,6 +14,9 @@ const MenuBar: React.FC<Props> = ({onExport,onExportJson}) => {
</div> </div>
<div className="bg-gray-700 button" onClick={onExportJson}> <div className="bg-gray-700 button" onClick={onExportJson}>
Export to JSON Export to JSON
</div>
<div className="bg-gray-700 button" onClick={onSave}>
Save
</div> </div>
<a href="https://developer.valvesoftware.com/wiki/CS:GO_Game_Mode_-_Retakes" target="_blank" rel='noreferrer'> <a href="https://developer.valvesoftware.com/wiki/CS:GO_Game_Mode_-_Retakes" target="_blank" rel='noreferrer'>
<div className="bg-gray-700 button"> <div className="bg-gray-700 button">