sort collection based on modification time desc

This commit is contained in:
Abhinav-grd 2021-02-16 17:39:43 +05:30
parent 6bb32f5c24
commit c0c8684125

View file

@ -123,7 +123,7 @@ export const syncCollections = async (token: string, key: string) => {
(await localForage.getItem<string>(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<number, file>();
const collectionMap = new Map<number, collection>();
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