diff --git a/src/App.js b/src/App.js index 65302f54a..4fcfaf2c6 100644 --- a/src/App.js +++ b/src/App.js @@ -1,9 +1,6 @@ import { throttle } from 'lodash' import { mapState } from 'pinia' import { defineAsyncComponent } from 'vue' -import { mapGetters } from 'vuex' -import messages from 'src/i18n/messages' -import localeService from 'src/services/locale/locale.service.js' import DesktopNav from './components/desktop_nav/desktop_nav.vue' import EditStatusModal from './components/edit_status_modal/edit_status_modal.vue' @@ -24,14 +21,17 @@ import WhoToFollowPanel from './components/who_to_follow_panel/who_to_follow_pan import { getOrCreateServiceWorker } from './services/sw/sw' import { windowHeight, windowWidth } from './services/window_utils/window_utils' -import { useI18nStore } from 'src/stores/i18n.js' import { useEmojiStore } from 'src/stores/emoji.js' +import { useI18nStore } from 'src/stores/i18n.js' import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInterfaceStore } from 'src/stores/interface.js' import { useShoutStore } from 'src/stores/shout.js' import { useSyncConfigStore } from 'src/stores/sync_config.js' +import messages from 'src/i18n/messages' +import localeService from 'src/services/locale/locale.service.js' + export default { name: 'app', components: { @@ -142,7 +142,9 @@ export default { return this.currentUser.background_image }, instanceBackground() { - return useSyncConfigStore().mergedConfig.hideInstanceWallpaper ? null : this.instanceBackgroundUrl + return useSyncConfigStore().mergedConfig.hideInstanceWallpaper + ? null + : this.instanceBackgroundUrl }, background() { return this.userBackground || this.instanceBackground @@ -203,7 +205,7 @@ export default { !useSyncConfigStore().mergedConfig.hideISP ) }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), ...mapState(useInterfaceStore, [ 'themeApplied', 'styleDataUsed', diff --git a/src/boot/after_store.js b/src/boot/after_store.js index b87ff8924..2171ce900 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -32,6 +32,7 @@ import { useI18nStore } from 'src/stores/i18n' import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInterfaceStore } from 'src/stores/interface.js' +import { useLocalConfigStore } from 'src/stores/local_config.js' import { useOAuthStore } from 'src/stores/oauth' import { useSyncConfigStore } from 'src/stores/sync_config.js' @@ -523,6 +524,8 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => { useInterfaceStore().setLayoutWidth(windowWidth()) useInterfaceStore().setLayoutHeight(windowHeight()) + window.syncConfig = useSyncConfigStore() + window.localConfig = useLocalConfigStore() FaviconService.initFaviconService() initServiceWorker(store) diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js index a67bd475e..e1f24c1fd 100644 --- a/src/components/attachment/attachment.js +++ b/src/components/attachment/attachment.js @@ -1,4 +1,4 @@ -import { mapGetters } from 'vuex' +import { mapState } from 'pinia' import nsfwImage from '../../assets/nsfw.png' import fileTypeService from '../../services/file_type/file_type.service.js' @@ -140,7 +140,7 @@ const Attachment = { videoTag() { return this.useModal ? 'button' : 'span' }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, watch: { 'attachment.description'(newVal) { diff --git a/src/components/chat_message/chat_message.js b/src/components/chat_message/chat_message.js index af3701ebf..b7267be2b 100644 --- a/src/components/chat_message/chat_message.js +++ b/src/components/chat_message/chat_message.js @@ -12,6 +12,7 @@ import UserAvatar from '../user_avatar/user_avatar.vue' import { useInstanceStore } from 'src/stores/instance.js' import { useInterfaceStore } from 'src/stores/interface' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faEllipsisH, faTimes } from '@fortawesome/free-solid-svg-icons' @@ -85,7 +86,7 @@ const ChatMessage = { return { left: 50 } } }, - ...mapGetters(['mergedConfig', 'findUser']), + ...mapPiniaState(useSyncConfigStore, ['mergedConfig', 'findUser']), }, data() { return { diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 76dd26352..c3bd50444 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -1,6 +1,6 @@ import { clone, filter, findIndex, get, reduce } from 'lodash' import { mapState as mapPiniaState } from 'pinia' -import { mapGetters, mapState } from 'vuex' +import { mapState } from 'vuex' import { WSConnectionStatus } from '../../services/api/api.service.js' import QuickFilterSettings from '../quick_filter_settings/quick_filter_settings.vue' @@ -393,7 +393,7 @@ const conversation = { maybeHighlight() { return this.isExpanded ? this.highlight : null }, - ...mapGetters(['mergedConfig']), + ...mapPiniaState(useSyncConfigStore, ['mergedConfig']), ...mapState({ mastoUserSocketStatus: (state) => state.api.mastoUserSocketStatus, }), diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js index 23de501de..ae46b0334 100644 --- a/src/components/emoji_input/emoji_input.js +++ b/src/components/emoji_input/emoji_input.js @@ -136,7 +136,7 @@ const EmojiInput = { return useSyncConfigStore().mergedConfig.padEmoji }, defaultCandidateIndex() { - return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1 + return useSyncConfigStore().mergedConfig.autocompleteSelect ? 0 : -1 }, preText() { return this.modelValue.slice(0, this.caret) @@ -165,7 +165,7 @@ const EmojiInput = { }, languages() { return ensureFinalFallback( - this.$store.getters.mergedConfig.interfaceLanguage, + useSyncConfigStore().mergedConfig.interfaceLanguage, ) }, maybeLocalizedEmojiNamesAndKeywords() { diff --git a/src/components/extra_notifications/extra_notifications.js b/src/components/extra_notifications/extra_notifications.js index bfe8dbe42..e00f58bec 100644 --- a/src/components/extra_notifications/extra_notifications.js +++ b/src/components/extra_notifications/extra_notifications.js @@ -3,6 +3,7 @@ import { mapGetters } from 'vuex' import { useAnnouncementsStore } from 'src/stores/announcements.js' import { useInterfaceStore } from 'src/stores/interface.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js index 37c30355c..ce537663f 100644 --- a/src/components/mention_link/mention_link.js +++ b/src/components/mention_link/mention_link.js @@ -1,3 +1,4 @@ +import { mapState as mapPiniaState } from 'pinia' import { defineAsyncComponent } from 'vue' import { mapGetters, mapState } from 'vuex' @@ -8,6 +9,8 @@ import { import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue' import UserAvatar from '../user_avatar/user_avatar.vue' +import { useSyncConfigStore } from 'src/stores/sync_config.js' + import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import { library } from '@fortawesome/fontawesome-svg-core' @@ -156,7 +159,7 @@ const MentionLink = { shouldFadeDomain() { return this.mergedConfig.mentionLinkFadeDomain }, - ...mapGetters(['mergedConfig']), + ...mapPiniaState(useSyncConfigStore, ['mergedConfig']), ...mapState({ currentUser: (state) => state.users.currentUser, }), diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index df2792c80..73b057eac 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -412,7 +412,7 @@ const PostStatusForm = { ) ) }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), ...mapState(useInterfaceStore, { mobileLayout: (store) => store.mobileLayout, }), diff --git a/src/components/quick_filter_settings/quick_filter_settings.js b/src/components/quick_filter_settings/quick_filter_settings.js index 6dc2b57af..feaa1c3ca 100644 --- a/src/components/quick_filter_settings/quick_filter_settings.js +++ b/src/components/quick_filter_settings/quick_filter_settings.js @@ -1,9 +1,9 @@ import { mapState } from 'pinia' -import { mapGetters } from 'vuex' import Popover from '../popover/popover.vue' import { useInterfaceStore } from 'src/stores/interface.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faFilter, faFont, faWrench } from '@fortawesome/free-solid-svg-icons' @@ -31,7 +31,7 @@ const QuickFilterSettings = { }, }, computed: { - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), ...mapState(useInterfaceStore, { mobileLayout: (state) => state.layoutType === 'mobile', }), @@ -87,7 +87,10 @@ const QuickFilterSettings = { }, set() { const value = !this.hideMedia - useSyncConfigStore().setSimplePrefAndSave({ path: 'hideAttachments', value }) + useSyncConfigStore().setSimplePrefAndSave({ + path: 'hideAttachments', + value, + }) useSyncConfigStore().setSimplePrefAndSave({ path: 'hideAttachmentsInConv', value, @@ -112,7 +115,10 @@ const QuickFilterSettings = { }, set() { const value = !this.muteBotStatuses - useSyncConfigStore().setSimplePrefAndSave({ path: 'muteBotStatuses', value }) + useSyncConfigStore().setSimplePrefAndSave({ + path: 'muteBotStatuses', + value, + }) }, }, muteSensitiveStatuses: { diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index f93e3eb59..cb9bb0466 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -259,7 +259,10 @@ export default { const writePath = `simple.${readPath}` if (!this.timedApplyMode) { - useSyncConfigStore().setSimplePrefAndSave({ path: writePath, value }) + useSyncConfigStore().setSimplePrefAndSave({ + path: writePath, + value, + }) useSyncConfigStore().pushSyncConfig() } else { if (useInterfaceStore().temporaryChangesTimeoutId !== null) { diff --git a/src/components/settings_modal/tabs/general_tab.js b/src/components/settings_modal/tabs/general_tab.js index 4a618bd67..7910744c7 100644 --- a/src/components/settings_modal/tabs/general_tab.js +++ b/src/components/settings_modal/tabs/general_tab.js @@ -10,8 +10,8 @@ import SharedComputedObject from '../helpers/shared_computed_object.js' import UnitSetting from '../helpers/unit_setting.vue' import { useInstanceStore } from 'src/stores/instance.js' -import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import localeService from 'src/services/locale/locale.service.js' diff --git a/src/components/settings_modal/tabs/posts_tab.js b/src/components/settings_modal/tabs/posts_tab.js index bf0b8d200..d81e67b51 100644 --- a/src/components/settings_modal/tabs/posts_tab.js +++ b/src/components/settings_modal/tabs/posts_tab.js @@ -5,6 +5,8 @@ import IntegerSetting from '../helpers/integer_setting.vue' import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue' import SharedComputedObject from '../helpers/shared_computed_object.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' + const GeneralTab = { data() { return { diff --git a/src/components/side_drawer/side_drawer.js b/src/components/side_drawer/side_drawer.js index a906cd3ba..bc8f9226d 100644 --- a/src/components/side_drawer/side_drawer.js +++ b/src/components/side_drawer/side_drawer.js @@ -10,8 +10,8 @@ import { useAnnouncementsStore } from 'src/stores/announcements' import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInterfaceStore } from 'src/stores/interface' -import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useShoutStore } from 'src/stores/shout' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { diff --git a/src/components/status_action_buttons/buttons_definitions.js b/src/components/status_action_buttons/buttons_definitions.js index 20db7aa45..5a44e1ca5 100644 --- a/src/components/status_action_buttons/buttons_definitions.js +++ b/src/components/status_action_buttons/buttons_definitions.js @@ -3,6 +3,7 @@ import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useReportsStore } from 'src/stores/reports.js' import { useStatusHistoryStore } from 'src/stores/statusHistory.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' const PRIVATE_SCOPES = new Set(['private', 'direct']) const PUBLIC_SCOPES = new Set(['public', 'unlisted']) @@ -52,7 +53,7 @@ export const BUTTONS = [ !PRIVATE_SCOPES.has(status.visibility)), toggleable: true, confirm: ({ status, getters }) => - !status.repeated && getters.mergedConfig.modalOnRepeat, + !status.repeated && useSyncConfigStore().mergedConfig.modalOnRepeat, confirmStrings: { title: 'status.repeat_confirm_title', body: 'status.repeat_confirm', @@ -227,7 +228,7 @@ export const BUTTONS = [ currentUser.privileges.includes('messages_delete')) ) }, - confirm: ({ getters }) => getters.mergedConfig.modalOnDelete, + confirm: ({ getters }) => useSyncConfigStore().mergedConfig.modalOnDelete, confirmStrings: { title: 'status.delete_confirm_title', body: 'status.delete_confirm', diff --git a/src/components/status_body/status_body.js b/src/components/status_body/status_body.js index 4a3872895..a8402a7ed 100644 --- a/src/components/status_body/status_body.js +++ b/src/components/status_body/status_body.js @@ -1,7 +1,9 @@ -import { mapGetters } from 'vuex' +import { mapState } from 'pinia' import RichContent from 'src/components/rich_content/rich_content.jsx' +import { useSyncConfigStore } from 'src/stores/sync_config.js' + import fileType from 'src/services/file_type/file_type.service' import { library } from '@fortawesome/fontawesome-svg-core' @@ -110,7 +112,7 @@ const StatusBody = { collapsedStatus() { return this.status.raw_html.replace(/(\n|)/g, ' ') }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, components: { RichContent, diff --git a/src/components/status_content/status_content.js b/src/components/status_content/status_content.js index 464005a62..678005801 100644 --- a/src/components/status_content/status_content.js +++ b/src/components/status_content/status_content.js @@ -1,3 +1,4 @@ +import { mapState as mapPiniaState } from 'pinia' import { mapGetters, mapState } from 'vuex' import StatusBody from 'src/components/status_body/status_body.vue' @@ -123,7 +124,7 @@ const StatusContent = { maxThumbnails() { return this.mergedConfig.maxThumbnails }, - ...mapGetters(['mergedConfig']), + ...mapPiniaState(useSyncConfigStore, ['mergedConfig']), ...mapState({ currentUser: (state) => state.users.currentUser, }), diff --git a/src/components/timeago/timeago.js b/src/components/timeago/timeago.js index efb92d4cd..a9e874862 100644 --- a/src/components/timeago/timeago.js +++ b/src/components/timeago/timeago.js @@ -1,3 +1,5 @@ +import { useSyncConfigStore } from 'src/stores/sync_config.js' + import * as DateUtils from 'src/services/date_utils/date_utils.js' import localeService from 'src/services/locale/locale.service.js' @@ -13,17 +15,17 @@ export default { }, computed: { shouldUseAbsoluteTimeFormat() { - if (!this.$store.getters.mergedConfig.useAbsoluteTimeFormat) { + if (!useSyncConfigStore().mergedConfig.useAbsoluteTimeFormat) { return false } return ( DateUtils.durationStrToMs( - this.$store.getters.mergedConfig.absoluteTimeFormatMinAge, + useSyncConfigStore().mergedConfig.absoluteTimeFormatMinAge, ) <= this.relativeTimeMs ) }, time12hFormat() { - return this.$store.getters.mergedConfig.absoluteTimeFormat12h === '12h' + return useSyncConfigStore().mergedConfig.absoluteTimeFormat12h === '12h' }, browserLocale() { return localeService.internalToBrowserLocale(this.$i18n.locale) diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index b94a9ab9a..3a1ede69c 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -1,7 +1,7 @@ import isEqual from 'lodash/isEqual' import merge from 'lodash/merge' import ldUnescape from 'lodash/unescape' -import { mapGetters } from 'vuex' +import { mapState } from 'pinia' import Checkbox from 'src/components/checkbox/checkbox.vue' import ColorInput from 'src/components/color_input/color_input.vue' @@ -243,7 +243,7 @@ export default { }) } }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, userHighlightColor: { get() { @@ -391,7 +391,7 @@ export default { ], }) }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, methods: { muteUser() { diff --git a/src/modules/users.js b/src/modules/users.js index a8752feff..d3e6eae7c 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -682,7 +682,6 @@ const users = { useInterfaceStore().setLastTimeline('public-timeline') useInterfaceStore().setLayoutWidth(windowWidth()) useInterfaceStore().setLayoutHeight(windowHeight()) - //useSyncConfigStore().clearSyncConfig() }) }, loginUser(store, accessToken) { @@ -780,7 +779,7 @@ const users = { dispatch('startFetchingFollowRequests') } - if (store.getters.mergedConfig.useStreamingApi) { + if (useSyncConfigStore().mergedConfig.useStreamingApi) { dispatch('fetchTimeline', { timeline: 'friends', since: null }) dispatch('fetchNotifications', { since: null }) dispatch('enableMastoSockets', true) diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 73411b6a5..fd3ef568c 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -4,6 +4,7 @@ import { promiseInterval } from '../promise_interval/promise_interval.js' import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInterfaceStore } from 'src/stores/interface.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' const update = ({ store, notifications, older }) => { store.dispatch('addNewNotifications', { notifications, older }) @@ -26,10 +27,9 @@ const mastoApiNotificationTypes = new Set([ const fetchAndUpdate = ({ store, credentials, older = false, since }) => { const args = { credentials } - const { getters } = store const rootState = store.rootState || store.state const timelineData = rootState.notifications - const hideMutedPosts = getters.mergedConfig.hideMutedPosts + const hideMutedPosts = useSyncConfigStore().mergedConfig.hideMutedPosts if (useInstanceCapabilitiesStore().pleromaChatMessagesAvailable) { mastoApiNotificationTypes.add('pleroma:chat_mention') diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index da62f8b37..b59653502 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -6,6 +6,7 @@ import { promiseInterval } from '../promise_interval/promise_interval.js' import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInterfaceStore } from 'src/stores/interface.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' const update = ({ store, @@ -44,9 +45,8 @@ const fetchAndUpdate = ({ }) => { const args = { timeline, credentials } const rootState = store.rootState || store.state - const { getters } = store const timelineData = rootState.statuses.timelines[camelCase(timeline)] - const { hideMutedPosts, replyVisibility } = getters.mergedConfig + const { hideMutedPosts, replyVisibility } = useSyncConfigStore().mergedConfig const loggedIn = !!rootState.users.currentUser if (older) { diff --git a/src/stores/i18n.js b/src/stores/i18n.js index f013f7c8f..78706af17 100644 --- a/src/stores/i18n.js +++ b/src/stores/i18n.js @@ -1,7 +1,8 @@ import Cookies from 'js-cookie' +import { defineStore } from 'pinia' + import messages from 'src/i18n/messages' import localeService from 'src/services/locale/locale.service.js' -import { defineStore } from 'pinia' const BACKEND_LANGUAGE_COOKIE_NAME = 'userLanguage' @@ -21,6 +22,6 @@ export const useI18nStore = defineStore('i18n', { BACKEND_LANGUAGE_COOKIE_NAME, localeService.internalToBackendLocaleMulti(value), ) - } + }, }, }) diff --git a/src/stores/interface.js b/src/stores/interface.js index e61186e7e..77982f927 100644 --- a/src/stores/interface.js +++ b/src/stores/interface.js @@ -186,7 +186,7 @@ export const useInterfaceStore = defineStore('interface', { const mobileLayout = width <= 800 const normalOrMobile = mobileLayout ? 'mobile' : 'normal' - const { thirdColumnMode } = window.vuex.getters.mergedConfig + const { thirdColumnMode } = useSyncConfigStore().mergedConfig if (thirdColumnMode === 'none' || !window.vuex.state.users.currentUser) { this.layoutType = normalOrMobile } else { @@ -252,7 +252,10 @@ export const useInterfaceStore = defineStore('interface', { this.resetThemeV3Palette() this.resetThemeV2() - useSyncConfigStore().setPreference({ path: 'simple.paletteCustomData', value }) + useSyncConfigStore().setPreference({ + path: 'simple.paletteCustomData', + value, + }) useSyncConfigStore().pushSyncConfig() this.applyTheme({ recompile: true }) @@ -292,7 +295,10 @@ export const useInterfaceStore = defineStore('interface', { this.resetThemeV2() this.resetThemeV3Palette() - useSyncConfigStore().setPreference({ path: 'simple.styleCustomData', value }) + useSyncConfigStore().setPreference({ + path: 'simple.styleCustomData', + value, + }) useSyncConfigStore().pushSyncConfig() this.useStylePalette = true @@ -330,18 +336,27 @@ export const useInterfaceStore = defineStore('interface', { this.resetThemeV2() useSyncConfigStore().setPreference({ path: 'simple.customTheme', value }) - useSyncConfigStore().setPreference({ path: 'simple.customThemeSource', value }) + useSyncConfigStore().setPreference({ + path: 'simple.customThemeSource', + value, + }) useSyncConfigStore().pushSyncConfig() this.applyTheme({ recompile: true }) }, resetThemeV3() { useSyncConfigStore().setPreference({ path: 'simple.style', value: null }) - useSyncConfigStore().setPreference({ path: 'simple.styleCustomData', value: null }) + useSyncConfigStore().setPreference({ + path: 'simple.styleCustomData', + value: null, + }) useSyncConfigStore().pushSyncConfig() }, resetThemeV3Palette() { - useSyncConfigStore().setPreference({ path: 'simple.palette', value: null }) + useSyncConfigStore().setPreference({ + path: 'simple.palette', + value: null, + }) useSyncConfigStore().setPreference({ path: 'simple.paletteCustomData', value: null, @@ -350,7 +365,10 @@ export const useInterfaceStore = defineStore('interface', { }, resetThemeV2() { useSyncConfigStore().setPreference({ path: 'simple.theme', value: null }) - useSyncConfigStore().setPreference({ path: 'simple.customTheme', value: null }) + useSyncConfigStore().setPreference({ + path: 'simple.customTheme', + value: null, + }) useSyncConfigStore().setPreference({ path: 'simple.customThemeSource', value: null, diff --git a/src/stores/local_config.js b/src/stores/local_config.js new file mode 100644 index 000000000..208ae09cf --- /dev/null +++ b/src/stores/local_config.js @@ -0,0 +1,50 @@ +import { cloneDeep, set } from 'lodash' +import { defineStore } from 'pinia' +import { toRaw } from 'vue' + +import { useInstanceStore } from 'src/stores/instance' + +import { defaultState as configDefaultState } from 'src/modules/default_config_state' + +export const defaultState = { + prefsStorage: { + ...configDefaultState, + }, +} + +export const useLocalConfigStore = defineStore('local_config', { + state() { + return cloneDeep(defaultState) + }, + actions: { + set({ path, value }) { + set(this.prefsStorage, path, value) + }, + unset({ path, value }) { + set(this.prefsStorage, path, undefined) + }, + clearSyncConfig() { + const blankState = { ...cloneDeep(defaultState) } + Object.keys(this).forEach((k) => { + this.prefsStorage[k] = blankState[k] + }) + }, + }, + getters: { + mergedConfig: (state) => { + const instancePrefs = useInstanceStore().prefsStorage + const result = Object.fromEntries( + Object.entries(state.prefsStorage).map(([k, v]) => [ + k, + v ?? instancePrefs[k], + ]), + ) + return result + }, + }, + persist: { + afterLoad(state) { + return state + }, + }, +}) diff --git a/src/stores/sync_config.js b/src/stores/sync_config.js index 99ff0f6d5..05a47fa64 100644 --- a/src/stores/sync_config.js +++ b/src/stores/sync_config.js @@ -97,14 +97,18 @@ const _verifyPrefs = (state) => { if (typeof v === 'undefined') return if (typeof v === 'number' || typeof v === 'boolean') return if (typeof v === 'object') return - console.warn(`Preference simple.${k} as invalid type ${typeof v}, reinitializing`) + console.warn( + `Preference simple.${k} as invalid type ${typeof v}, reinitializing`, + ) set(state.prefsStorage.simple, k, defaultState.prefsStorage.simple[k]) }) // Collections Object.entries(defaultState.prefsStorage.collections).forEach(([k, v]) => { if (Array.isArray(v)) return - console.warn(`Preference collections.${k} as invalid type ${typeof v}, reinitializing`) + console.warn( + `Preference collections.${k} as invalid type ${typeof v}, reinitializing`, + ) set( state.prefsStorage.collections, k, @@ -306,7 +310,9 @@ export const _mergePrefs = (recent, stale) => { break case 'addToCollection': if (!path.startsWith('collections')) { - return console.error('Illegal operation "addToCollection" on a non-collection') + return console.error( + 'Illegal operation "addToCollection" on a non-collection', + ) } set( resultOutput, @@ -316,7 +322,9 @@ export const _mergePrefs = (recent, stale) => { break case 'removeFromCollection': { if (!path.startsWith('collections')) { - return console.error('Illegal operation "removeFromCollection" on a non-collection') + return console.error( + 'Illegal operation "removeFromCollection" on a non-collection', + ) } const newSet = new Set(get(resultOutput, path)) newSet.delete(args[0]) @@ -438,9 +446,7 @@ export const useSyncConfigStore = defineStore('sync_config', { `Tried to edit internal (starts with _) field '${path}', ignoring.`, ) } - if ( - path.startsWith('collections') - ) { + if (path.startsWith('collections')) { throw new Error( `Invalid operation 'set' for collection field '${path}', ignoring.`, ) @@ -468,9 +474,7 @@ export const useSyncConfigStore = defineStore('sync_config', { `Tried to edit internal (starts with _) field '${path}', ignoring.`, ) } - if ( - path.startsWith('collections') - ) { + if (path.startsWith('collections')) { throw new Error( `Invalid operation 'unset' for collection field '${path}', ignoring.`, )