mirror of
https://github.com/TheRealOwenRees/chess-scribe-website.git
synced 2026-07-23 01:46:57 +00:00
remove try/catch in downloadString
This commit is contained in:
@@ -6,12 +6,9 @@ API base URL
|
|||||||
- favicon and page titles
|
- favicon and page titles
|
||||||
- rearrange buttons / header space - collapse on smaller screens
|
- rearrange buttons / header space - collapse on smaller screens
|
||||||
|
|
||||||
- add / edit headers
|
|
||||||
- custom headers - title etc
|
|
||||||
- Loading Chessboard with suspense and spinner
|
- Loading Chessboard with suspense and spinner
|
||||||
- toasts
|
- toasts
|
||||||
|
|
||||||
- Lichess login
|
- Lichess login
|
||||||
- stringUtils - downloadString - move it out of try / catch and let program use the try/catch
|
|
||||||
|
|
||||||
- logger
|
- logger
|
||||||
@@ -29,8 +29,17 @@ export const useChessGame = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSavePgn = () => {
|
const handleSavePgn = () => {
|
||||||
const pgnString = buildPgnString(gameState);
|
try {
|
||||||
downloadString(pgnString, "game.pgn");
|
const pgnString = buildPgnString(gameState);
|
||||||
|
downloadString(pgnString, "game.pgn");
|
||||||
|
} catch (error) {
|
||||||
|
// TODO logger
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
toast.error("An error occurred while saving the PGN. Please try again.", {
|
||||||
|
toastId: "pgn-download-error",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSavePdf = async () => {
|
const handleSavePdf = async () => {
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
export const downloadString = (string: string, filename: string) => {
|
export const downloadString = (string: string, filename: string) => {
|
||||||
try {
|
const element = document.createElement("a");
|
||||||
const element = document.createElement("a");
|
const file = new Blob([string], { type: "text/plain" });
|
||||||
const file = new Blob([string], { type: "text/plain" });
|
|
||||||
|
|
||||||
element.href = URL.createObjectURL(file);
|
element.href = URL.createObjectURL(file);
|
||||||
element.download = filename;
|
element.download = filename;
|
||||||
document.body.appendChild(element);
|
document.body.appendChild(element);
|
||||||
element.click();
|
element.click();
|
||||||
} catch (error) {
|
|
||||||
throw new Error("Failed to download file");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user