Browse Source

chore(gui-v2): add types

pull/2716/head
Braks 3 years ago committed by Pranav C
parent
commit
4042a0051a
  1. 4
      packages/nc-gui-v2/composables/useGlobalState.ts
  2. 6
      packages/nc-gui-v2/plugins/tele.ts

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

@ -11,12 +11,12 @@ export const useGlobalState = (): GlobalState => {
const preferredLanguages = $(usePreferredLanguages())
const darkMode = $(usePreferredDark())
const initialState = { token: null, user: null, lang: preferredLanguages[0] || 'en', darkMode }
const initialState: State = { token: null, user: null, lang: preferredLanguages[0] || 'en', darkMode }
const storage = useStorage<State>(storageKey, initialState)
// getters
const signedIn = computed(() => storage.value.token !== undefined && storage.value.user !== undefined)
const signedIn = computed(() => storage.value.token !== null && storage.value.token !== '' && storage.value.user !== null)
// actions
function signOut() {

6
packages/nc-gui-v2/plugins/tele.ts

@ -26,6 +26,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
} catch {}
}
if (nuxtApp.$state.signedIn.value) {
await init(nuxtApp.$state.token.value)
}
router.afterEach((to, from) => {
if (!socket || (to.path === from.path && (to.query && to.query.type) === (from.query && from.query.type))) return
@ -77,8 +81,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
}
}
if (nuxtApp.$state.signedIn.value) await init(nuxtApp.$state.token.value)
watch((nuxtApp.$state as GlobalState).token, (newToken, oldToken) => {
if (newToken && newToken !== oldToken) init(newToken)
else if (!newToken) socket.disconnect()

Loading…
Cancel
Save