From 9fcb3e8e712bef8fe57b438ec489be8664443a9a Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Wed, 13 Jul 2022 22:39:01 +0300 Subject: [PATCH 01/11] refactor: add HeaderBar --- src/Home.tsx | 188 +++++-------------------------- src/components/FloatingPanel.tsx | 27 +++++ src/components/HeaderBar.tsx | 125 ++++++++++++++++++++ src/components/PageContainer.tsx | 20 ++++ 4 files changed, 203 insertions(+), 157 deletions(-) create mode 100644 src/components/FloatingPanel.tsx create mode 100644 src/components/HeaderBar.tsx create mode 100644 src/components/PageContainer.tsx diff --git a/src/Home.tsx b/src/Home.tsx index c1e5f48..a43af49 100644 --- a/src/Home.tsx +++ b/src/Home.tsx @@ -11,18 +11,17 @@ import { channel_on_game_update, channel_on_game_user_leave, } from "./channel_names"; -import Button from "./components/Button"; import InfoPanel from "./components/InfoPanel"; import { CommonMancalaGame, MancalaGame, Pit } from "mancala.js"; import { GameMove } from "./models/GameMove"; import PitAnimator from "./animation/PitAnimator"; import BoardViewModel from "./viewmodel/BoardViewModel"; import { v4 } from "uuid"; -import { Menu, MenuButton, MenuItem } from "@szhsin/react-menu"; -import "@szhsin/react-menu/dist/index.css"; -import "@szhsin/react-menu/dist/transitions/slide.css"; import { getColorByBrightness } from "./util/ColorUtil"; import { Theme } from "./theme/Theme"; +import HeaderBar from "./components/HeaderBar"; +import FloatingPanel from "./components/FloatingPanel"; +import PageContainer from "./components/PageContainer"; type ConnectionState = "connecting" | "error" | "connected" | "reconnecting"; @@ -113,6 +112,17 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { setBoardViewModel(boardViewModel); }; + const resetGameState = () => { + setGame(undefined); + setCrashMessage(undefined); + setUserKeyWhoLeave(undefined); + }; + + const getBoardIndex = (index: number) => { + if (userKey === game.player2Id) return index + game.board.pits.length / 2; + return index; + }; + React.useEffect(() => { setTheme(context.themeManager.theme); const pitAnimator = new PitAnimator(context, updateBoardViewModel); @@ -131,27 +141,16 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { }; }, [boardViewModel]); - const resetGameState = () => { - setGame(undefined); - setCrashMessage(undefined); - setUserKeyWhoLeave(undefined); - }; - - const newGameClick = () => { + const onNewGameClick = () => { resetGameState(); setSearchingOpponent(true); context.rtmt.sendMessage("new_game", {}); }; - const leaveGame = () => { + const onLeaveGameClick = () => { context.rtmt.sendMessage(channel_leave_game, {}); }; - const getBoardIndex = (index: number) => { - if (userKey === game.player2Id) return index + game.board.pits.length / 2; - return index; - }; - const onHoleSelect = (index: number, pit: Pit) => { //TODO : stoneCount comes from view model! if (pit.stoneCount === 0) { @@ -178,149 +177,24 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { return map[connectionState]; }; - const renderNewGameButton = () => { - const newGame = ( -