From 127dac9d91a07c48d0173c6b6f4f7418347a9687 Mon Sep 17 00:00:00 2001 From: Keeler Russell Date: Sat, 25 Apr 2020 10:59:23 -0700 Subject: [PATCH 01/36] refactor: Extract Checkbox.jsx --- frontend/src/components/Checkbox.jsx | 27 +++++++++++++++++++++++++++ frontend/src/components/README.md | 5 +++++ frontend/src/game/GameSettings.jsx | 2 +- frontend/src/game/StartPanel.jsx | 4 ++-- frontend/src/lobby/CreatePanel.jsx | 2 +- frontend/src/lobby/GameOptions.jsx | 3 ++- frontend/src/utils.jsx | 21 --------------------- 7 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 frontend/src/components/Checkbox.jsx create mode 100644 frontend/src/components/README.md diff --git a/frontend/src/components/Checkbox.jsx b/frontend/src/components/Checkbox.jsx new file mode 100644 index 00000000..25dfa104 --- /dev/null +++ b/frontend/src/components/Checkbox.jsx @@ -0,0 +1,27 @@ +import React from "react"; +import PropTypes from "prop-types"; + +import App from "../app"; + +const Checkbox = ({link, text, side, onChange, ...rest}) => ( +
+ {side === "right" ? text : ""} + + {side === "left" ? text : ""} +
+); + +Checkbox.propTypes = { + link: PropTypes.string, + text: PropTypes.string, + side: PropTypes.string, + onChange: PropTypes.func +}; + +export default Checkbox; diff --git a/frontend/src/components/README.md b/frontend/src/components/README.md new file mode 100644 index 00000000..ca327996 --- /dev/null +++ b/frontend/src/components/README.md @@ -0,0 +1,5 @@ +# Components + +A set of general UI components. + +Many are "connected" tools which use a "link" prop to connect to the app state. diff --git a/frontend/src/game/GameSettings.jsx b/frontend/src/game/GameSettings.jsx index 007fc6de..610a4716 100644 --- a/frontend/src/game/GameSettings.jsx +++ b/frontend/src/game/GameSettings.jsx @@ -1,7 +1,7 @@ import React from "react"; import App from "../app"; -import {Checkbox} from "../utils"; +import Checkbox from "../components/Checkbox"; const GameSettings = () => (
diff --git a/frontend/src/game/StartPanel.jsx b/frontend/src/game/StartPanel.jsx index 79038ae1..5b5c482f 100644 --- a/frontend/src/game/StartPanel.jsx +++ b/frontend/src/game/StartPanel.jsx @@ -1,8 +1,8 @@ import React from "react"; import App from "../app"; -import { Select, Checkbox, toTitleCase } from "../utils"; - +import Checkbox from "../components/Checkbox"; +import { Select, toTitleCase } from "../utils"; const StartPanel = () => { const gameType = toTitleCase(App.state.game.type); diff --git a/frontend/src/lobby/CreatePanel.jsx b/frontend/src/lobby/CreatePanel.jsx index 5c90d89d..e26c1c4f 100644 --- a/frontend/src/lobby/CreatePanel.jsx +++ b/frontend/src/lobby/CreatePanel.jsx @@ -2,7 +2,7 @@ import React from "react"; import _ from "utils/utils"; import App from "../app"; -import {Checkbox} from "../utils"; +import Checkbox from "../components/Checkbox"; import GameTypes from "./GameTypes"; import GameOptions from "./GameOptions"; diff --git a/frontend/src/lobby/GameOptions.jsx b/frontend/src/lobby/GameOptions.jsx index 8e8ed17b..3f93eb91 100644 --- a/frontend/src/lobby/GameOptions.jsx +++ b/frontend/src/lobby/GameOptions.jsx @@ -3,7 +3,8 @@ import PropTypes from "prop-types"; import _ from "utils/utils"; import App from "../app"; -import { Checkbox, Select } from "../utils"; +import Checkbox from "../components/Checkbox" +import { Select } from "../utils"; import Set from "./Set"; import CubeList from "./CubeList"; diff --git a/frontend/src/utils.jsx b/frontend/src/utils.jsx index 6f6d0881..2376dcb4 100644 --- a/frontend/src/utils.jsx +++ b/frontend/src/utils.jsx @@ -8,27 +8,6 @@ import App from "./app"; * through a "link" prop to connect to the app state */ -export const Checkbox = ({link, text, side, onChange, ...rest}) => ( -
- {side === "right" ? text : ""} - - {side === "left" ? text : ""} -
-); - -Checkbox.propTypes = { - link: PropTypes.string, - text: PropTypes.string, - side: PropTypes.string, - onChange: PropTypes.func -}; - export const Spaced = ({elements}) => ( elements .map((x, index) => {x}) From 86cadbf885b9d55aed041b9b9bbcb1a785b3b154 Mon Sep 17 00:00:00 2001 From: Keeler Russell Date: Sat, 25 Apr 2020 11:02:18 -0700 Subject: [PATCH 02/36] refactor: Extract Spaced.jsx --- frontend/src/components/Spaced.jsx | 13 +++++++++++++ frontend/src/game/Cols.jsx | 2 +- frontend/src/game/Grid.jsx | 2 +- frontend/src/lobby/Header.jsx | 2 +- frontend/src/utils.jsx | 10 ---------- 5 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 frontend/src/components/Spaced.jsx diff --git a/frontend/src/components/Spaced.jsx b/frontend/src/components/Spaced.jsx new file mode 100644 index 00000000..e729ae4e --- /dev/null +++ b/frontend/src/components/Spaced.jsx @@ -0,0 +1,13 @@ +import React from "react"; + +const Spaced = ({elements}) => ( + elements + .map((x, index) => {x}) + .reduce((prev, curr) => [ + prev, + , + curr + ]) +); + +export default Spaced; diff --git a/frontend/src/game/Cols.jsx b/frontend/src/game/Cols.jsx index d05ac470..15196b21 100644 --- a/frontend/src/game/Cols.jsx +++ b/frontend/src/game/Cols.jsx @@ -3,7 +3,7 @@ import PropTypes from "prop-types"; import App from "../app"; import {getZoneDisplayName} from "../zones"; -import {Spaced} from "../utils.jsx"; +import Spaced from "../components/Spaced"; import {getCardSrc, getFallbackSrc} from "../cardimage"; class Cols extends Component { diff --git a/frontend/src/game/Grid.jsx b/frontend/src/game/Grid.jsx index cac13620..f689a54b 100644 --- a/frontend/src/game/Grid.jsx +++ b/frontend/src/game/Grid.jsx @@ -4,7 +4,7 @@ import PropTypes from "prop-types"; import _ from "utils/utils"; import App from "../app"; import {getCardSrc, getFallbackSrc} from "../cardimage"; -import {Spaced} from "../utils"; +import Spaced from "../components/Spaced"; import {ZONE_PACK, getZoneDisplayName} from "../zones"; const Grid = ({zones}) => ( diff --git a/frontend/src/lobby/Header.jsx b/frontend/src/lobby/Header.jsx index 47fd8166..c621fd95 100644 --- a/frontend/src/lobby/Header.jsx +++ b/frontend/src/lobby/Header.jsx @@ -1,7 +1,7 @@ import React from "react"; import { STRINGS } from "../config"; -import { Spaced } from "../utils"; +import Spaced from "../components/Spaced"; import App from "../app"; const Header = () => ( diff --git a/frontend/src/utils.jsx b/frontend/src/utils.jsx index 2376dcb4..dd461469 100644 --- a/frontend/src/utils.jsx +++ b/frontend/src/utils.jsx @@ -8,16 +8,6 @@ import App from "./app"; * through a "link" prop to connect to the app state */ -export const Spaced = ({elements}) => ( - elements - .map((x, index) => {x}) - .reduce((prev, curr) => [ - prev, - , - curr - ]) -); - export const Select = ({ link, opts, From 4fc39723dc3bd739a59342d413e4dd5623a76b0d Mon Sep 17 00:00:00 2001 From: Keeler Russell Date: Sat, 25 Apr 2020 11:05:21 -0700 Subject: [PATCH 03/36] refactor: Extract Select.jsx --- frontend/src/components/Select.jsx | 29 +++++++++++++++++++++++++++++ frontend/src/game/DeckSettings.jsx | 2 +- frontend/src/game/StartPanel.jsx | 3 ++- frontend/src/lobby/GameOptions.jsx | 4 ++-- frontend/src/utils.jsx | 23 ----------------------- 5 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 frontend/src/components/Select.jsx diff --git a/frontend/src/components/Select.jsx b/frontend/src/components/Select.jsx new file mode 100644 index 00000000..a98482ec --- /dev/null +++ b/frontend/src/components/Select.jsx @@ -0,0 +1,29 @@ +import React from "react"; +import PropTypes from "prop-types"; + +import App from "../app"; + +const Select = ({ + link, + opts, + onChange = (e) => { App.save(link, e.currentTarget.value); }, + value = App.state[link], + ...rest}) => ( + +); + +Select.propTypes = { + link: PropTypes.string, + onChange: PropTypes.func, + value: PropTypes.any, + opts: PropTypes.array +}; + +export default Select; diff --git a/frontend/src/game/DeckSettings.jsx b/frontend/src/game/DeckSettings.jsx index 191cfe96..d788b550 100644 --- a/frontend/src/game/DeckSettings.jsx +++ b/frontend/src/game/DeckSettings.jsx @@ -4,7 +4,7 @@ import PropTypes from "prop-types"; import App from "../app"; import {getZoneDisplayName, ZONE_MAIN, ZONE_SIDEBOARD} from "../zones"; import {COLORS_TO_LANDS_NAME} from "../gamestate"; -import {Select} from "../utils"; +import Select from "../components/Select"; const DeckSettings = () => ( (App.state.isGameFinished || App.state.didGameStart) diff --git a/frontend/src/game/StartPanel.jsx b/frontend/src/game/StartPanel.jsx index 5b5c482f..83669392 100644 --- a/frontend/src/game/StartPanel.jsx +++ b/frontend/src/game/StartPanel.jsx @@ -2,7 +2,8 @@ import React from "react"; import App from "../app"; import Checkbox from "../components/Checkbox"; -import { Select, toTitleCase } from "../utils"; +import Select from "../components/Select"; +import { toTitleCase } from "../utils"; const StartPanel = () => { const gameType = toTitleCase(App.state.game.type); diff --git a/frontend/src/lobby/GameOptions.jsx b/frontend/src/lobby/GameOptions.jsx index 3f93eb91..bb4709b8 100644 --- a/frontend/src/lobby/GameOptions.jsx +++ b/frontend/src/lobby/GameOptions.jsx @@ -3,8 +3,8 @@ import PropTypes from "prop-types"; import _ from "utils/utils"; import App from "../app"; -import Checkbox from "../components/Checkbox" -import { Select } from "../utils"; +import Checkbox from "../components/Checkbox"; +import Select from "../components/Select"; import Set from "./Set"; import CubeList from "./CubeList"; diff --git a/frontend/src/utils.jsx b/frontend/src/utils.jsx index dd461469..69d71b65 100644 --- a/frontend/src/utils.jsx +++ b/frontend/src/utils.jsx @@ -8,29 +8,6 @@ import App from "./app"; * through a "link" prop to connect to the app state */ -export const Select = ({ - link, - opts, - onChange = (e) => { App.save(link, e.currentTarget.value); }, - value = App.state[link], - ...rest}) => ( - -); - -Select.propTypes = { - link: PropTypes.string, - onChange: PropTypes.func, - value: PropTypes.any, - opts: PropTypes.array -}; - export const Textarea = ({link, ...rest}) => (