pdf generation toasts

This commit is contained in:
2026-06-02 21:22:57 +02:00
parent 1c8f1674b7
commit a5bb7dafd9
4 changed files with 34 additions and 3 deletions
+1
View File
@@ -30,6 +30,7 @@
"react": "^19.2.0", "react": "^19.2.0",
"react-dom": "^19.2.0", "react-dom": "^19.2.0",
"react-icons": "^5.6.0", "react-icons": "^5.6.0",
"react-toastify": "^11.1.0",
"tailwindcss": "^4.1.18", "tailwindcss": "^4.1.18",
"zod": "^4.4.3" "zod": "^4.4.3"
}, },
+15
View File
@@ -53,6 +53,9 @@ importers:
react-icons: react-icons:
specifier: ^5.6.0 specifier: ^5.6.0
version: 5.6.0(react@19.2.6) version: 5.6.0(react@19.2.6)
react-toastify:
specifier: ^11.1.0
version: 11.1.0(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
tailwindcss: tailwindcss:
specifier: ^4.1.18 specifier: ^4.1.18
version: 4.3.0 version: 4.3.0
@@ -1858,6 +1861,12 @@ packages:
react-is@17.0.2: react-is@17.0.2:
resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==}
react-toastify@11.1.0:
resolution: {integrity: sha512-e9h23x3phN0wbFeB6yovmWp7lobzV4CaCH0LO8nVP6H7Y+3GbcLpIzMm9dJhcp1RXbpyfvjgpfXqO80QAmn7sg==}
peerDependencies:
react: ^18 || ^19
react-dom: ^18 || ^19
react@19.2.6: react@19.2.6:
resolution: {integrity: sha512-sfWGGfavi0xr8Pg0sVsyHMAOziVYKgPLNrS7ig+ivMNb3wbCBw3KxtflsGBAwD3gYQlE/AEZsTLgToRrSCjb0Q==} resolution: {integrity: sha512-sfWGGfavi0xr8Pg0sVsyHMAOziVYKgPLNrS7ig+ivMNb3wbCBw3KxtflsGBAwD3gYQlE/AEZsTLgToRrSCjb0Q==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@@ -3839,6 +3848,12 @@ snapshots:
react-is@17.0.2: {} react-is@17.0.2: {}
react-toastify@11.1.0(react-dom@19.2.6(react@19.2.6))(react@19.2.6):
dependencies:
clsx: 2.1.1
react: 19.2.6
react-dom: 19.2.6(react@19.2.6)
react@19.2.6: {} react@19.2.6: {}
readdirp@5.0.0: {} readdirp@5.0.0: {}
+16 -3
View File
@@ -5,6 +5,7 @@ import {
useRef, useRef,
useState, useState,
} from "react"; } from "react";
import { toast } from "react-toastify";
import type { IPosition } from "#/interfaces.ts"; import type { IPosition } from "#/interfaces.ts";
import { gameReducer, initialGameState } from "#/reducers/gameReducer.ts"; import { gameReducer, initialGameState } from "#/reducers/gameReducer.ts";
import { downloadPDF } from "#/utils/pdfUtils.ts"; import { downloadPDF } from "#/utils/pdfUtils.ts";
@@ -54,17 +55,29 @@ export const useChessGame = () => {
if (response.ok) { if (response.ok) {
downloadPDF(await response.blob()); downloadPDF(await response.blob());
// TODO toast
// TODO add metrics logger - add success to analytics
toast.success("PDF successfully generated!", {
toastId: "pdf-success",
});
} else { } else {
const body = await response.json();
// TODO toast and remove console but pass to logger // TODO toast and remove console but pass to logger
const body = await response.json();
console.error("Error saving PDF:", body.error); console.error("Error saving PDF:", body.error);
toast.error("An error has occurred. Please try again later.", {
toastId: "pdf-error",
});
} }
} catch (error: unknown) { } catch (error: unknown) {
// TODO add metrics / logger
console.error("Error saving PDF:", error); console.error("Error saving PDF:", error);
if (error instanceof Error) { if (error instanceof Error) {
// do something here such as toast toast.error("An error has occurred. Please try again later.", {
toastId: "pdf-error",
});
} }
} finally { } finally {
setGeneratingPdf(false); setGeneratingPdf(false);
+2
View File
@@ -2,6 +2,7 @@ import { TanStackDevtools } from "@tanstack/react-devtools";
import { createRootRoute, HeadContent, Scripts } from "@tanstack/react-router"; import { createRootRoute, HeadContent, Scripts } from "@tanstack/react-router";
import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools"; import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools";
import { type ReactNode, Suspense } from "react"; import { type ReactNode, Suspense } from "react";
import { ToastContainer } from "react-toastify";
import { MatomoAnalytics } from "#/components/MatomoAnalytics.tsx"; import { MatomoAnalytics } from "#/components/MatomoAnalytics.tsx";
import Footer from "../components/Footer"; import Footer from "../components/Footer";
import Header from "../components/Header"; import Header from "../components/Header";
@@ -40,6 +41,7 @@ function RootDocument({ children }: { children: ReactNode }) {
<body className="font-sans antialiased"> <body className="font-sans antialiased">
<Header /> <Header />
{children} {children}
<ToastContainer position="bottom-right" />
<Footer /> <Footer />
<TanStackDevtools <TanStackDevtools
config={{ config={{