From ef523056ece6becd9423196b2a7d6bf45aca937e Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Thu, 14 Jul 2022 13:23:15 +0300 Subject: [PATCH] fix warnings --- src/Home.tsx | 26 +++++------ src/components/HeaderBar.tsx | 15 ++++-- src/components/InfoPanel.tsx | 22 ++++----- src/components/board/BoardView.tsx | 74 ++++++++---------------------- src/components/board/StoneView.tsx | 2 +- src/util/Util.ts | 2 +- 6 files changed, 56 insertions(+), 85 deletions(-) diff --git a/src/Home.tsx b/src/Home.tsx index 2148a47..d05ecb4 100644 --- a/src/Home.tsx +++ b/src/Home.tsx @@ -26,24 +26,24 @@ import PageContainer from "./components/PageContainer"; type ConnectionState = "connecting" | "error" | "connected" | "reconnecting"; const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { - const [userKey, setUserKey] = useState(undefined); + const [userKey, setUserKey] = useState(undefined); const [connectionState, setConnetionState] = useState("connecting"); const [searchingOpponent, setSearchingOpponent] = useState(false); - const [game, setGame] = useState(undefined); + const [game, setGame] = useState(undefined); - const [crashMessage, setCrashMessage] = useState(undefined); + const [crashMessage, setCrashMessage] = useState(undefined); - const [userKeyWhoLeave, setUserKeyWhoLeave] = useState(undefined); + const [userKeyWhoLeave, setUserKeyWhoLeave] = useState(undefined); - const [boardViewModel, setBoardViewModel] = useState(null); + const [boardViewModel, setBoardViewModel] = useState(undefined); - const [boardId, setBoardId] = useState(); + const [boardId, setBoardId] = useState("-1"); - const [pitAnimator, setPitAnimator] = useState(); + const [pitAnimator, setPitAnimator] = useState(undefined); const [theme, setTheme] = useState(undefined); @@ -119,6 +119,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { }; const getBoardIndex = (index: number) => { + if(!game) return -1; if (userKey === game.player2Id) return index + game.board.pits.length / 2; return index; }; @@ -137,7 +138,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { React.useEffect(() => { context.themeManager.onThemeChange = (theme) => { setTheme(theme); - pitAnimator && updateBoardViewModel(pitAnimator.getBoardViewModelFromGame(game)); + pitAnimator && game && updateBoardViewModel(pitAnimator.getBoardViewModelFromGame(game)); }; }, [boardViewModel]); @@ -152,6 +153,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { }; const onPitSelect = (index: number, pit: Pit) => { + if(!boardViewModel) return; //TODO : stoneCount comes from view model! if (pit.stoneCount === 0) { //TODO : warn user @@ -201,17 +203,15 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { crashMessage={crashMessage} userKey={userKey} userKeyWhoLeave={userKeyWhoLeave} - searchingOpponent={searchingOpponent} - /> - {game && boardViewModel && ( + searchingOpponent={searchingOpponent} /> + {game && boardViewModel && userKey && ( + onPitSelect={onPitSelect} /> )} ); diff --git a/src/components/HeaderBar.tsx b/src/components/HeaderBar.tsx index 253c51e..78d8c98 100644 --- a/src/components/HeaderBar.tsx +++ b/src/components/HeaderBar.tsx @@ -8,7 +8,12 @@ import Button from "./Button"; import "@szhsin/react-menu/dist/index.css"; import "@szhsin/react-menu/dist/transitions/slide.css"; -function renderNewGameButton(context: Context, game: MancalaGame, onNewGameClick: () => void, userKeyWhoLeave: string, crashMessage: string): JSX.Element { +function renderNewGameButton( + context: Context, game: + MancalaGame | undefined, + onNewGameClick: () => void, + userKeyWhoLeave: string | undefined, + crashMessage: string | undefined): JSX.Element { const newGame = (