diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 6227241ed..9600a3767 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -123,7 +123,7 @@ export const syncCollections = async (token: string, key: string) => { (await localForage.getItem(COLLECTION_UPDATION_TIME)) ?? '0'; const updatedCollections = (await getCollections(token, lastCollectionUpdationTime, key)) || []; - + localCollections.sort((a, b) => b.updationTime - a.updationTime); if (updatedCollections.length == 0) { return localCollections; } @@ -153,6 +153,7 @@ export const syncCollections = async (token: string, key: string) => { updationTime = Math.max(updationTime, collection.updationTime); } } + collections.sort((a, b) => a.updationTime - b.updationTime); await localForage.setItem(COLLECTION_UPDATION_TIME, updationTime); await localForage.setItem(COLLECTIONS, collections); return collections; @@ -165,9 +166,6 @@ export const getCollectionAndItsLatestFile = ( const latestFile = new Map(); const collectionMap = new Map(); - collections.forEach((collection) => - collectionMap.set(collection.id, collection) - ); files.forEach((file) => { if (!latestFile.has(file.collectionID)) { latestFile.set(file.collectionID, file); @@ -176,7 +174,7 @@ export const getCollectionAndItsLatestFile = ( let allCollectionAndItsLatestFile: CollectionAndItsLatestFile[] = []; const userID = getData(LS_KEYS.USER).id; - for (const [_, collection] of collectionMap) { + for (const collection of collections) { if ( collection.owner.id != userID || collection.type == CollectionType.favorites