@@ -185,6 +185,13 @@ export const useListsStore = defineStore(ListsStoreConstants.Store, () => {
185
185
}
186
186
} ;
187
187
188
+ /** Filter favorites and collections out */
189
+ const myLists = computed ( ( ) => {
190
+ return lists . value ?. filter ( list => {
191
+ return [ ListType . List , ListType . Watchlist ] . map ( String ) . includes ( list . type ) ;
192
+ } ) ;
193
+ } ) ;
194
+
188
195
const initListsStore = async ( ) => {
189
196
await restoreState ( ) ;
190
197
@@ -193,7 +200,7 @@ export const useListsStore = defineStore(ListsStoreConstants.Store, () => {
193
200
} ) ;
194
201
} ;
195
202
196
- return { listsLoading : loading , lists, activeList, fetchLists, clearState, initListsStore, getIcon } ;
203
+ return { listsLoading : loading , lists, myLists , activeList, fetchLists, clearState, initListsStore, getIcon } ;
197
204
} ) ;
198
205
199
206
export const useListsStoreRefs = ( ) => storeToRefs ( useListsStore ( ) ) ;
@@ -209,6 +216,9 @@ type ListErrorDictionary = Partial<Record<ListEntity['type'], ErrorDictionary>>;
209
216
type ListTypeLoading = Partial < Record < ListTypes , boolean > > ;
210
217
type ListDictionaryItemLoading = Partial < Record < ListTypes , Partial < Record < ListItemTypes , Record < string , boolean > > > > > ;
211
218
219
+ type ListItemQuery = TraktWatchlistGetQuery | TraktFavoriteGetQuery | TraktCollectionGetQuery | TraktListItemsGetQuery ;
220
+ type ListQuery = { page ?: number ; limit ?: number ; list ?: ListEntity } ;
221
+
212
222
const ListStoreConstants = {
213
223
Store : 'data.list' ,
214
224
LocalPageSize : 'data.list.page-size' ,
@@ -280,10 +290,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
280
290
281
291
const { user } = useUserSettingsStoreRefs ( ) ;
282
292
283
- const fetchItems = async (
284
- list : ListEntity ,
285
- query : TraktWatchlistGetQuery | TraktFavoriteGetQuery | TraktCollectionGetQuery | TraktListItemsGetQuery ,
286
- ) => {
293
+ const fetchItems = async ( list : ListEntity , query : ListItemQuery = { } ) => {
287
294
let _query = { ...query } ;
288
295
let response ;
289
296
@@ -314,20 +321,16 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
314
321
return response ;
315
322
} ;
316
323
317
- const fetchListItems = async ( {
318
- page,
319
- limit = pageSize . value ,
320
- list = activeList . value ,
321
- } : { page ?: number ; limit ?: number ; list ?: ListEntity } = { } ) => {
322
- if ( ! firstLoad . value && loading . value ) {
324
+ const fetchListItems = async ( { page, limit = pageSize . value , list = activeList . value } : ListQuery = { } , parallel = false ) => {
325
+ if ( ! firstLoad . value && ! parallel && loading . value ) {
323
326
logger . warn ( 'Already fetching list' ) ;
324
327
return ;
325
328
}
326
329
if ( firstLoad . value ) firstLoad . value = false ;
327
330
328
331
logger . debug ( 'Fetching List' , { list, page, limit } ) ;
329
332
330
- loading . value = true ;
333
+ if ( ! parallel ) loading . value = true ;
331
334
typeLoading [ list . type ] = true ;
332
335
listDictionaryLoading [ list . id . toString ( ) ] = true ;
333
336
const timeout = debounceLoading ( listItems , loadingPlaceholder , ! page ) ;
@@ -348,12 +351,19 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
348
351
throw e ;
349
352
} finally {
350
353
clearTimeout ( timeout ) ;
351
- loading . value = false ;
354
+ if ( ! parallel ) loading . value = false ;
352
355
typeLoading [ list . type ] = false ;
353
356
listDictionaryLoading [ list . id . toString ( ) ] = false ;
354
357
}
355
358
} ;
356
359
360
+ const fetchAll = async ( lists : ListEntity [ ] , query ?: Omit < ListQuery , 'list' > ) => {
361
+ if ( ! lists . length ) return ;
362
+ loading . value = true ;
363
+ await Promise . all ( lists . map ( list => fetchListItems ( { list, ...query } , true ) ) ) ;
364
+ loading . value = false ;
365
+ } ;
366
+
357
367
const i18n = useI18n ( 'common' , 'notification' ) ;
358
368
359
369
const { fetchActivity } = useActivityStore ( ) ;
@@ -475,6 +485,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
475
485
belowThreshold,
476
486
loadingPlaceholder,
477
487
fetchListItems,
488
+ fetchAll,
478
489
filteredListItems,
479
490
initListStore,
480
491
isListLoading,
0 commit comments