diff options
-rw-r--r-- | api/api.ts | 16 | ||||
-rw-r--r-- | components/gameSettings.tsx | 29 |
2 files changed, 34 insertions, 11 deletions
@@ -7,3 +7,19 @@ export interface userInfo { username?: string, }; +export type ruleset = { + timelimit: { + enabled: boolean; + minutes?: number; + seconds?: number; + addmove?: number; + shared: boolean; + }, + ranked: boolean; +}; + +export interface userPreferences { + darkMode?: boolean; + ruleset?: ruleset; +} + 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<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 })) + .catch(() => {}); + } + showEditGameRules = () => this.setState({ editGameRulesDialogVisible: true }); hideEditGameRules = () => this.setState({ editGameRulesDialogVisible: false }); setGameRules = (newRules: ruleset) => this.setState({ ruleset: newRules }); |