Skip to content

Commit 38cd65c

Browse files
committed
fix(loading): adds loading bar to progress page too
1 parent 447a139 commit 38cd65c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/services/trakt.service.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type { TraktWatched } from '~/models/trakt/trakt-watched.model';
2626
import type { TraktWatchlistGetQuery } from '~/models/trakt/trakt-watchlist.model';
2727
import type { SettingsAuth, UserSetting } from '~/models/trakt-service.model';
2828
import type { TvdbApiResponse } from '~/models/tvdb/tvdb-client.model';
29+
import type { CancellablePromise } from '~/utils/fetch.utils';
2930

3031
import { type BaseCacheOption, type CacheResponse, getCachedFunction, type TypedResponse } from '~/services/common/base-client';
3132
import { LoadingBarService } from '~/services/loading-bar.service';
@@ -169,24 +170,26 @@ export class TraktService {
169170
await useUserSettingsStore().setUserSetting(undefined, account);
170171
}
171172

173+
static async loadingBar<T>(query: Promise<T> | CancellablePromise<T>) {
174+
const timeout = setTimeout(() => LoadingBarService.start(), 500);
175+
try {
176+
await query;
177+
LoadingBarService.finish();
178+
} catch (error) {
179+
LoadingBarService.error();
180+
} finally {
181+
clearTimeout(timeout);
182+
}
183+
}
184+
172185
static listen() {
173186
this.traktClient.onAuthChange(async _auth => {
174187
logger.debug('TraktClient.onAuthChange', { ..._auth });
175188
});
176189

177190
this.traktClient.onCall(async call => {
178191
logger.debug('TraktClient.onCall', call);
179-
180-
const timeout = setTimeout(() => LoadingBarService.start(), 500);
181-
try {
182-
await call.query;
183-
LoadingBarService.finish();
184-
} catch (error) {
185-
LoadingBarService.error();
186-
throw error;
187-
} finally {
188-
clearTimeout(timeout);
189-
}
192+
await this.loadingBar(call.query);
190193
});
191194

192195
this.tvdbClient.onAuthChange(async _auth => {
@@ -345,7 +348,9 @@ export class TraktService {
345348

346349
static progress = {
347350
async onDeck() {
348-
const response = await TraktService.cachedProgress();
351+
const call = TraktService.cachedProgress();
352+
TraktService.loadingBar(call).catch(); // ignore loading error
353+
const response = await call;
349354
if (!response.ok) throw response;
350355
return response.json();
351356
},

0 commit comments

Comments
 (0)