From 3f13d9e35ba55ddb7cda064aedf94bf3f9b14102 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 4 Feb 2021 09:42:54 +0100 Subject: fetch unexisting endpoint for userPreferences --- components/gameSettings.tsx | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'components') diff --git a/components/gameSettings.tsx b/components/gameSettings.tsx index 8bffeee..8f15aa1 100644 --- a/components/gameSettings.tsx +++ b/components/gameSettings.tsx @@ -1,20 +1,12 @@ import { ReactNode, Component } from 'react'; +import axios from 'axios'; import { Button, Vierkant, CheckBox, Input } from './ui'; import { DialogBox } from './dialogBox'; +import { ruleset, userPreferences } from '../api/api'; import BuildRoundedIcon from '@material-ui/icons/BuildRounded'; -type ruleset = { - timelimit: { - enabled: boolean; - minutes?: number; - seconds?: number; - addmove?: number; - shared: boolean; - }, - ranked: boolean; -}; type CurrentGameSettingsStateType = { editGameRulesDialogVisible: boolean; @@ -24,7 +16,7 @@ type CurrentGameSettingsStateType = { export class CurrentGameSettings extends Component { state: CurrentGameSettingsStateType = { editGameRulesDialogVisible: false, - ruleset: { // default ruleset (should be replaced in this.constructor()) + ruleset: { timelimit: { enabled: false, shared: false @@ -33,6 +25,21 @@ export class CurrentGameSettings extends Component { } } + constructor(props: {}) { + super(props); + + if (typeof window === "undefined") return; // return if run on server + + axios.request({ + 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 })) + .catch(() => {}); + } + showEditGameRules = () => this.setState({ editGameRulesDialogVisible: true }); hideEditGameRules = () => this.setState({ editGameRulesDialogVisible: false }); setGameRules = (newRules: ruleset) => this.setState({ ruleset: newRules }); -- cgit v1.2.3