X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fstore.js;h=b81ec5524639866ad2c1d5c7a9f59732364c6716;hb=db1f1f9adb920605c7a16b060a7737e54636ee08;hp=e7e869717f76ec150e1b66fcea0c2d3e8e226190;hpb=e9b0b5043dc87ebc6857c255e2202a215912c4d9;p=vchess.git diff --git a/client/src/store.js b/client/src/store.js index e7e86971..b81ec552 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -53,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) {