@inzombieland/nuxt-common 1.16.21 → 1.16.24

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.21",
3
+ "version": "1.16.24",
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.21";
5
+ const version = "1.16.24";
6
6
 
7
7
  const module = defineNuxtModule({
8
8
  meta: {
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { StyleProvider, Themes } from "@varlet/ui"
3
3
  import { useLocalStorage } from "@vueuse/core"
4
- import { useI18n, useLocalePath } from "#i18n"
4
+ import { useLocalePath } from "#i18n"
5
5
  import { useNuxtApp } from "#imports"
6
6
  import { onMounted, ref, watch } from "vue"
7
7
  import { useRouter } from "vue-router"
@@ -15,15 +15,12 @@ import "@vant/touch-emulator"
15
15
 
16
16
  const theme = ref("")
17
17
  const appPreferencesTheme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }))
18
- const locale = useLocalStorage("locale", "en")
19
18
  const user = useUser()
20
19
  const activeSessions = useActiveSessions()
21
20
  const { fetchActiveSessions, logout } = useUserActions()
22
21
  const localePath = useLocalePath()
23
22
  const router = useRouter()
24
23
  const appLoading = ref(Boolean(user.value))
25
- // @ts-ignore
26
- const { setLocale } = useI18n()
27
24
  const { $mobileApp } = useNuxtApp()
28
25
 
29
26
  useSubscribe("WS.SessionsUpdated", async (session: { status?: string; visitorId?: string; sessionId?: string }) => {
@@ -52,10 +49,12 @@ onMounted(() => {
52
49
  appPreferencesTheme,
53
50
  newThemeValue => {
54
51
  try {
55
- const { value } = JSON.parse(newThemeValue)
56
- theme.value = value
52
+ if (newThemeValue) {
53
+ const { value } = JSON.parse(newThemeValue)
54
+ theme.value = value
55
+ }
57
56
  } catch (error) {
58
- console.error(`Error parsing theme storage object:`, error)
57
+ console.error(`Error parsing app preferences theme:`, error)
59
58
  }
60
59
 
61
60
  if (!theme.value) {
@@ -80,14 +79,6 @@ onMounted(() => {
80
79
  { immediate: true }
81
80
  )
82
81
 
83
- watch(
84
- locale,
85
- locale => {
86
- setLocale(locale as "en" | "ru")
87
- },
88
- { immediate: true }
89
- )
90
-
91
82
  appLoading.value = false
92
83
  })
93
84
 
@@ -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) => {
@@ -1,15 +1,11 @@
1
- import { Locale as VarletLocale } from "@varlet/ui";
2
1
  import { useLocalStorage } from "@vueuse/core";
3
- import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
4
- import enUS from "vant/es/locale/lang/en-US";
5
- import ruRU from "vant/es/locale/lang/ru-RU";
6
- import { watch } from "vue";
7
2
  import { createApiFetch } from "./api-client.mjs";
8
3
  import bus from "./bus.mjs";
9
4
  import { newCometClient } from "./comet-client.mjs";
10
5
  import { useApiActions } from "./composables/use-api-actions.mjs";
11
6
  import { createApiGetUser } from "./get-user.mjs";
12
7
  import { createApiGetVisitorIdentifier } from "./get-visitor.mjs";
8
+ import { createInitApplication } from "./init-application.mjs";
13
9
  import { createApiRefreshToken } from "./refresh-token.mjs";
14
10
  import { createApiUserActions } from "./user-actions.mjs";
15
11
  export { useUser } from "./composables/use-user.mjs";
@@ -20,8 +16,8 @@ export function initApiFetch($fetch, config) {
20
16
  const fetch = createApiFetch($fetch, config);
21
17
  const getUser = createApiGetUser(fetch, config);
22
18
  const getVisitorIdentifier = createApiGetVisitorIdentifier(config);
19
+ const initApplication = createInitApplication();
23
20
  const refreshToken = createApiRefreshToken(fetch, config);
24
- const useApiFetch = () => fetch;
25
21
  const userActions = createApiUserActions(fetch, config, getUser);
26
22
  apiActions.value = {
27
23
  initialized: true,
@@ -30,8 +26,6 @@ export function initApiFetch($fetch, config) {
30
26
  };
31
27
  if (typeof window !== "undefined") {
32
28
  const loggedIn = useLocalStorage("lin", "no");
33
- const theme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }));
34
- const locale = useLocalStorage("locale", "en");
35
29
  const cometServerURL = config.cometServerURL;
36
30
  let cometClient;
37
31
  bus.subscribe("user:onUpdated", (user) => {
@@ -46,35 +40,12 @@ export function initApiFetch($fetch, config) {
46
40
  cometClient.isStarted = false;
47
41
  }
48
42
  loggedIn.value = user ? "yes" : "no";
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 theme storage object:`, error);
56
- }
57
- if (user && user.locale !== locale.value) {
58
- locale.value = user.locale;
59
- }
60
43
  });
61
- watch(
62
- locale,
63
- (locale2) => {
64
- if (locale2 === "ru") {
65
- VantLocale.use(locale2, ruRU);
66
- VarletLocale.add("en-US", VarletLocale.enUS);
67
- } else {
68
- VantLocale.use(locale2, enUS);
69
- VarletLocale.add("en-US", VarletLocale.enUS);
70
- }
71
- },
72
- { immediate: true }
73
- );
74
- setNotifyDefaultOptions({ position: "bottom" });
75
44
  bus.subscribe("app:beforeMount", () => {
76
45
  getVisitorIdentifier();
46
+ initApplication();
77
47
  });
78
48
  }
49
+ const useApiFetch = () => fetch;
79
50
  return { fetch, getUser, useApiFetch, userActions };
80
51
  }
@@ -0,0 +1 @@
1
+ export declare const createInitApplication: () => () => void;
@@ -0,0 +1,63 @@
1
+ import { Locale as VarletLocale } from "@varlet/ui";
2
+ import { useLocalStorage } from "@vueuse/core";
3
+ import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
4
+ import enUS from "vant/es/locale/lang/en-US";
5
+ import ruRU from "vant/es/locale/lang/ru-RU";
6
+ import { watch } from "vue";
7
+ import { useI18n } from "vue-i18n";
8
+ import { useUser } from "./composables/use-user.mjs";
9
+ import { once } from "./helpers/index.mjs";
10
+ function initApplication() {
11
+ const user = useUser();
12
+ const theme = useLocalStorage("app-preferences-theme", JSON.stringify({ value: "" }));
13
+ const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
14
+ const i18n = useI18n();
15
+ watch(
16
+ user,
17
+ (user2) => {
18
+ try {
19
+ const { value } = JSON.parse(theme.value);
20
+ if (user2 && user2.theme !== value) {
21
+ theme.value = JSON.stringify({ value: user2.theme });
22
+ }
23
+ } catch (error) {
24
+ console.error(`Error parsing app preferences theme:`, error);
25
+ }
26
+ try {
27
+ const { value } = JSON.parse(locale.value);
28
+ if (user2 && user2.locale !== value) {
29
+ locale.value = JSON.stringify({ value: user2.locale });
30
+ }
31
+ } catch (error) {
32
+ console.error(`Error parsing app preferences locale:`, error);
33
+ }
34
+ },
35
+ { immediate: true }
36
+ );
37
+ watch(
38
+ locale,
39
+ (locale2) => {
40
+ try {
41
+ const { value } = JSON.parse(locale2);
42
+ if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
43
+ i18n.setLocale(value);
44
+ }
45
+ if (value === "en") {
46
+ VantLocale.use(locale2, enUS);
47
+ VarletLocale.add("en-US", VarletLocale.enUS);
48
+ }
49
+ if (value === "ru") {
50
+ VantLocale.use(locale2, ruRU);
51
+ VarletLocale.add("en-US", VarletLocale.enUS);
52
+ }
53
+ } catch (error) {
54
+ console.error(`Error parsing app preferences locale:`, error);
55
+ }
56
+ },
57
+ { immediate: true }
58
+ );
59
+ setNotifyDefaultOptions({ position: "bottom" });
60
+ }
61
+ export const createInitApplication = once(() => {
62
+ return () => initApplication();
63
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/api",
3
- "version": "1.16.21",
3
+ "version": "1.16.24",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
@@ -17,7 +17,6 @@
17
17
  "ofetch": "^1.4.1",
18
18
  "rxjs": "^7.8.2",
19
19
  "vant": "^4.9.19",
20
- "vue": "^3.5.13",
21
20
  "zod": "^3.24.2"
22
21
  }
23
22
  }
@@ -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.21",
3
+ "version": "1.16.24",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {