pgnviewer lazy load and suspense

This commit is contained in:
2026-06-03 10:02:53 +02:00
parent 6a9a51c1ed
commit 9ecbce5a15
2 changed files with 61 additions and 49 deletions
+3 -6
View File
@@ -3,12 +3,9 @@ FEN string
Env Vars Env Vars
API base URL API base URL
- favicon and page titles - favicon and page titles - SEO related things
- rearrange buttons / header space - collapse on smaller screens - rearrange buttons / header space - collapse on smaller screens
- Loading Chessboard with suspense and spinner - Loading Chessboard with suspense and spinner
- toasts
- Lichess login - Lichess login
- logger
- logger - contact form
+58 -43
View File
@@ -1,10 +1,23 @@
import { lazy, Suspense } from "react";
import CustomHeaders from "#/components/CustomHeaders.tsx"; import CustomHeaders from "#/components/CustomHeaders.tsx";
import HeaderFields from "#/components/HeaderFields.tsx"; import HeaderFields from "#/components/HeaderFields.tsx";
import LichessButton from "#/components/LichessButton.tsx"; import LichessButton from "#/components/LichessButton.tsx";
import PgnViewer from "#/components/PgnViewer.tsx";
import Section from "#/components/Section.tsx"; import Section from "#/components/Section.tsx";
import { useChessGame } from "#/hooks/useChessGame.ts"; import { useChessGame } from "#/hooks/useChessGame.ts";
const PgnViewer = lazy(() => import("#/components/PgnViewer.tsx"));
const LoadingBoard = () => {
return (
<div className="relative grid h-125 w-160 items-center text-center">
<p>Loading...</p>
<div id="loading-bar-spinner" className="spinner">
<div className="spinner-icon"></div>
</div>
</div>
);
};
const Chessboard = () => { const Chessboard = () => {
const { const {
gameState, gameState,
@@ -35,51 +48,53 @@ const Chessboard = () => {
</Section> </Section>
<div className="grid grid-cols-2 gap-4"> <div className="grid grid-cols-2 gap-4">
<div> <Suspense fallback={<LoadingBoard />}>
<PgnViewer <div>
gamePgn={gameState.pgn || ""} <PgnViewer
handlePlyChange={handlePlyChange} gamePgn={gameState.pgn || ""}
/> handlePlyChange={handlePlyChange}
<div className="grid grid-cols-3 gap-2 max-w-150 mt-2"> />
<button <div className="grid grid-cols-3 gap-2 max-w-150 mt-2">
className="btn btn-primary" <button
type="button" className="btn btn-primary"
onClick={handleClearGame} type="button"
> onClick={handleClearGame}
Clear Game
</button>
<div className="flex gap-2 items-center">
<label
htmlFor="diagram-add"
className="text-sm text-(--base-content)"
> >
Select Diagram Clear Game
</label> </button>
<input <div className="flex gap-2 items-center">
id="diagram-toggle" <label
name="diagram-toggle" htmlFor="diagram-add"
type="checkbox" className="text-sm text-(--base-content)"
className="checkbox-accent" >
checked={gameState.diagrams.some( Select Diagram
(d) => d.ply === currentPosition.ply, </label>
)} <input
onChange={handleToggleDiagram} id="diagram-toggle"
/> name="diagram-toggle"
</div> type="checkbox"
className="checkbox-accent"
checked={gameState.diagrams.some(
(d) => d.ply === currentPosition.ply,
)}
onChange={handleToggleDiagram}
/>
</div>
<label className="toggle text-sm text-(--base-content)"> <label className="toggle text-sm text-(--base-content)">
Render move times Render move times
<input <input
id="render-times" id="render-times"
name="render-times" name="render-times"
type="checkbox" type="checkbox"
checked={gameState.diagramClock} checked={gameState.diagramClock}
onChange={handleToggleClock} onChange={handleToggleClock}
/> />
<span className="slider round" /> <span className="slider round" />
</label> </label>
</div>
</div> </div>
</div> </Suspense>
<div className="flex flex-col gap-4 items-center"> <div className="flex flex-col gap-4 items-center">
<div className="flex justify-center gap-4"> <div className="flex justify-center gap-4">