/** * @fileOverview */ import * as React from 'react' import { useSelector } from 'react-redux' import { GameIdContext } from '../../app' import { useAppDispatch } from '../../hooks' import { GameProgressState, loadProgress, selectProgress } from '../../state/progress' import { downloadFile } from '../world_tree' import { Button } from '../button' /** Pop-up that is displaying the Game Info. * * `handleClose` is the function to close it again because it's open/closed state is * controlled by the containing element. */ export function UploadPopup ({handleClose}) { const [file, setFile] = React.useState(); const gameId = React.useContext(GameIdContext) const gameProgress = useSelector(selectProgress(gameId)) const dispatch = useAppDispatch() const handleFileChange = (e) => { if (e.target.files) { setFile(e.target.files[0]) } } /** Upload progress from a */ const uploadProgress = (e) => { if (!file) {return} const fileReader = new FileReader() fileReader.readAsText(file, "UTF-8") fileReader.onload = (e) => { const data = JSON.parse(e.target.result.toString()) as GameProgressState console.debug("Json Data", data) dispatch(loadProgress({game: gameId, data: data})) } handleClose() } /** Download the current progress (i.e. what's saved in the browser store) */ const downloadProgress = (e) => { e.preventDefault() downloadFile({ data: JSON.stringify(gameProgress, null, 2), fileName: `lean4game-${gameId}-${new Date().toLocaleDateString()}.json`, fileType: 'text/json', }) } return

Upload Saved Progress

Select a JSON file with the saved game progress to load your progress.

Warning: This will delete your current game progress! Consider downloading your current progress first!

}