aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-04 09:42:54 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-04 09:42:54 +0100
commit3f13d9e35ba55ddb7cda064aedf94bf3f9b14102 (patch)
tree123d20cf61c27e6f4b567885dc1cab6b73c50ddc /components
parentaba3566129bed29fb3385a80f8e255e378b6e9d8 (diff)
fetch unexisting endpoint for userPreferences
Diffstat (limited to 'components')
-rw-r--r--components/gameSettings.tsx29
1 files changed, 18 insertions, 11 deletions
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 });