From ac24424a27a4fec421a2bc08493c826bdad21283 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 17:18:58 +0300 Subject: [PATCH 1/7] add React Functional Component snippet --- .vscode/.snippet.code-snippets | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.vscode/.snippet.code-snippets b/.vscode/.snippet.code-snippets index f4961fc..a072b93 100644 --- a/.vscode/.snippet.code-snippets +++ b/.vscode/.snippet.code-snippets @@ -15,5 +15,27 @@ "`}" ], "description": "Log output to console" + }, + "React Functional Component": { + "scope": "typescriptreact", + "prefix": "rfc", + "body": [ + "import * as React from 'react';", + "import { FunctionComponent } from 'react';", + "", + "const $TM_FILENAME_BASE: FunctionComponent = () => {", + "\treturn (", + "\t\t
", + "\t\t\t$0", + "\t\t\t", + "\t\t
", + "\t);", + "}", + "", + "export default $TM_FILENAME_BASE;" + ], + "description": "Log output to console" } } \ No newline at end of file From a8e98995d99f5b1395d06775a6462fd477d5773b Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 17:44:55 +0300 Subject: [PATCH 2/7] add HeaderbarIcon --- src/components/headerbar/HeaderbarIcon.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/components/headerbar/HeaderbarIcon.tsx diff --git a/src/components/headerbar/HeaderbarIcon.tsx b/src/components/headerbar/HeaderbarIcon.tsx new file mode 100644 index 0000000..b012df0 --- /dev/null +++ b/src/components/headerbar/HeaderbarIcon.tsx @@ -0,0 +1,22 @@ +import * as React from "react"; +import { FunctionComponent } from "react"; +//@ts-ignore +import MancalaIcon from "jsx:../../mancala.svg"; + +const HeaderbarIcon: FunctionComponent = () => { + return ( +
+ + +
+ ); +} + +export default HeaderbarIcon; \ No newline at end of file From c38d8c60d5cff7531b58b33e996c88991ec41232 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 17:45:03 +0300 Subject: [PATCH 3/7] add Row --- src/components/Row.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/components/Row.tsx diff --git a/src/components/Row.tsx b/src/components/Row.tsx new file mode 100644 index 0000000..bc0db42 --- /dev/null +++ b/src/components/Row.tsx @@ -0,0 +1,20 @@ +import * as React from 'react'; +import { FunctionComponent } from 'react'; + +const Row: FunctionComponent = ({children}) => { + return ( +
+ {children} + +
+ ); +} + +export default Row; \ No newline at end of file From 32419a6ad4fefb9a6e20b3f3d8c4cb352e882ca6 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 17:45:21 +0300 Subject: [PATCH 4/7] add HeaderbarTitle --- src/components/headerbar/HeaderbarTitle.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/components/headerbar/HeaderbarTitle.tsx diff --git a/src/components/headerbar/HeaderbarTitle.tsx b/src/components/headerbar/HeaderbarTitle.tsx new file mode 100644 index 0000000..2da3039 --- /dev/null +++ b/src/components/headerbar/HeaderbarTitle.tsx @@ -0,0 +1,18 @@ +import * as React from 'react'; +import { FunctionComponent } from 'react'; +import { Context } from '../../context/context'; + +const HeaderbarTitle: FunctionComponent<{ title: string, color: string }> = ({ title, color }) => { + return ( +

+ {title} + +

+ ); +} + +export default HeaderbarTitle; \ No newline at end of file From 1e092d94568f82cb4f30d6a13e06cc05b8f64612 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 17:45:35 +0300 Subject: [PATCH 5/7] add ThemeSwitchMenu --- src/components/headerbar/ThemeSwitchMenu.tsx | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/components/headerbar/ThemeSwitchMenu.tsx diff --git a/src/components/headerbar/ThemeSwitchMenu.tsx b/src/components/headerbar/ThemeSwitchMenu.tsx new file mode 100644 index 0000000..8740671 --- /dev/null +++ b/src/components/headerbar/ThemeSwitchMenu.tsx @@ -0,0 +1,57 @@ +import { Menu, MenuItem } from "@szhsin/react-menu"; +import * as React from "react"; +import { FunctionComponent } from "react"; +import { Context } from "../../context/context"; + +const ThemeSwitchMenu: FunctionComponent<{ context: Context, textColor: string }> = (props) => { + const { context, textColor } = props; + const menuButton = + light_mode + ; + const menuItems = context.themeManager.themes.map((theme, index) => { + const themeBackground = context.themeManager.theme.background; + return ( + (event.target.style.background = themeBackground)} + //@ts-ignore + onMouseOut={(event) => (event.target.style.background = "transparent")} + onClick={() => (context.themeManager.theme = theme)}> +
+ {theme.name} + + + ); + }) + return ( +
+ + {menuItems} + + +
+ ); +} + +export default ThemeSwitchMenu; \ No newline at end of file From b59dbdc5c904a6507003b6836e2517d42e4a2f33 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 17:45:48 +0300 Subject: [PATCH 6/7] refactor HeaderBar --- src/components/HeaderBar.tsx | 97 ++++-------------------------------- 1 file changed, 11 insertions(+), 86 deletions(-) diff --git a/src/components/HeaderBar.tsx b/src/components/HeaderBar.tsx index 68c34c2..d1bdc24 100644 --- a/src/components/HeaderBar.tsx +++ b/src/components/HeaderBar.tsx @@ -7,8 +7,10 @@ import { getColorByBrightness } from "../util/ColorUtil"; import Button from "./Button"; import "@szhsin/react-menu/dist/index.css"; import "@szhsin/react-menu/dist/transitions/slide.css"; -//@ts-ignore -import MancalaIcon from "jsx:../mancala.svg"; +import HeaderbarIcon from "./headerbar/HeaderbarIcon"; +import HeaderbarTitle from "./headerbar/HeaderbarTitle"; +import Row from "./Row"; +import ThemeSwitchMenu from "./headerbar/ThemeSwitchMenu"; function renderNewGameButton( context: Context, @@ -54,15 +56,11 @@ const HeaderBar: FunctionComponent<{ ); return (
-
-
- -
-

- {context.texts.Mancala} -

-
-
+ + + + + {renderNewGameButton(context, game, onNewGameClick, userKeyWhoLeave, crashMessage)} {game && @@ -75,7 +73,7 @@ const HeaderBar: FunctionComponent<{ text={context.texts.Leave} onClick={onLeaveGameClick} /> )} -
+ + `}
) } 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) => { - const themeBackground = context.themeManager.theme.background; - return ( - (event.target.style.background = themeBackground)} - //@ts-ignore - onMouseOut={(event) => (event.target.style.background = "transparent")} - onClick={() => (context.themeManager.theme = theme)}> -
- {theme.name} - - - ); - }) - return ( -
- - {menuItems} - - -
- ); -} - From 8e71a30a4f51dfb261a5e36b717a3fd3423addcd Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 15 Jul 2022 18:11:09 +0300 Subject: [PATCH 7/7] refactor Headerbar --- src/components/HeaderBar.tsx | 77 +------------------- src/components/headerbar/ThemeSwitchMenu.tsx | 2 + src/routes/Home.tsx | 33 +++++++-- 3 files changed, 31 insertions(+), 81 deletions(-) diff --git a/src/components/HeaderBar.tsx b/src/components/HeaderBar.tsx index d1bdc24..826c4c2 100644 --- a/src/components/HeaderBar.tsx +++ b/src/components/HeaderBar.tsx @@ -1,79 +1,10 @@ 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/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"; -import HeaderbarIcon from "./headerbar/HeaderbarIcon"; -import HeaderbarTitle from "./headerbar/HeaderbarTitle"; -import Row from "./Row"; -import ThemeSwitchMenu from "./headerbar/ThemeSwitchMenu"; +import { FunctionComponent } from "react";; -function renderNewGameButton( - context: Context, - game: MancalaGame | undefined, - onNewGameClick: () => void, - userKeyWhoLeave: string | undefined, - crashMessage: string | undefined): JSX.Element { - const newGame = ( -