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/dialogBox.tsx | 16 +- components/gameSettings.tsx | 363 +++++++++++++++++++++----------------------- 2 files changed, 176 insertions(+), 203 deletions(-) (limited to 'components') diff --git a/components/dialogBox.tsx b/components/dialogBox.tsx index 7abbded..0a61762 100644 --- a/components/dialogBox.tsx +++ b/components/dialogBox.tsx @@ -1,4 +1,4 @@ -import { CSSProperties, ReactNode } from 'react'; +import { ReactNode } from 'react'; import { Vierkant } from './ui'; @@ -7,20 +7,10 @@ import CancelIcon from '@material-ui/icons/Cancel'; export function DialogBox(props: { children: ReactNode; title: string; - style?: CSSProperties; onclick?: () => void; + hidden?: boolean; }) { - return + return

{props.title}

({ + 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