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 = (
-
- );
- if (userKeyWhoLeave) {
- return newGame;
- }
- if (crashMessage) {
- return newGame;
- }
- if (!game) {
- return newGame;
- } else if (game.state == "ended") {
- return newGame;
- }
- return <>>;
- };
- const menuTextColor = getColorByBrightness(
- context.themeManager.theme.appBarBgColor,
+ const textColorOnBoard = getColorByBrightness(
+ context.themeManager.theme.boardColor,
context.themeManager.theme.textColor,
context.themeManager.theme.textLightColor
);
+
return (
-
- {showConnectionState && (
-
- {connectionStateText()}
-
- )}
-
-
- {context.texts.Mancala}
-
-
-
-
-
- {renderNewGameButton()}
- {game &&
- !userKeyWhoLeave &&
- !crashMessage &&
- (game?.state === "playing" || game?.state === "initial") && (
-
- )}
-
-
+
+
+ {connectionStateText()}
+
+
= ({ initial = 0 }) => {
onHoleSelect={onHoleSelect}
/>
)}
-
+
);
};
diff --git a/src/components/FloatingPanel.tsx b/src/components/FloatingPanel.tsx
new file mode 100644
index 0000000..979a129
--- /dev/null
+++ b/src/components/FloatingPanel.tsx
@@ -0,0 +1,27 @@
+import * as React from "react";
+import { FunctionComponent } from "react";
+import { Context } from "../context";
+
+const FloatingPanel: FunctionComponent<{
+ context: Context;
+ color: string;
+ visible: boolean;
+}> = (props) => {
+ if(!props.visible) return <>>
+ return (
+
+ {props.children}
+
+ )
+};
+
+export default FloatingPanel;
\ No newline at end of file
diff --git a/src/components/HeaderBar.tsx b/src/components/HeaderBar.tsx
new file mode 100644
index 0000000..058d8f5
--- /dev/null
+++ b/src/components/HeaderBar.tsx
@@ -0,0 +1,125 @@
+import * as React from "react";
+import { FunctionComponent } from "react";
+import { Menu, MenuItem } from "@szhsin/react-menu";
+import { MancalaGame } from "mancala.js";
+import { Context } from "../context";
+import { getColorByBrightness } from "../util/ColorUtil";
+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 {
+ const newGame = (
+
+ );
+ if (userKeyWhoLeave) {
+ return newGame;
+ }
+ if (crashMessage) {
+ return newGame;
+ }
+ if (!game) {
+ return newGame;
+ } else if (game.state == "ended") {
+ return newGame;
+ }
+ return <>>;
+};
+
+const HeaderBar: FunctionComponent<{
+ context: Context,
+ game: MancalaGame,
+ userKeyWhoLeave: string,
+ crashMessage: string,
+ onNewGameClick: () => void,
+ onLeaveGameClick: () => void
+}> = (props) => {
+ const { context, game, userKeyWhoLeave, crashMessage, onNewGameClick, onLeaveGameClick } = props;
+ const textColor = getColorByBrightness(
+ context.themeManager.theme.appBarBgColor,
+ context.themeManager.theme.textColor,
+ context.themeManager.theme.textLightColor
+ );
+ return (
+
+
+ {context.texts.Mancala}
+
+
+
+
+
+ {renderNewGameButton(context, game, onNewGameClick, userKeyWhoLeave, crashMessage)}
+ {game &&
+ !userKeyWhoLeave &&
+ !crashMessage &&
+ (game?.state === "playing" || game?.state === "initial") && (
+
+ )}
+
+
)
+}
+export default HeaderBar;
+
+const ThemeSwitchMenu: FunctionComponent<{ context: Context, textColor: string }> = (props) => {
+ const { context, textColor } = props;
+ const menuButton =
+ light_mode
+ ;
+ const menuItems = context.themeManager.themes.map((theme, index) => {
+ return ();
+ })
+ return ();
+}
+
diff --git a/src/components/PageContainer.tsx b/src/components/PageContainer.tsx
new file mode 100644
index 0000000..4bdac52
--- /dev/null
+++ b/src/components/PageContainer.tsx
@@ -0,0 +1,20 @@
+import * as React from "react";
+import { FunctionComponent } from "react";
+import { Theme } from "../theme/Theme";
+
+const PageContainer: FunctionComponent<{theme: Theme}> = (props) => {
+ return (
+
+ {props.children}
+
+ );
+}
+
+export default PageContainer;
\ No newline at end of file