Skip to content

Commit 4174de1

Browse files
committed
feat(loading): adds loading bar service
1 parent 020686f commit 4174de1

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

src/components/AppComponent.vue

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Transition } from 'vue';
33
import { RouterView } from 'vue-router';
44
55
import { NavbarComponent } from '~/components/common';
6-
76
import { useAuthSettingsStoreRefs } from '~/stores/settings/auth.store';
87
98
const { isAuthenticated } = useAuthSettingsStoreRefs();
@@ -46,7 +45,6 @@ main {
4645
display: flex;
4746
align-items: center;
4847
justify-content: center;
49-
height: calc(100vh - 2.75rem);
5048
padding: 0 2rem;
5149
}
5250
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
import { useLoadingBar } from 'naive-ui';
3+
4+
import { LoadingBarService } from '~/services/loading-bar.service';
5+
6+
const loadingBar = useLoadingBar();
7+
8+
LoadingBarService.instance = loadingBar;
9+
</script>

src/components/web/ContainerComponent.ce.vue

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
<script setup lang="ts">
2-
import { darkTheme, lightTheme, NConfigProvider } from 'naive-ui';
2+
import { darkTheme, lightTheme, NConfigProvider, NLoadingBarProvider } from 'naive-ui';
33
4-
import { computed } from 'vue';
4+
import { computed, ref } from 'vue';
55
6+
import LoadingBarProvider from '~/components/common/navbar/LoadingBarProvider.vue';
67
import { watchPreferDark } from '~/utils';
78
import { lazyComponent } from '~/utils/lazy.utils';
89
910
const AppComponent = lazyComponent(() => import('~/components/AppComponent.vue'));
1011
1112
const isDark = watchPreferDark();
1213
const theme = computed(() => (isDark.value ? darkTheme : lightTheme));
14+
15+
const root = ref<HTMLElement>();
1316
</script>
1417

1518
<template>
16-
<div id="trakt-extension-root">
19+
<div id="trakt-extension-root" ref="root">
1720
<NConfigProvider :theme="theme" abstract>
18-
<AppComponent />
21+
<NLoadingBarProvider
22+
:to="root"
23+
:loading-bar-style="{
24+
loading: {
25+
'--n-color-loading': 'white',
26+
},
27+
}"
28+
>
29+
<AppComponent />
30+
<LoadingBarProvider />
31+
</NLoadingBarProvider>
1932
</NConfigProvider>
2033
</div>
2134
</template>

src/services/loading-bar.service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { useLoadingBar } from 'naive-ui';
2+
3+
export class LoadingBarService {
4+
static instance: ReturnType<typeof useLoadingBar>;
5+
}

src/services/trakt.service.ts

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { TraktApiResponse } from '~/models/trakt/trakt-client.model';
44
import type { SettingsAuth, UserSetting } from '~/models/trakt-service.model';
55
import type { TvdbApiResponse } from '~/models/tvdb/tvdb-client.model';
66

7+
import { LoadingBarService } from '~/services/loading-bar.service';
78
import { TmdbClient } from '~/services/tmdb-client/clients/tmdb-client';
89
import { traktApi } from '~/services/trakt-client/api/trakt-api.endpoints';
910
import { TraktClient } from '~/services/trakt-client/clients/trakt-client';
@@ -101,6 +102,17 @@ export class TraktService {
101102

102103
this.traktClient.onCall(async call => {
103104
console.info('TraktClient.onCall', call);
105+
106+
const timeout = setTimeout(() => LoadingBarService.instance?.start(), 500);
107+
try {
108+
await call.query;
109+
LoadingBarService.instance?.finish();
110+
} catch (error) {
111+
LoadingBarService.instance?.error();
112+
throw error;
113+
} finally {
114+
clearTimeout(timeout);
115+
}
104116
});
105117

106118
this.tvdbClient.onAuthChange(async _auth => {

0 commit comments

Comments
 (0)