Skip to content

Commit

Permalink
feat: added toasts and indicator for ONNX model loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjosethomas committed Feb 5, 2025
1 parent 3ab6f28 commit 774b6fa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"react": "18.3.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "18.3.1",
"react-hot-toast": "^2.5.1",
"react-markdown": "^9.0.3",
"react-tooltip": "^5.28.0",
"recharts": "^2.15.0",
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useMaiaEngine/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Maia {
try {
const buffer = await this.getCachedModel(this.modelUrl, this.type)
await this.initializeModel(buffer)
this.options.setStatus('ready')
} catch (e) {
this.options.setStatus('no-cache')
}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Head from 'next/head'
import { Toaster } from 'react-hot-toast'
import Script from 'next/script'
import { useRouter } from 'next/router'
import type { AppProps } from 'next/app'
Expand Down Expand Up @@ -51,6 +52,7 @@ function MaiaPlatform({ Component, pageProps }: AppProps) {
</div>
<Footer />
</div>
<Toaster position="bottom-right" />
<Analytics />
<Script async src="/analytics.js?id=G-SNP84LXLKY" />
<Script id="analytics">
Expand Down
17 changes: 17 additions & 0 deletions src/pages/analysis/[...id].tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import toast from 'react-hot-toast'
import React, {
useMemo,
Dispatch,
Expand All @@ -6,6 +7,7 @@ import React, {
useContext,
useCallback,
SetStateAction,
useRef,
} from 'react'
import Head from 'next/head'
import type { NextPage } from 'next'
Expand Down Expand Up @@ -261,11 +263,26 @@ const Analysis: React.FC<Props> = ({
const [arrows, setArrows] = useState<DrawShape[]>([])
const [brushes, setBrushes] = useState<DrawBrushes>({} as DrawBrushes)
const [screen, setScreen] = useState(screens[0])
const toastId = useRef<string>(null)

useEffect(() => {
setHoverArrow(null)
}, [controller.currentIndex])

useEffect(() => {
if (maiaStatus === 'loading' && !toastId.current) {
toastId.current = toast.loading('Loading Maia Model...')
} else if (maiaStatus === 'ready') {
if (toastId.current) {
toast.success('Loaded Maia! Analysis is ready', {
id: toastId.current,
})
} else {
toast.success('Loaded Maia! Analysis is ready')
}
}
}, [maiaStatus])

const launchContinue = useCallback(() => {
const fen = analyzedGame.moves[controller.currentIndex].board
const url = '/play' + '?fen=' + encodeURIComponent(fen)
Expand Down

0 comments on commit 774b6fa

Please sign in to comment.