1 import { ajax
} from "./utils/ajax";
2 import { getRandString
} from "./utils/alea";
4 // Global store: see https://medium.com/fullstackio/managing-state-in-vue-js-23a0352b1c87
14 socketCloseListener: null,
16 ajax("/variants", "GET", res
=> { this.state
.variants
= res
.variantArray
; });
17 let mysid
= localStorage
["mysid"];
20 mysid
= getRandString();
21 localStorage
["mysid"] = mysid
; //done only once (unless user clear browser data)
23 // Quick user setup using local storage:
25 id: localStorage
["myid"] || 0,
26 name: localStorage
["myname"] || "", //"" for "anonymous"
27 email: "", //unknown yet
28 notify: false, //email notifications
31 // Slow verification through the server:
32 // NOTE: still superficial identity usurpation possible, but difficult.
33 ajax("/whoami", "GET", res
=> {
34 this.state
.user
.id
= res
.id
;
35 this.state
.user
.name
= res
.name
;
36 this.state
.user
.email
= res
.email
;
37 this.state
.user
.notify
= res
.notify
;
39 // Settings initialized with values from localStorage
40 this.state
.settings
= {
41 bcolor: localStorage
.getItem("bcolor") || "lichess",
42 sound: parseInt(localStorage
.getItem("sound")) || 1,
43 hints: localStorage
.getItem("hints") == "true",
44 highlight: localStorage
.getItem("highlight") == "true",
46 const supportedLangs
= ["en","es","fr"];
47 this.state
.lang
= localStorage
["lang"] ||
48 (supportedLangs
.includes(navigator
.language
)
51 this.setTranslations();
53 updateSetting: function(propName
, value
) {
54 this.state
.settings
[propName
] = value
;
55 localStorage
.setItem(propName
, value
);
57 setTranslations: async
function() {
58 // Import translations from "./translations/$lang.js"
59 const tModule
= await
import("@/translations/" + this.state
.lang
+ ".js");
60 this.state
.tr
= tModule
.translations
;
63 this.state
.lang
= lang
;
64 this.setTranslations();