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
+16 -3
View File
@@ -5,6 +5,7 @@ import {
useRef,
useState,
} from "react";
import { toast } from "react-toastify";
import type { IPosition } from "#/interfaces.ts";
import { gameReducer, initialGameState } from "#/reducers/gameReducer.ts";
import { downloadPDF } from "#/utils/pdfUtils.ts";
@@ -54,17 +55,29 @@ export const useChessGame = () => {
if (response.ok) {
downloadPDF(await response.blob());
// TODO toast
// TODO add metrics logger - add success to analytics
toast.success("PDF successfully generated!", {
toastId: "pdf-success",
});
} else {
const body = await response.json();
// TODO toast and remove console but pass to logger
const body = await response.json();
console.error("Error saving PDF:", body.error);
toast.error("An error has occurred. Please try again later.", {
toastId: "pdf-error",
});
}
} catch (error: unknown) {
// TODO add metrics / logger
console.error("Error saving PDF:", 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 {
setGeneratingPdf(false);
+2
View File
@@ -2,6 +2,7 @@ import { TanStackDevtools } from "@tanstack/react-devtools";
import { createRootRoute, HeadContent, Scripts } from "@tanstack/react-router";
import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools";
import { type ReactNode, Suspense } from "react";
import { ToastContainer } from "react-toastify";
import { MatomoAnalytics } from "#/components/MatomoAnalytics.tsx";
import Footer from "../components/Footer";
import Header from "../components/Header";
@@ -40,6 +41,7 @@ function RootDocument({ children }: { children: ReactNode }) {
<body className="font-sans antialiased">
<Header />
{children}
<ToastContainer position="bottom-right" />
<Footer />
<TanStackDevtools
config={{