From c18c2ea9d450635f8a97fb68136ac4b42e67ec54 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Tue, 23 Mar 2021 11:34:19 -0400 Subject: [PATCH] Fix settings data migration issues --- newstore/localpersistence.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/newstore/localpersistence.ts b/newstore/localpersistence.ts index 14cbeaf29..bdfb4a4a2 100644 --- a/newstore/localpersistence.ts +++ b/newstore/localpersistence.ts @@ -1,18 +1,21 @@ import { settingsStore, bulkApplySettings, defaultSettings } from "./settings" import clone from "lodash/clone" import assign from "lodash/assign" +import eq from "lodash/eq" function checkAndMigrateOldSettings() { - // Don't do migration if the new settings object exists - if (window.localStorage.getItem("settings")) return - const vuexData = JSON.parse(window.localStorage.getItem("vuex") || "{}") - if (vuexData === {}) return - - const settingsData = clone(defaultSettings) - assign(settingsData, vuexData.postwoman.settings) + if (eq(vuexData, {})) return - window.localStorage.setItem("settings", JSON.stringify(settingsData)) + if (vuexData.postwoman && vuexData.postwoman.settings) { + const settingsData = clone(defaultSettings) + assign(settingsData, vuexData.postwoman.settings) + + window.localStorage.setItem("settings", JSON.stringify(settingsData)) + + delete vuexData.postwoman.settings + window.localStorage.setItem("vuex", JSON.stringify(vuexData)) + } } function setupSettingsPersistence() {