Browse Source

chore(gui-v2): remove typecasting in state plugin

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
pull/2716/head
Braks 2 years ago committed by Pranav C
parent
commit
81546ff3be
  1. 7
      packages/nc-gui-v2/composables/useGlobalState.ts
  2. 16
      packages/nc-gui-v2/plugins/state.ts

7
packages/nc-gui-v2/composables/useGlobalState.ts

@ -30,7 +30,10 @@ export const useGlobalState = (): GlobalState => {
/** reactive timestamp to check token expiry against */
const timestamp = $(useTimestamp({ immediate: true, interval: 100 }))
const { $api, vueApp } = useNuxtApp()
const {
$api,
vueApp: { i18n },
} = useNuxtApp()
/**
* Set initial language based on browser settings.
@ -42,7 +45,7 @@ export const useGlobalState = (): GlobalState => {
const [lang, code] = language.split(/[_-]/)
/** find all locales that match the language */
let availableLocales = vueApp.i18n.availableLocales.filter((locale) => locale.startsWith(lang))
let availableLocales = i18n.availableLocales.filter((locale) => locale.startsWith(lang))
/** If we can match more than one locale, we check if the code of the language matches as well */
if (availableLocales.length > 1) {

16
packages/nc-gui-v2/plugins/state.ts

@ -1,11 +1,23 @@
import { defineNuxtPlugin } from '#app'
import { useGlobalState } from '~/composables/useGlobalState'
/**
* Injects global state into nuxt app.
*
* @example
* ```js
* import { useNuxtApp } from '#app'
*
* const { $state } = useNuxtApp()
*
* console.log($state.lang.value) // 'en'
* ```
*/
export default defineNuxtPlugin((nuxtApp) => {
const storage = useGlobalState()
// set initial app language to the first preferred language (found in state)
;(nuxtApp.vueApp as any).i18n.locale.value = storage.lang.value
/** set i18n locale to stored language */
nuxtApp.vueApp.i18n.locale = storage.lang.value
nuxtApp.provide('state', storage)
})

Loading…
Cancel
Save