@inzombieland/nuxt-common 1.16.20 → 1.16.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.20",
3
+ "version": "1.16.23",
4
4
  "configKey": "nuxt-common",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.6.0",
package/dist/module.mjs CHANGED
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
2
2
  import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addPlugin, addComponent } from '@nuxt/kit';
3
3
 
4
4
  const name = "@inzombieland/nuxt-common";
5
- const version = "1.16.20";
5
+ const version = "1.16.23";
6
6
 
7
7
  const module = defineNuxtModule({
8
8
  meta: {
@@ -13,8 +13,9 @@ import bus from "./packages/api/bus"
13
13
  import type { ConfigProviderTheme } from "vant"
14
14
  import "@vant/touch-emulator"
15
15
 
16
- const theme = useLocalStorage("theme", "")
17
- const locale = useLocalStorage("locale", "en")
16
+ const theme = ref("")
17
+ const appPreferencesTheme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }))
18
+ const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }))
18
19
  const user = useUser()
19
20
  const activeSessions = useActiveSessions()
20
21
  const { fetchActiveSessions, logout } = useUserActions()
@@ -48,13 +49,23 @@ useSubscribe("WS.SessionsUpdated", async (session: { status?: string; visitorId?
48
49
 
49
50
  onMounted(() => {
50
51
  watch(
51
- theme,
52
- theme => {
53
- if (!theme) {
54
- theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
52
+ appPreferencesTheme,
53
+ newThemeValue => {
54
+ try {
55
+ if (newThemeValue) {
56
+ const { value } = JSON.parse(newThemeValue)
57
+ theme.value = value
58
+ }
59
+ } catch (error) {
60
+ console.error(`Error parsing app preferences theme:`, error)
55
61
  }
56
62
 
57
- if (theme === "dark") {
63
+ if (!theme.value) {
64
+ theme.value = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
65
+ appPreferencesTheme.value = JSON.stringify({ value: theme.value })
66
+ }
67
+
68
+ if (theme.value === "dark") {
58
69
  document.documentElement.classList.remove("light", "van-theme-light")
59
70
  document.documentElement.classList.add("dark", "van-theme-dark")
60
71
  StyleProvider(Themes.dark)
@@ -65,7 +76,7 @@ onMounted(() => {
65
76
  }
66
77
 
67
78
  if ($mobileApp?.changeTheme && typeof $mobileApp.changeTheme === "function") {
68
- $mobileApp.changeTheme({ theme })
79
+ $mobileApp.changeTheme({ theme: theme.value })
69
80
  }
70
81
  },
71
82
  { immediate: true }
@@ -74,7 +85,13 @@ onMounted(() => {
74
85
  watch(
75
86
  locale,
76
87
  locale => {
77
- setLocale(locale as "en" | "ru")
88
+ try {
89
+ const { value } = JSON.parse(locale)
90
+ setLocale(value)
91
+ } catch (error) {
92
+ console.error(`Error parsing app preferences locale:`, error)
93
+ setLocale("en")
94
+ }
78
95
  },
79
96
  { immediate: true }
80
97
  )
@@ -93,7 +110,10 @@ if (typeof window !== "undefined") {
93
110
  :class="{ app: appLoading }"
94
111
  >
95
112
  <slot />
96
- <van-config-provider :theme="theme as ConfigProviderTheme" />
113
+ <van-config-provider
114
+ v-if="theme"
115
+ :theme="theme as ConfigProviderTheme"
116
+ />
97
117
  </div>
98
118
  </template>
99
119
 
@@ -121,8 +121,8 @@ export const changeTheme = async (body) => {
121
121
  updateUser(body);
122
122
  }
123
123
  if (typeof window !== "undefined") {
124
- const theme = useLocalStorage("theme", "light");
125
- theme.value = body.theme;
124
+ const theme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }));
125
+ theme.value = JSON.stringify({ value: body.theme });
126
126
  }
127
127
  };
128
128
  export const changeLocale = async (body) => {
@@ -134,8 +134,8 @@ export const changeLocale = async (body) => {
134
134
  if (typeof window !== "undefined") {
135
135
  const localeCookie = useCookie("locale", { maxAge: 60 * 60 * 24 * 365 });
136
136
  localeCookie.value = body.locale;
137
- const locale = useLocalStorage("locale", "en");
138
- locale.value = body.locale;
137
+ const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "" }));
138
+ locale.value = JSON.stringify({ value: body.locale });
139
139
  }
140
140
  };
141
141
  export const changeAvatar = async (body) => {
@@ -30,8 +30,8 @@ export function initApiFetch($fetch, config) {
30
30
  };
31
31
  if (typeof window !== "undefined") {
32
32
  const loggedIn = useLocalStorage("lin", "no");
33
- const theme = useLocalStorage("theme", "");
34
- const locale = useLocalStorage("locale", "en");
33
+ const theme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }));
34
+ const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
35
35
  const cometServerURL = config.cometServerURL;
36
36
  let cometClient;
37
37
  bus.subscribe("user:onUpdated", (user) => {
@@ -46,20 +46,38 @@ export function initApiFetch($fetch, config) {
46
46
  cometClient.isStarted = false;
47
47
  }
48
48
  loggedIn.value = user ? "yes" : "no";
49
- if (user && user.theme !== theme.value) {
50
- theme.value = user.theme;
49
+ try {
50
+ const { value } = JSON.parse(theme.value);
51
+ if (user && user.theme !== value) {
52
+ theme.value = JSON.stringify({ value: user.theme });
53
+ }
54
+ } catch (error) {
55
+ console.error(`Error parsing app preferences theme:`, error);
51
56
  }
52
- if (user && user.locale !== locale.value) {
53
- locale.value = user.locale;
57
+ try {
58
+ const { value } = JSON.parse(locale.value);
59
+ if (user && user.locale !== value) {
60
+ locale.value = JSON.stringify({ value: user.locale });
61
+ }
62
+ } catch (error) {
63
+ console.error(`Error parsing app preferences locale:`, error);
54
64
  }
55
65
  });
56
66
  watch(
57
67
  locale,
58
68
  (locale2) => {
59
- if (locale2 === "ru") {
60
- VantLocale.use(locale2, ruRU);
61
- VarletLocale.add("en-US", VarletLocale.enUS);
62
- } else {
69
+ try {
70
+ const { value } = JSON.parse(locale2);
71
+ if (value === "en") {
72
+ VantLocale.use(locale2, enUS);
73
+ VarletLocale.add("en-US", VarletLocale.enUS);
74
+ }
75
+ if (value === "ru") {
76
+ VantLocale.use(locale2, ruRU);
77
+ VarletLocale.add("en-US", VarletLocale.enUS);
78
+ }
79
+ } catch (error) {
80
+ console.error(`Error parsing app preferences locale:`, error);
63
81
  VantLocale.use(locale2, enUS);
64
82
  VarletLocale.add("en-US", VarletLocale.enUS);
65
83
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/api",
3
- "version": "1.16.20",
3
+ "version": "1.16.23",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
@@ -1,10 +1,8 @@
1
- import { useLocalStorage } from "@vueuse/core";
2
1
  import { addRouteMiddleware, defineNuxtPlugin } from "#app";
3
2
  import { useRequestHeaders, useRuntimeConfig, useState } from "#imports";
4
3
  import { fetch, getUser } from "./api/index.mjs";
5
4
  import { authMiddleware, guestMiddleware, localeMiddleware } from "./middleware/index.mjs";
6
5
  import { flush, setToken, setUser } from "./packages/api/api-client.mjs";
7
- import bus from "./packages/api/bus.mjs";
8
6
  const useAuth = () => {
9
7
  return useState("auth", () => null);
10
8
  };
@@ -28,10 +26,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
28
26
  }
29
27
  nuxtApp.hook("app:beforeMount", () => {
30
28
  auth.value = null;
31
- bus.subscribe("user:onUpdated", (value) => {
32
- const loggedIn = useLocalStorage("lin", "no");
33
- loggedIn.value = value ? "yes" : "no";
34
- });
35
29
  });
36
30
  addRouteMiddleware("auth", authMiddleware, { global: false });
37
31
  addRouteMiddleware("guest", guestMiddleware, { global: false });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.20",
3
+ "version": "1.16.23",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {