cleanup app_bar.tsx

This commit is contained in:
joneugster
2023-10-23 21:07:33 +02:00
parent e740027144
commit 787d010b6c
6 changed files with 226 additions and 406 deletions
+11 -12
View File
@@ -9,6 +9,15 @@ import { deleteProgress, selectProgress } from '../../state/progress'
import { downloadFile } from '../world_tree'
import { Button } from '../button'
/** download the current progress (i.e. what's saved in the browser store) */
export function downloadProgress(gameId: string, gameProgress: any, ev: React.MouseEvent) {
ev.preventDefault()
downloadFile({
data: JSON.stringify(gameProgress, null, 2),
fileName: `lean4game-${gameId}-${new Date().toLocaleDateString()}.json`,
fileType: 'text/json',
})
}
/** Pop-up to delete game progress.
*
@@ -20,23 +29,13 @@ export function ErasePopup ({handleClose}) {
const gameProgress = useSelector(selectProgress(gameId))
const dispatch = useAppDispatch()
/** 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',
})
}
const eraseProgress = () => {
dispatch(deleteProgress({game: gameId}))
handleClose()
}
const downloadAndErase = (e) => {
downloadProgress(e)
const downloadAndErase = (ev) => {
downloadProgress(gameId, gameProgress, ev)
eraseProgress()
}