Improvements - untested
[vchess.git] / client / src / store.js
index 60e01b9..b81ec55 100644 (file)
@@ -13,7 +13,8 @@ export const store = {
   socketCloseListener: null,
   initialize() {
     ajax("/variants", "GET", res => {
-      this.state.variants = res.variantArray;
+      this.state.variants = res.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)
@@ -52,16 +53,22 @@ export const store = {
       this.state.user.notify = res.notify;
     });
     // Settings initialized with values from localStorage
+    const getItemDefaultTrue = (item) => {
+      const value = localStorage.getItem(item);
+      if (!value) return true;
+      return value == "true";
+    };
     this.state.settings = {
       bcolor: localStorage.getItem("bcolor") || "lichess",
-      sound: parseInt(localStorage.getItem("sound")) || 1,
-      hints: localStorage.getItem("hints") == "true",
-      highlight: localStorage.getItem("highlight") == "true"
+      sound: getItemDefaultTrue("sound"),
+      hints: getItemDefaultTrue("hints"),
+      highlight: getItemDefaultTrue("highlight")
     };
     const supportedLangs = ["en", "es", "fr"];
+    const navLanguage = navigator.language.substr(0,2);
     this.state.lang =
       localStorage["lang"] ||
-      (supportedLangs.includes(navigator.language) ? navigator.language : "en");
+      (supportedLangs.includes(navLanguage) ? navLanguage : "en");
     this.setTranslations();
   },
   updateSetting: function(propName, value) {