mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-05 23:27:55 +02:00
4502fd443e
Our IndexDB handling did not have very good error handling. It wasn't reporting the actual errors that occured, nor was it using actual Error objects. In some cases it also had overly convoluted Promise use, and it didn't need to be .tsx either. The biggest issue was that if any problem occured during the main load(), this would end up as an unhandled rejection and so it would only be logged to the console. This extends the previous catch to also cover this, so that the recovery screen is activated.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import React, { useState } from "react";
|
|
import { deleteGame } from "../../db";
|
|
import { ConfirmationModal } from "./ConfirmationModal";
|
|
import Button from "@mui/material/Button";
|
|
import { Tooltip } from "@mui/material";
|
|
|
|
import DeleteIcon from "@mui/icons-material/Delete";
|
|
import { pushDisableRestore } from "../../Electron";
|
|
|
|
interface IProps {
|
|
color?: "primary" | "warning" | "error";
|
|
}
|
|
|
|
export function DeleteGameButton({ color = "primary" }: IProps): React.ReactElement {
|
|
const [modalOpened, setModalOpened] = useState(false);
|
|
|
|
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: %o", r));
|
|
}}
|
|
open={modalOpened}
|
|
onClose={() => setModalOpened(false)}
|
|
confirmationText={"Really delete your game? (It's permanent!)"}
|
|
additionalButton={<Button onClick={() => setModalOpened(false)}>Cancel</Button>}
|
|
/>
|
|
</>
|
|
);
|
|
}
|