@mundogamernetwork/shared-ui 1.16.2 → 1.16.3
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/package.json +1 -1
- package/services/userStatusService.ts +21 -0
- package/stores/auth.ts +27 -0
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import httpService from "./httpService";
|
|
2
|
+
|
|
3
|
+
// httpService's baseURL always ends with /api/v1 (see httpService.ts's
|
|
4
|
+
// getHttpService()), so the path here must NOT repeat that prefix — unlike
|
|
5
|
+
// the per-site copies of this file, whose own httpService.ts instances
|
|
6
|
+
// don't normalize it away.
|
|
7
|
+
export const getUserStatus = async () => {
|
|
8
|
+
const params = {
|
|
9
|
+
platform_id: import.meta.env.VITE_SYSTEM_ID,
|
|
10
|
+
};
|
|
11
|
+
return await httpService.get(`/public/user-status`, { params });
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const userChangeStatus = async (status: boolean) => {
|
|
15
|
+
const params = {
|
|
16
|
+
platform_id: import.meta.env.VITE_SYSTEM_ID,
|
|
17
|
+
hidden_status: status,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return await httpService.post(`/public/user-status`, params);
|
|
21
|
+
};
|
package/stores/auth.ts
CHANGED
|
@@ -13,6 +13,8 @@ export const useAuthStore = defineStore({
|
|
|
13
13
|
signedIn: false,
|
|
14
14
|
initialized: false,
|
|
15
15
|
loading: false,
|
|
16
|
+
showOnline: false,
|
|
17
|
+
statusLoaded: false,
|
|
16
18
|
};
|
|
17
19
|
},
|
|
18
20
|
actions: {
|
|
@@ -65,6 +67,31 @@ export const useAuthStore = defineStore({
|
|
|
65
67
|
this.signedIn = false;
|
|
66
68
|
this.initialized = false;
|
|
67
69
|
this.loading = false;
|
|
70
|
+
this.showOnline = false;
|
|
71
|
+
this.statusLoaded = false;
|
|
72
|
+
},
|
|
73
|
+
// Used by shop-frontend, the one site with no local stores/auth.ts of its
|
|
74
|
+
// own (it re-exports this store directly — see its own file for why).
|
|
75
|
+
// Every other site has its own copy of this same pattern in its local
|
|
76
|
+
// store, wired to its own services/userStatusService.ts.
|
|
77
|
+
async fetchOnlineStatus() {
|
|
78
|
+
if (this.statusLoaded || !this.signedIn) return;
|
|
79
|
+
try {
|
|
80
|
+
const { getUserStatus } = await import("../services/userStatusService");
|
|
81
|
+
const response = await getUserStatus();
|
|
82
|
+
this.showOnline = !response.data.data[0].user_status[0].hidden_status;
|
|
83
|
+
this.statusLoaded = true;
|
|
84
|
+
} catch (e: any) {
|
|
85
|
+
if (e?.response?.status !== 401) {
|
|
86
|
+
this.showOnline = false;
|
|
87
|
+
this.statusLoaded = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
async toggleOnlineStatus() {
|
|
92
|
+
this.showOnline = !this.showOnline;
|
|
93
|
+
const { userChangeStatus } = await import("../services/userStatusService");
|
|
94
|
+
await userChangeStatus(!this.showOnline);
|
|
68
95
|
},
|
|
69
96
|
},
|
|
70
97
|
getters: {
|