From 27b8ed315b63269794623fa0d5f034928a430c92 Mon Sep 17 00:00:00 2001 From: Renard Date: Fri, 4 Oct 2019 15:37:19 -0300 Subject: Asignar valores default a opciones faltantes --- src/App.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/App.js b/src/App.js index 43bb29e..04a2726 100644 --- a/src/App.js +++ b/src/App.js @@ -63,21 +63,27 @@ class App extends Component { let lsSettings = localStorage.getItem("settings"); let settings = JSON.parse(lsSettings); - + const defaultSettings = { + homeSound: "msn", + threadSound: "msn", + nightMode: false, + notifyOnHome: true, + notifyOnThread: true, + autoUpdateThreads: true, + showAvatars: true, + postPassword: this.genPassword(), + embedYoutube: true + }; if (lsSettings === null) { - let defaultSettings = { - homeSound: "msn", - threadSound: "msn", - nightMode: false, - notifyOnHome: true, - notifyOnThread: true, - autoUpdateThreads: true, - showAvatars: true, - postPassword: this.genPassword() - }; localStorage.setItem("settings", JSON.stringify(defaultSettings)); settings = defaultSettings; } else { + Object.keys(defaultSettings).forEach(key => { + if (settings[key] === undefined) { + settings[key] = defaultSettings[key]; + } + }); + localStorage.setItem("settings", JSON.stringify(defaultSettings)); this.setState({ nightMode: settings.nightMode }); } } -- cgit v1.2.1-18-gbd029