@@ -26,6 +26,7 @@ import type { TraktWatched } from '~/models/trakt/trakt-watched.model';
26
26
import type { TraktWatchlistGetQuery } from '~/models/trakt/trakt-watchlist.model' ;
27
27
import type { SettingsAuth , UserSetting } from '~/models/trakt-service.model' ;
28
28
import type { TvdbApiResponse } from '~/models/tvdb/tvdb-client.model' ;
29
+ import type { CancellablePromise } from '~/utils/fetch.utils' ;
29
30
30
31
import { type BaseCacheOption , type CacheResponse , getCachedFunction , type TypedResponse } from '~/services/common/base-client' ;
31
32
import { LoadingBarService } from '~/services/loading-bar.service' ;
@@ -169,24 +170,26 @@ export class TraktService {
169
170
await useUserSettingsStore ( ) . setUserSetting ( undefined , account ) ;
170
171
}
171
172
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
+
172
185
static listen ( ) {
173
186
this . traktClient . onAuthChange ( async _auth => {
174
187
logger . debug ( 'TraktClient.onAuthChange' , { ..._auth } ) ;
175
188
} ) ;
176
189
177
190
this . traktClient . onCall ( async call => {
178
191
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 ) ;
190
193
} ) ;
191
194
192
195
this . tvdbClient . onAuthChange ( async _auth => {
@@ -345,7 +348,9 @@ export class TraktService {
345
348
346
349
static progress = {
347
350
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 ;
349
354
if ( ! response . ok ) throw response ;
350
355
return response . json ( ) ;
351
356
} ,
0 commit comments