2022-04-07 01:30:08 +02:00
|
|
|
import React, { useState } from "react";
|
2022-01-10 17:29:58 +01:00
|
|
|
import { deleteGame } from "../../db";
|
|
|
|
import { ConfirmationModal } from "./ConfirmationModal";
|
|
|
|
import Button from "@mui/material/Button";
|
2022-04-07 01:30:08 +02:00
|
|
|
import { Tooltip } from "@mui/material";
|
2022-01-10 17:29:58 +01:00
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
import DeleteIcon from "@mui/icons-material/Delete";
|
|
|
|
import { pushDisableRestore } from "../../Electron";
|
2022-01-10 17:29:58 +01:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
color?: "primary" | "warning" | "error";
|
|
|
|
}
|
|
|
|
|
|
|
|
export function DeleteGameButton({ color = "primary" }: IProps): React.ReactElement {
|
|
|
|
const [modalOpened, setModalOpened] = useState(false);
|
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Tooltip title="This will permanently delete your local save game. Did you export it before?">
|
|
|
|
<Button startIcon={<DeleteIcon />} color={color} onClick={() => setModalOpened(true)}>
|
|
|
|
Delete Save
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
<ConfirmationModal
|
|
|
|
onConfirm={() => {
|
|
|
|
setModalOpened(false);
|
|
|
|
deleteGame()
|
|
|
|
.then(() => {
|
|
|
|
pushDisableRestore();
|
|
|
|
setTimeout(() => location.reload(), 1000);
|
|
|
|
})
|
|
|
|
.catch((r) => console.error(`Could not delete game: ${r}`));
|
|
|
|
}}
|
|
|
|
open={modalOpened}
|
|
|
|
onClose={() => setModalOpened(false)}
|
|
|
|
confirmationText={"Really delete your game? (It's permanent!)"}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
2022-01-10 17:29:58 +01:00
|
|
|
}
|