From 300db9a687a9ecbad50c30e099af6dd6540bf55f Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Sat, 30 Jul 2022 14:17:16 +0300 Subject: [PATCH] add loby page --- src/MancalaApp.tsx | 14 +++++++-- src/routes/LobyPage.tsx | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/routes/LobyPage.tsx diff --git a/src/MancalaApp.tsx b/src/MancalaApp.tsx index 80427d0..3d049c8 100644 --- a/src/MancalaApp.tsx +++ b/src/MancalaApp.tsx @@ -13,13 +13,18 @@ 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'; const context = initContext(); const MancalaApp: FunctionComponent = () => { + const [userKey, setUserKey] = useState(undefined); const [connectionState, setConnetionState] = useState("connecting"); + const [theme, setTheme] = useState(context.themeManager.theme); + const onConnectionDone = () => { setConnetionState("connected"); }; @@ -48,6 +53,9 @@ const MancalaApp: FunctionComponent = () => { }; React.useEffect(() => { connectToServer("connecting"); + context.themeManager.onThemeChange = (theme: Theme) => { + setTheme(theme); + } return () => { // todo: dispose rtmt.dispose //context.rtmt.dispose(); @@ -74,10 +82,12 @@ const MancalaApp: FunctionComponent = () => { <> - } /> + } /> - } > + } > + + }> diff --git a/src/routes/LobyPage.tsx b/src/routes/LobyPage.tsx new file mode 100644 index 0000000..386f13e --- /dev/null +++ b/src/routes/LobyPage.tsx @@ -0,0 +1,68 @@ +import { CommonMancalaGame, MancalaGame } from 'mancala.js'; +import * as React from 'react'; +import { FunctionComponent, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import Center from '../components/Center'; +import CircularPanel from '../components/CircularPanel'; +import HeaderBar from '../components/headerbar/HeaderBar'; +import HeaderbarIcon from '../components/headerbar/HeaderbarIcon'; +import HeaderbarTitle from '../components/headerbar/HeaderbarTitle'; +import ThemeSwitchMenu from '../components/headerbar/ThemeSwitchMenu'; +import PageContainer from '../components/PageContainer'; +import Row from '../components/Row'; +import { channel_on_game_start } from '../const/channel_names'; +import { Context } from '../context/context'; +import { Theme } from '../theme/Theme'; +import { getColorByBrightness } from '../util/ColorUtil'; + +const LobyPage: FunctionComponent<{ + context: Context, + userKey?: string, + theme: Theme +}> = ({ context, userKey, theme }) => { + + let navigate = useNavigate(); + + useEffect(() => { + listenMessages(); + context.rtmt.sendMessage("new_game", {}); + }, []); + + const listenMessages = () => { + context.rtmt.listenMessage(channel_on_game_start, (message: Object) => { + const newGame: CommonMancalaGame = message as CommonMancalaGame; + navigate(`/game/${newGame.id}`) + }); + } + + const textColorOnAppBar = getColorByBrightness( + context.themeManager.theme.appBarBgColor, + context.themeManager.theme.textColor, + context.themeManager.theme.textLightColor + ); + const textColorOnBoard = getColorByBrightness( + context.themeManager.theme.boardColor, + context.themeManager.theme.textColor, + context.themeManager.theme.textLightColor + ); + return ( + + + + + + + + + + +
+ +

{`${context.texts.SearchingOpponent} ${context.texts.PleaseWait}...`}

+
+
+
+ ); +} + +export default LobyPage; \ No newline at end of file