diff --git a/package.json b/package.json index 7241b81..b3b4f81 100644 --- a/package.json +++ b/package.json @@ -13,17 +13,19 @@ "author": "", "license": "ISC", "dependencies": { - "@szhsin/react-menu": "^3.0.2", + "@szhsin/react-menu": "^3.1.2", "@types/": "szhsin/react-menu", "@types/eventemitter2": "^4.1.0", "@types/styled-jsx": "^3.4.4", "@types/uuid": "^8.3.4", "eventemitter2": "^6.4.7", "mancala.js": "^0.0.2-beta.3", + "notyf": "^3.10.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "6", "styled-jsx": "^5.0.2", + "sweetalert": "^2.1.2", "uuid": "^8.3.2" }, "devDependencies": { diff --git a/src/MancalaApp.tsx b/src/MancalaApp.tsx index ba62f58..b35675d 100644 --- a/src/MancalaApp.tsx +++ b/src/MancalaApp.tsx @@ -12,9 +12,11 @@ import Home from './routes/Home'; import { initContext } from './context/context'; import { RTMTWS } from './rtmt/rtmt_websocket'; import { getColorByBrightness } from './util/ColorUtil'; -import { ConnectionState } from './models/ConnectionState'; import { Theme } from './theme/Theme'; import LobyPage from './routes/LobyPage'; +import swal from 'sweetalert'; +import { ConnectionState } from './rtmt/rtmt'; + const context = initContext(); const MancalaApp: FunctionComponent = () => { @@ -40,9 +42,15 @@ const MancalaApp: FunctionComponent = () => { setTheme(theme) } const connectToServer = async () => { - const userKey = await context.userKeyStore.getUserKey(); - setUserKey(userKey); - (context.rtmt as RTMTWS).initWebSocket(userKey); + try { + const userKey = await context.userKeyStore.getUserKey(); + setUserKey(userKey); + (context.rtmt as RTMTWS).initWebSocket(userKey); + } catch (error) { + //TODO: check if it is network error! + swal(context.texts.Error + "!", context.texts.ErrorWhenRetrievingInformation, "error"); + console.error(error); + } }; React.useEffect(() => { @@ -74,7 +82,6 @@ const MancalaApp: FunctionComponent = () => { context.themeManager.theme.textColor, context.themeManager.theme.textLightColor ); - if (!userKey) return <>; return ( <> @@ -82,7 +89,7 @@ const MancalaApp: FunctionComponent = () => { } /> - } > + } > }> @@ -90,7 +97,7 @@ const MancalaApp: FunctionComponent = () => { - {connectionStateText()} + {connectionStateText()} ); diff --git a/src/animation/PitAnimator.ts b/src/animation/PitAnimator.ts index 4db6dc3..ffcdf84 100644 --- a/src/animation/PitAnimator.ts +++ b/src/animation/PitAnimator.ts @@ -13,6 +13,7 @@ import { Context } from "../context/context"; import BoardViewModelFactory from "../factory/BoardViewModelFactory"; import { PitViewModelFactory } from "../factory/PitViewModelFactory"; import { Game } from "../models/Game"; +import { Theme } from "../theme/Theme"; import { getColorByBrightness } from "../util/ColorUtil"; import BoardViewModel from "../viewmodel/BoardViewModel"; @@ -35,6 +36,7 @@ export default class PitAnimator { ) { this.context = context; this.onBoardViewModelUpdate = onBoardViewModelUpdate; + this.context.themeManager.on("themechange", this.onThemeChange.bind(this)); } get mancalaGame(): MancalaGame | undefined { @@ -190,6 +192,11 @@ export default class PitAnimator { }); } + private onThemeChange(theme: Theme){ + if(!this.game) return; + this.onBoardViewModelUpdate?.(this.getBoardViewModelFromGame(this.game)); + } + public resetAnimationState() { this.animationIndex = -1; this.currentHistoryItem = undefined; @@ -204,6 +211,7 @@ export default class PitAnimator { } public dispose() { + this.context.themeManager.off("themechange", this.onThemeChange.bind(this)); this.resetAnimationState(); this.clearCurrentInterval(); } diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 6c09a2c..620e3e1 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -18,7 +18,7 @@ const Button: FunctionComponent<{