Skip to content

Commit 1efd934

Browse files
committed
fix(web): ensure only one instance of globals are used & fix router
1 parent c18a59c commit 1efd934

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/router/create-router.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ export const createRouter = ({ baseName = '', baseUrl = import.meta.env.BASE_URL
1818
setBaseUrl(baseUrl);
1919

2020
const _routes = routes.map(r => ({ ...r, path: `${baseName}${r.path}` }));
21+
const _routesWithBase = [
22+
{
23+
path: `${baseName}/:pathMatch(.*)`,
24+
redirect: { name: Route.Calendar },
25+
},
26+
..._routes,
27+
];
2128

2229
const router = createVueRouter({
2330
history: createWebHashHistory(baseUrl),
24-
routes: [
25-
{
26-
path: `${baseName}/:pathMatch(.*)`,
27-
redirect: { name: Route.Calendar },
28-
},
29-
..._routes,
30-
],
31+
routes: _routesWithBase,
3132
});
3233

3334
const { waitAppReady } = useAppStateStoreRefs();
@@ -63,7 +64,8 @@ export const createRouter = ({ baseName = '', baseUrl = import.meta.env.BASE_URL
6364
});
6465

6566
restoreLastRoute().then(async _route => {
66-
await router.push(_route?.name !== Route.Login ? _route : { name: Route.Calendar });
67+
const isNotLogin = _route?.name && _route?.name !== Route.Login;
68+
await router.push(isNotLogin ? _route : { name: Route.Calendar });
6769
});
6870

6971
return router;

src/stores/data/activity.store.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ref, watch } from 'vue';
44

55
import type { TraktSyncActivities } from '~/models/trakt/trakt-sync.model';
66

7+
import type { RecursiveType } from '~/utils/typescript.utils';
8+
79
import { NotificationService } from '~/services/notification.service';
810
import { TraktService } from '~/services/trakt.service';
911
import { logger } from '~/stores/settings/log.store';
@@ -47,7 +49,8 @@ export const useActivityStore = defineStore('data.activity', () => {
4749
await restoreState();
4850

4951
watch(activity, (next, prev) => {
50-
const changed = compareDateObject(toDateObject(prev), toDateObject(next));
52+
if (!prev) return;
53+
const changed: RecursiveType<RecursiveType<TraktSyncActivities, Date>, boolean> = compareDateObject(toDateObject(prev), toDateObject(next));
5154

5255
if (changed?.episodes?.watched_at || changed?.shows?.hidden_at || changed?.seasons?.hidden_at) {
5356
TraktService.evict.progress.show();

src/web/init-vue-app.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createPinia } from 'pinia';
22

3-
import { createApp } from 'vue';
3+
import { createApp, getCurrentInstance } from 'vue';
44

55
import type { App, Component } from 'vue';
66

@@ -13,10 +13,13 @@ export type InitVueAppOption = RouterOptions;
1313
export const initVueApp = (component: Component, options: InitVueAppOption = {}) => {
1414
const app = createApp(component);
1515

16-
const pinia = createPinia();
16+
// check if an instance already exist, if not, create one
17+
let pinia = getCurrentInstance()?.appContext?.config?.globalProperties?.$pinia;
18+
if (!pinia) pinia = createPinia();
1719
app.use(pinia);
1820

19-
const router = createRouter(options);
21+
let router = getCurrentInstance()?.appContext?.config?.globalProperties?.$router;
22+
if (!router) router = createRouter(options);
2023
app.use(router);
2124

2225
initServices().then(() => console.info('Services initialized.'));

0 commit comments

Comments
 (0)