Skip to content

Commit f7f7a1e

Browse files
feat: add download model modal blocker to train page
1 parent be75bee commit f7f7a1e

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/components/Analysis/DownloadModelModal.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ export const DownloadModelModal: React.FC<Props> = ({
7676
/>
7777
</div>
7878
) : null}
79+
<Link
80+
href="/"
81+
className="order-2 flex h-8 cursor-pointer select-none items-center gap-1 self-end rounded bg-background-2 px-3 text-sm transition duration-200 hover:bg-background-3 md:order-3 md:h-10 md:px-4 md:text-base"
82+
>
83+
<p>Return Home</p>
84+
</Link>
7985
<div
8086
tabIndex={0}
8187
role="button"

src/pages/train.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { useRouter } from 'next/router'
1616
import type { Key } from 'chessground/types'
1717
import type { DrawShape } from 'chessground/draw'
1818
import { Chess, PieceSymbol } from 'chess.ts'
19+
import { AnimatePresence } from 'framer-motion'
20+
import toast from 'react-hot-toast'
1921
import {
2022
getTrainingGame,
2123
logPuzzleGuesses,
@@ -32,6 +34,7 @@ import {
3234
AuthenticatedWrapper,
3335
GameBoard,
3436
PromotionOverlay,
37+
DownloadModelModal,
3538
Highlight,
3639
MoveMap,
3740
BlunderMeter,
@@ -255,6 +258,7 @@ const Train: React.FC<Props> = ({
255258
const [hoverArrow, setHoverArrow] = useState<DrawShape | null>(null)
256259
const [arrows, setArrows] = useState<DrawShape[]>([])
257260
const analysisSyncedRef = useRef(false)
261+
const toastId = useRef<string | null>(null)
258262
const [promotionFromTo, setPromotionFromTo] = useState<
259263
[string, string] | null
260264
>(null)
@@ -286,6 +290,27 @@ const Train: React.FC<Props> = ({
286290
}
287291
}, [showAnalysis, analysisController, controller.currentNode])
288292

293+
// Toast notifications for Maia model status
294+
useEffect(() => {
295+
return () => {
296+
toast.dismiss()
297+
}
298+
}, [])
299+
300+
useEffect(() => {
301+
if (analysisController.maiaStatus === 'loading' && !toastId.current) {
302+
toastId.current = toast.loading('Loading Maia Model...')
303+
} else if (analysisController.maiaStatus === 'ready') {
304+
if (toastId.current) {
305+
toast.success('Loaded Maia! Analysis is ready', {
306+
id: toastId.current,
307+
})
308+
} else {
309+
toast.success('Loaded Maia! Analysis is ready')
310+
}
311+
}
312+
}, [analysisController.maiaStatus])
313+
289314
const onSelectSquare = useCallback(
290315
(square: Key) => {
291316
if (!showAnalysis) {
@@ -1045,6 +1070,15 @@ const Train: React.FC<Props> = ({
10451070
content="Collection of chess training and analysis tools centered around Maia."
10461071
/>
10471072
</Head>
1073+
<AnimatePresence>
1074+
{analysisController.maiaStatus === 'no-cache' ||
1075+
analysisController.maiaStatus === 'downloading' ? (
1076+
<DownloadModelModal
1077+
progress={analysisController.maiaProgress}
1078+
download={analysisController.downloadMaia}
1079+
/>
1080+
) : null}
1081+
</AnimatePresence>
10481082
<TrainingControllerContext.Provider value={controller}>
10491083
{trainingGame && (isMobile ? mobileLayout : desktopLayout)}
10501084
</TrainingControllerContext.Provider>

0 commit comments

Comments
 (0)