From d881b92f86a38fc8992100bde61e75fe0deae32e Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 16 Mar 2026 16:56:20 +0200 Subject: [PATCH] fix import/export --- .../settings_modal/settings_modal.js | 26 ++++++++++++++++--- .../settings_modal/tabs/filtering_tab.js | 8 ++++-- src/i18n/en.json | 1 + src/stores/local_config.js | 2 ++ src/stores/sync_config.js | 16 ++++++++++-- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/components/settings_modal/settings_modal.js b/src/components/settings_modal/settings_modal.js index 25c508bef..853ef5eb0 100644 --- a/src/components/settings_modal/settings_modal.js +++ b/src/components/settings_modal/settings_modal.js @@ -9,6 +9,7 @@ import PanelLoading from 'src/components/panel_loading/panel_loading.vue' import Popover from '../popover/popover.vue' import { useInterfaceStore } from 'src/stores/interface.js' +import { LOCAL_ONLY_KEYS, useLocalConfigStore } from 'src/stores/local_config.js' import { useSyncConfigStore } from 'src/stores/sync_config.js' import { @@ -137,7 +138,24 @@ const SettingsModal = { }, onImport(data) { if (data) { - this.$store.dispatch('loadSettings', data) + Object.entries(data).forEach(([path, value]) => { + if (LOCAL_ONLY_KEYS.has(path)) { + useLocalConfigStore().set({ path, value }) + } else { + if (path.startsWith('muteFilters')) { + Object.keys(useSyncConfigStore().mergedConfig.muteFilters).forEach((key) => { + useSyncConfigStore().unsetPreference({ path: `simple.${path}.${key}` }) + }) + + Object.entries(value).forEach(([key, filter]) => { + useSyncConfigStore().setPreference({ path: `simple.${path}.${key}`, value: filter }) + }) + } else { + useSyncConfigStore().setPreference({ path: `simple.${path}`, value }) + } + } + }) + useSyncConfigStore().pushSyncConfig() } }, restore() { @@ -150,7 +168,7 @@ const SettingsModal = { this.dataThemeExporter.exportData() }, generateExport(theme = false) { - const { config } = this.$store.state + const config = useSyncConfigStore().mergedConfigWithoutDefaults let sample = config if (!theme) { const ignoreList = new Set([ @@ -159,7 +177,9 @@ const SettingsModal = { 'colors', ]) sample = Object.fromEntries( - Object.entries(sample).filter(([key]) => !ignoreList.has(key)), + Object.entries(sample).filter( + ([key, value]) => !ignoreList.has(key) && value !== undefined, + ), ) } const clone = cloneDeep(sample) diff --git a/src/components/settings_modal/tabs/filtering_tab.js b/src/components/settings_modal/tabs/filtering_tab.js index 3724ea0e7..b2694152e 100644 --- a/src/components/settings_modal/tabs/filtering_tab.js +++ b/src/components/settings_modal/tabs/filtering_tab.js @@ -93,8 +93,6 @@ const FilteringTab = { computed: { ...SharedComputedObject(), ...mapState(useSyncConfigStore, { - muteFilters: (store) => - Object.entries(store.prefsStorage.simple.muteFilters), muteFiltersObject: (store) => store.prefsStorage.simple.muteFilters, }), ...mapState(useInstanceCapabilitiesStore, ['blockExpiration']), @@ -260,6 +258,12 @@ const FilteringTab = { replyVisibility() { this.$store.dispatch('queueFlushAll') }, + muteFiltersObject() { + console.log('UPDATE') + this.muteFiltersDraftObject = cloneDeep( + useSyncConfigStore().prefsStorage.simple.muteFilters, + ) + } }, } diff --git a/src/i18n/en.json b/src/i18n/en.json index 70c099932..0165af240 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -381,6 +381,7 @@ "select_all": "Select all" }, "settings": { + "invalid_settings_imported": "Error importing settings", "add_language": "Add fallback language", "remove_language": "Remove", "primary_language": "Primary language:", diff --git a/src/stores/local_config.js b/src/stores/local_config.js index 73ea1d7d4..3611b559e 100644 --- a/src/stores/local_config.js +++ b/src/stores/local_config.js @@ -6,6 +6,8 @@ import { useInstanceStore } from 'src/stores/instance' import { defaultState as configDefaultState } from 'src/modules/default_config_state' +export const LOCAL_ONLY_KEYS = new Set(Object.keys(configDefaultState)) + export const defaultState = { prefsStorage: { ...configDefaultState, diff --git a/src/stores/sync_config.js b/src/stores/sync_config.js index b740e1bec..996f32979 100644 --- a/src/stores/sync_config.js +++ b/src/stores/sync_config.js @@ -18,7 +18,10 @@ import { toRaw } from 'vue' import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js' import { useInstanceStore } from 'src/stores/instance.js' -import { useLocalConfigStore } from 'src/stores/local_config.js' +import { + LOCAL_ONLY_KEYS, + useLocalConfigStore, +} from 'src/stores/local_config.js' import { storage } from 'src/lib/storage.js' import { @@ -35,7 +38,6 @@ export const COMMAND_TRIM_FLAGS = 1000 export const COMMAND_TRIM_FLAGS_AND_RESET = 1001 export const COMMAND_WIPE_JOURNAL = 1010 export const COMMAND_WIPE_JOURNAL_AND_STORAGE = 1011 -const LOCAL_ONLY_KEYS = new Set(Object.keys(defaultConfigLocal)) export const defaultState = { // do we need to update data on server? @@ -739,6 +741,16 @@ export const useSyncConfigStore = defineStore('sync_config', { ) return result }, + mergedConfigWithoutDefaults: (state) => { + const localPrefs = useLocalConfigStore().prefsStorage + const result = Object.fromEntries( + Object.entries(state.prefsStorage.simple).map(([k, value]) => [ + k, + LOCAL_ONLY_KEYS.has(k) ? localPrefs[k] : value, + ]), + ) + return result + }, }, persist: { afterLoad(state) {