X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fstore.js;h=792d2a5b2a7f3eb59ab94cdbab327eba28545ca3;hb=d54f6261c9e30f4eabb402ad301dd5c5e40fb656;hp=705f473c0fec795ca949445e42f540dccb285db5;hpb=f35b9960e1c527fc400ebac85321bd4712459da3;p=vchess.git diff --git a/client/src/store.js b/client/src/store.js index 705f473c..792d2a5b 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -13,14 +13,25 @@ export const store = { }, socketCloseListener: null, initialize() { + const headers = { + "Content-Type": "application/json;charset=UTF-8", + "X-Requested-With": "XMLHttpRequest" + }; fetch( params.serverUrl + "/variants", - {method: "GET"}, + { + method: "GET", + headers: headers + } ) .then(res => res.json()) .then(json => { - this.state.variants = json.variantArray.sort( - (v1,v2) => v1.name.localeCompare(v2.name)); + if (!Array.isArray(json.variantArray)) { + alert("Variants loading failed: reload the page"); + return; + } + this.state.variants = json.variantArray + .sort((v1,v2) => v1.name.localeCompare(v2.name)); }); let mysid = localStorage.getItem("mysid"); // Assign mysid only once (until next time user clear browser data) @@ -34,6 +45,7 @@ export const store = { name: localStorage.getItem("myname") || "", //"" for "anonymous" email: "", //unknown yet notify: false, //email notifications + newsRead: localStorage.getItem("newsRead") || 0, sid: mysid }; // Slow verification through the server: @@ -42,6 +54,7 @@ export const store = { params.serverUrl + "/whoami", { method: "GET", + headers: headers, credentials: params.credentials } ) @@ -65,6 +78,8 @@ export const store = { localStorage.removeItem("myname"); this.state.user.email = json.email; this.state.user.notify = json.notify; + if (!!json.newsRead && json.newsRead > this.state.user.newsRead) + this.state.user.newsRead = json.newsRead; }); // Settings initialized with values from localStorage const getItemDefaultTrue = (item) => { @@ -77,6 +92,7 @@ export const store = { sound: getItemDefaultTrue("sound"), hints: getItemDefaultTrue("hints"), highlight: getItemDefaultTrue("highlight"), + gotonext: getItemDefaultTrue("gotonext"), randomness: parseInt(localStorage.getItem("randomness")) }; if (isNaN(this.state.settings.randomness))