From af796b465c66a61b498facff010b372a52a24508 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 18 Apr 2021 14:28:53 +0200 Subject: wip dialog box --- components/gameSettings.tsx | 363 +++++++++++++++++++++----------------------- 1 file changed, 173 insertions(+), 190 deletions(-) (limited to 'components/gameSettings.tsx') diff --git a/components/gameSettings.tsx b/components/gameSettings.tsx index f562e5d..3c3a699 100644 --- a/components/gameSettings.tsx +++ b/components/gameSettings.tsx @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Component, CSSProperties, ReactNode } from 'react'; +import { Component, CSSProperties, ReactNode, useEffect, useState } from 'react'; import { ruleset, userPreferences } from '../api/api'; import { DialogBox } from './dialogBox'; @@ -7,106 +7,93 @@ import { Button, CheckBox, Input, Vierkant } from './ui'; import BuildOutlinedIcon from '@material-ui/icons/BuildOutlined'; -type CurrentGameSettingsStateType = { - editGameRulesDialogVisible: boolean; - ruleset: ruleset; -}; - -export class CurrentGameSettings extends Component { - state: CurrentGameSettingsStateType = { - editGameRulesDialogVisible: false, - ruleset: { - timelimit: { - enabled: false, - shared: false, - }, - ranked: false, +export function CurrentGameSettings() { + var [editGameRulesDialogVisible, setEditGameRulesDialogVisible] = useState(false); + var [ruleset, setRuleset] = useState({ + timelimit: { + enabled: false, + shared: false, + minutes: 0, + seconds: 0, + addmove: 0, }, - }; - - constructor(props: {}) { - super(props); + ranked: false, + }); - if (typeof window === 'undefined') return; // return if run on server - - axios.request({ + useEffect(() => { + axios.request<{ preferences: userPreferences; }>({ method: 'get', url: `/api/user/preferences`, headers: { 'content-type': 'application/json' }, }) - // FIXME: this assumes the request ruleset has all properties of a ruleset - .then(request => this.setState({ ruleset: request.data.ruleset || this.state.ruleset })) + .then(request => setRuleset(request.data.preferences.ruleset)) .catch(() => {}); - } + }, []); - showEditGameRules = () => this.setState({ editGameRulesDialogVisible: true }); - hideEditGameRules = () => this.setState({ editGameRulesDialogVisible: false }); - setGameRules = (newRules: ruleset) => this.setState({ ruleset: newRules }); + /* showEditGameRules = () => this.setState({ editGameRulesDialogVisible: true }); */ + /* hideEditGameRules = () => this.setState({ editGameRulesDialogVisible: false }); */ + /* setGameRules = (newRules: ruleset) => this.setState({ ruleset: newRules }); */ - render() { - var timelimit_str = this.state.ruleset.timelimit.enabled - ? `${this.state.ruleset.timelimit.minutes}m${this.state.ruleset.timelimit.seconds}s plus ${this.state.ruleset.timelimit.addmove}` - : 'Geen tijdslimiet'; - var ranked_str = this.state.ruleset.ranked - ? 'Gerangschikt' - : 'Niet gerangschikt'; - return
+

-

- {timelimit_str} -
- {ranked_str} -

- - -
; - } + Spelregels aanpassen + + + setEditGameRulesDialogVisible(false)} + setGameRules={setRuleset} + ruleset={ruleset} + visible={editGameRulesDialogVisible} + /> + ; } function GameSettingsSection(props: { @@ -168,120 +155,116 @@ function GameRule(props: { } type editGameSettingsProps = { - parentState: CurrentGameSettingsStateType; + visible: boolean; + ruleset: ruleset; hideEditGameRules: () => void; setGameRules: (newRules: ruleset) => void; }; -export class EditGameSettings extends Component { - render() { - return ; } -- cgit v1.2.3 From 763d21dc09ea1ae5bf7bda03763386039de396a9 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 18 Apr 2021 19:34:00 +0200 Subject: edit game rules working (still some inline css) --- components/dialogBox.tsx | 19 ++++------ components/gameSettings.tsx | 85 ++++++++------------------------------------- pages/_app.tsx | 1 + styles/gameSettings.css | 59 +++++++++++++++++++++++++++++++ styles/ui.css | 10 ++++++ 5 files changed, 92 insertions(+), 82 deletions(-) create mode 100644 styles/gameSettings.css (limited to 'components/gameSettings.tsx') diff --git a/components/dialogBox.tsx b/components/dialogBox.tsx index 0a61762..4ead7c5 100644 --- a/components/dialogBox.tsx +++ b/components/dialogBox.tsx @@ -9,20 +9,15 @@ export function DialogBox(props: { title: string; onclick?: () => void; hidden?: boolean; + className?: string; }) { - return -

{props.title}

+ return +

{props.title}

- + {props.children}
; diff --git a/components/gameSettings.tsx b/components/gameSettings.tsx index 3c3a699..bb01284 100644 --- a/components/gameSettings.tsx +++ b/components/gameSettings.tsx @@ -30,60 +30,24 @@ export function CurrentGameSettings() { .catch(() => {}); }, []); - /* showEditGameRules = () => this.setState({ editGameRulesDialogVisible: true }); */ - /* hideEditGameRules = () => this.setState({ editGameRulesDialogVisible: false }); */ - /* setGameRules = (newRules: ruleset) => this.setState({ ruleset: newRules }); */ - var timelimit_str = ruleset.timelimit.enabled ? `${ruleset.timelimit.minutes}m${ruleset.timelimit.seconds}s plus ${ruleset.timelimit.addmove}` : 'Geen tijdslimiet'; var ranked_str = ruleset.ranked ? 'Gerangschikt' : 'Niet gerangschikt'; - return
-

+ return

+

{timelimit_str}
{ranked_str}

@@ -105,13 +69,7 @@ function GameSettingsSection(props: { }) { return