@@ -16,6 +16,8 @@ import { useRouter } from 'next/router'
1616import type { Key } from 'chessground/types'
1717import type { DrawShape } from 'chessground/draw'
1818import { Chess , PieceSymbol } from 'chess.ts'
19+ import { AnimatePresence } from 'framer-motion'
20+ import toast from 'react-hot-toast'
1921import {
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