@inzombieland/nuxt-common 1.16.29 → 1.17.0

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.29",
3
+ "version": "1.17.0",
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.29";
5
+ const version = "1.17.0";
6
6
 
7
7
  const module = defineNuxtModule({
8
8
  meta: {
@@ -1,6 +1,5 @@
1
- import { useLocalStorage } from "@vueuse/core";
2
1
  import { useCookie, useRequestHeaders } from "#imports";
3
- import { useThemeMode } from "../packages/api/index.mjs";
2
+ import { useAppLocale, useThemeMode } from "../packages/api/index.mjs";
4
3
  import { flush, setToken, updateUser } from "../packages/api/api-client.mjs";
5
4
  import { fetch, getUser, userActions, useUser } from "./index.mjs";
6
5
  export const signIn = userActions.signIn;
@@ -135,8 +134,8 @@ export const changeLocale = async (body) => {
135
134
  if (typeof window !== "undefined") {
136
135
  const localeCookie = useCookie("locale", { maxAge: 60 * 60 * 24 * 365 });
137
136
  localeCookie.value = body.locale;
138
- const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "" }));
139
- locale.value = JSON.stringify({ value: body.locale });
137
+ const locale = useAppLocale();
138
+ locale.value = { value: body.locale };
140
139
  }
141
140
  };
142
141
  export const changeAvatar = async (body) => {
@@ -0,0 +1,3 @@
1
+ import { useAppLocale } from "../packages/api";
2
+ export { useAppLocale };
3
+ export default useAppLocale;
@@ -0,0 +1,3 @@
1
+ import { useAppLocale } from "../packages/api/index.mjs";
2
+ export { useAppLocale };
3
+ export default useAppLocale;
@@ -0,0 +1 @@
1
+ export declare const useAppLocale: () => import("@vueuse/shared").RemovableRef<any>;
@@ -0,0 +1,13 @@
1
+ import { useLocalStorage } from "@vueuse/core";
2
+ export const useAppLocale = () => {
3
+ return useLocalStorage(
4
+ "app-preferences-locale",
5
+ { value: "en" },
6
+ {
7
+ serializer: {
8
+ read: (v) => v ? JSON.parse(v) : null,
9
+ write: (v) => JSON.stringify(v)
10
+ }
11
+ }
12
+ );
13
+ };
@@ -6,6 +6,7 @@ export { useUser } from "./composables/use-user";
6
6
  export { useSubscribe } from "./composables/use-subscribe";
7
7
  export { useActiveSessions } from "./composables/use-active-sessions";
8
8
  export { useThemeMode } from "./composables/use-theme-mode";
9
+ export { useAppLocale } from "./composables/use-app-locale";
9
10
  export { getVisitor, getVisitorId, type Visitor } from "./get-visitor";
10
11
  export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
11
12
  fetch: Fetch;
@@ -14,6 +14,7 @@ export { useUser } from "./composables/use-user.mjs";
14
14
  export { useSubscribe } from "./composables/use-subscribe.mjs";
15
15
  export { useActiveSessions } from "./composables/use-active-sessions.mjs";
16
16
  export { useThemeMode } from "./composables/use-theme-mode.mjs";
17
+ export { useAppLocale } from "./composables/use-app-locale.mjs";
17
18
  export { getVisitor, getVisitorId } from "./get-visitor.mjs";
18
19
  const apiActions = useApiActions();
19
20
  let userActions;
@@ -1,5 +1,4 @@
1
1
  import { StyleProvider, Themes, Locale as VarletLocale } from "@varlet/ui";
2
- import { useLocalStorage } from "@vueuse/core";
3
2
  import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
4
3
  import enUS from "vant/es/locale/lang/en-US";
5
4
  import ruRU from "vant/es/locale/lang/ru-RU";
@@ -10,24 +9,19 @@ import { useActiveSessions } from "./composables/use-active-sessions.mjs";
10
9
  import { useSubscribe } from "./composables/use-subscribe.mjs";
11
10
  import { useUser } from "./composables/use-user.mjs";
12
11
  import { once } from "./helpers/index.mjs";
13
- import { getVisitorId, useThemeMode, useUserActions } from "./index.mjs";
12
+ import { getVisitorId, useAppLocale, useThemeMode, useUserActions } from "./index.mjs";
14
13
  function initApplication() {
15
14
  const router = useRouter();
16
15
  const user = useUser();
17
16
  const theme = useThemeMode();
18
- const locale = useLocalStorage("app-preferences-locale", JSON.stringify({ value: "en" }));
17
+ const locale = useAppLocale();
19
18
  const i18n = useI18n();
20
19
  watch(user, (user2) => {
21
20
  if (user2 && user2.theme !== theme.value?.value) {
22
21
  theme.value = { value: user2.theme };
23
22
  }
24
- try {
25
- const { value } = JSON.parse(locale.value);
26
- if (user2 && user2.locale !== value) {
27
- locale.value = JSON.stringify({ value: user2.locale });
28
- }
29
- } catch (error) {
30
- console.error(`Error parsing app preferences locale:`, error);
23
+ if (user2 && user2.locale !== locale.value?.value) {
24
+ locale.value = { value: user2.locale };
31
25
  }
32
26
  });
33
27
  watch(
@@ -48,21 +42,16 @@ function initApplication() {
48
42
  watch(
49
43
  locale,
50
44
  (locale2) => {
51
- try {
52
- const { value } = JSON.parse(locale2);
53
- if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
54
- i18n.setLocale(value);
55
- }
56
- if (value === "en") {
57
- VantLocale.use(locale2, enUS);
58
- VarletLocale.add("en-US", VarletLocale.enUS);
59
- }
60
- if (value === "ru") {
61
- VantLocale.use(locale2, ruRU);
62
- VarletLocale.add("en-US", VarletLocale.enUS);
63
- }
64
- } catch (error) {
65
- console.error(`Error parsing app preferences locale:`, error);
45
+ if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
46
+ i18n.setLocale(locale2?.value);
47
+ }
48
+ if (locale2?.value === "en") {
49
+ VantLocale.use(locale2, enUS);
50
+ VarletLocale.add("en-US", VarletLocale.enUS);
51
+ }
52
+ if (locale2?.value === "ru") {
53
+ VantLocale.use(locale2, ruRU);
54
+ VarletLocale.add("en-US", VarletLocale.enUS);
66
55
  }
67
56
  },
68
57
  { immediate: true }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/api",
3
- "version": "1.16.29",
3
+ "version": "1.17.0",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.29",
3
+ "version": "1.17.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {