logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/
commit: aa98e83ff003df834e50665f7ac5f265751784ed
parent edfaf5e80cb232ba6452d07614895c08c2e3978f
Author: Sean King <seanking2919@protonmail.com>
Date:   Tue,  4 Apr 2023 14:40:12 -0600

Move i18n to new store

Diffstat:

Msrc/boot/after_store.js8++++++++
Msrc/main.js6+-----
Msrc/modules/config.js3++-
Msrc/services/notification_utils/notification_utils.js3++-
Asrc/stores/i18n.js14++++++++++++++
5 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/boot/after_store.js b/src/boot/after_store.js @@ -1,4 +1,5 @@ import { createApp } from 'vue' +import { createPinia } from 'pinia' import { createRouter, createWebHistory } from 'vue-router' import vClickOutside from 'click-outside-vue3' import VueVirtualScroller from 'vue-virtual-scroller' @@ -17,6 +18,8 @@ import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js' import { applyTheme, applyConfig } from '../services/style_setter/style_setter.js' import FaviconService from '../services/favicon_service/favicon_service.js' +import { useI18nStore } from '../stores/i18n' + let staticInitialResults = null const parsedInitialResults = () => { @@ -395,6 +398,11 @@ const afterStoreSetup = async ({ store, i18n }) => { }) const app = createApp(App) + const pinia = createPinia() + + app.use(pinia) + + useI18nStore().setI18n(i18n) app.use(router) app.use(store) diff --git a/src/main.js b/src/main.js @@ -67,11 +67,6 @@ const persistedStateOptions = { } const store = createStore({ modules: { - i18n: { - getters: { - i18n: () => i18n.global - } - }, interface: interfaceModule, instance: instanceModule, // TODO refactor users/statuses modules, they depend on each other @@ -99,6 +94,7 @@ const persistedStateOptions = { strict: false // Socket modifies itself, let's ignore this for now. // strict: process.env.NODE_ENV !== 'production' }) + if (storageError) { store.dispatch('pushGlobalNotice', { messageKey: 'errors.storage_unavailable', level: 'error' }) } diff --git a/src/modules/config.js b/src/modules/config.js @@ -2,6 +2,7 @@ import Cookies from 'js-cookie' import { setPreset, applyTheme, applyConfig } from '../services/style_setter/style_setter.js' import messages from '../i18n/messages' import localeService from '../services/locale/locale.service.js' +import { useI18nStore } from '../stores/i18n.js' const BACKEND_LANGUAGE_COOKIE_NAME = 'userLanguage' @@ -194,7 +195,7 @@ const config = { applyTheme(value) break case 'interfaceLanguage': - messages.setLanguage(this.getters.i18n, value) + messages.setLanguage(useI18nStore().i18n, value) dispatch('loadUnicodeEmojiData', value) Cookies.set( BACKEND_LANGUAGE_COOKIE_NAME, diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js @@ -1,6 +1,7 @@ import { filter, sortBy, includes } from 'lodash' import { muteWordHits } from '../status_parser/status_parser.js' import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js' +import { useI18nStore } from '../../stores/i18n.js' export const notificationsFromStore = store => store.state.statuses.notifications.data @@ -59,7 +60,7 @@ export const maybeShowNotification = (store, notification) => { if (!visibleTypes(store).includes(notification.type)) return if (notification.type === 'mention' && isMutedNotification(store, notification)) return - const notificationObject = prepareNotificationObject(notification, store.rootGetters.i18n) + const notificationObject = prepareNotificationObject(notification, useI18nStore().i18n) showDesktopNotification(rootState, notificationObject) } diff --git a/src/stores/i18n.js b/src/stores/i18n.js @@ -0,0 +1,14 @@ +import { defineStore } from 'pinia' + +export const useI18nStore = defineStore('i18n', { + state: () => ({ + i18n: null + }), + actions: { + setI18n (newI18n) { + this.$patch({ + i18n: newI18n.global + }) + } + } +})