@@ -95,7 +95,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
95
95
} ;
96
96
97
97
const updateDictionary = ( list : ListEntity , item : MinimalItem , remove ?: boolean ) => {
98
- if ( ! [ ListType . List , ListType . Watchlist ] . map ( String ) . includes ( list . type ) ) return ;
98
+ if ( ! [ ListType . List , ListType . Watchlist , ListType . Favorites ] . map ( String ) . includes ( list . type ) ) return ;
99
99
const _id = list . id . toString ( ) ;
100
100
101
101
if ( ! listDictionary [ _id ] ) listDictionary [ _id ] = { } ;
@@ -154,7 +154,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
154
154
} ;
155
155
156
156
const { evicted } = useActivityStore ( ) ;
157
- const fetchListItems = async ( { page, limit = pageSize . value , list = activeList . value } : ListQuery = { } , parallel = false ) => {
157
+ const fetchListItems = async ( { page, limit = pageSize . value , list = activeList . value } : ListQuery = { } , parallel = false , updateState = true ) => {
158
158
if ( ! isAuthenticated . value ) {
159
159
Logger . error ( 'Cannot fetch list, user is not authenticated' ) ;
160
160
return ;
@@ -170,7 +170,9 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
170
170
if ( ! parallel ) loading . value = true ;
171
171
typeLoading [ list . type ] = true ;
172
172
listDictionaryLoading [ list . id . toString ( ) ] = true ;
173
- const { clearLoading } = debounceLoading ( listItems , loadingPlaceholder , { clear : ! page , time : 1000 } ) ;
173
+
174
+ let clearLoading : ( ( ) => void ) | undefined ;
175
+ if ( updateState ) clearLoading = debounceLoading ( listItems , loadingPlaceholder , { clear : ! page , time : 1000 } ) . clearLoading ;
174
176
175
177
try {
176
178
const response = await fetchItems ( list , { pagination : { page, limit } } ) ;
@@ -179,16 +181,18 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
179
181
if ( 'id' in item ) return item ;
180
182
return { ...item , id : `${ page } -${ index } ` } ;
181
183
} ) ;
182
- pagination . value = response . pagination ?? { } ;
183
- listItems . value = page ? [ ...listItems . value . filter ( l => l . type !== ListScrollItemType . Loading ) , ...newData ] : newData ;
184
+ if ( updateState ) {
185
+ pagination . value = response . pagination ?? { } ;
186
+ listItems . value = page ? [ ...listItems . value . filter ( l => l . type !== ListScrollItemType . Loading ) , ...newData ] : newData ;
187
+ }
184
188
evicted . watchlist = false ;
185
189
} catch ( e ) {
186
190
Logger . error ( 'Failed to fetch list' ) ;
187
191
NotificationService . error ( `Failed to fetch list '${ list } '` , e ) ;
188
- listItems . value = listItems . value . filter ( l => l . type !== ListScrollItemType . Loading ) ;
192
+ if ( updateState ) listItems . value = listItems . value . filter ( l => l . type !== ListScrollItemType . Loading ) ;
189
193
throw e ;
190
194
} finally {
191
- clearLoading ( ) ;
195
+ clearLoading ?. ( ) ;
192
196
if ( ! parallel ) loading . value = false ;
193
197
typeLoading [ list . type ] = false ;
194
198
listDictionaryLoading [ list . id . toString ( ) ] = false ;
@@ -198,7 +202,7 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
198
202
const fetchAll = async ( lists : ListEntity [ ] , query ?: Omit < ListQuery , 'list' > ) => {
199
203
if ( ! lists . length ) return ;
200
204
loading . value = true ;
201
- await Promise . all ( lists . map ( list => fetchListItems ( { list, ...query } , true ) ) ) ;
205
+ await Promise . all ( lists . map ( list => fetchListItems ( { list, ...query } , true , false ) ) ) ;
202
206
loading . value = false ;
203
207
} ;
204
208
@@ -257,8 +261,9 @@ export const useListStore = defineStore(ListStoreConstants.Store, () => {
257
261
} else if ( listType === ListType . Watchlist ) {
258
262
await TraktService [ remove ? 'remove' : 'add' ] . watchlist ( { [ `${ itemType } s` ] : [ { ids : itemIds } ] } ) ;
259
263
updateDictionary ( list , { [ itemType ] : { ids : itemIds } } , remove ) ;
260
- } else if ( listType === 'favorites' ) {
264
+ } else if ( listType === ListType . Favorites ) {
261
265
await TraktService [ remove ? 'remove' : 'add' ] . favorites ( { [ `${ itemType } s` ] : [ { ids : itemIds } ] } ) ;
266
+ updateDictionary ( list , { [ itemType ] : { ids : itemIds } } , remove ) ;
262
267
} else if ( listType === ListType . Collection ) {
263
268
if ( remove ) {
264
269
await TraktService . remove . collection ( { [ `${ itemType } s` ] : [ { ids : itemIds } ] } ) ;
0 commit comments