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 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 (
<div className="text-white">
<MenuBar
@ -21,6 +34,11 @@ const App: React.FC = () => {
setExportText(JSON.stringify(retakesConfig))
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)} />

View File

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