sort collection based on modification time desc
This commit is contained in:
parent
6bb32f5c24
commit
c0c8684125
|
@ -123,7 +123,7 @@ export const syncCollections = async (token: string, key: string) => {
|
||||||
(await localForage.getItem<string>(COLLECTION_UPDATION_TIME)) ?? '0';
|
(await localForage.getItem<string>(COLLECTION_UPDATION_TIME)) ?? '0';
|
||||||
const updatedCollections =
|
const updatedCollections =
|
||||||
(await getCollections(token, lastCollectionUpdationTime, key)) || [];
|
(await getCollections(token, lastCollectionUpdationTime, key)) || [];
|
||||||
|
localCollections.sort((a, b) => b.updationTime - a.updationTime);
|
||||||
if (updatedCollections.length == 0) {
|
if (updatedCollections.length == 0) {
|
||||||
return localCollections;
|
return localCollections;
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,7 @@ export const syncCollections = async (token: string, key: string) => {
|
||||||
updationTime = Math.max(updationTime, collection.updationTime);
|
updationTime = Math.max(updationTime, collection.updationTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
collections.sort((a, b) => a.updationTime - b.updationTime);
|
||||||
await localForage.setItem(COLLECTION_UPDATION_TIME, updationTime);
|
await localForage.setItem(COLLECTION_UPDATION_TIME, updationTime);
|
||||||
await localForage.setItem(COLLECTIONS, collections);
|
await localForage.setItem(COLLECTIONS, collections);
|
||||||
return collections;
|
return collections;
|
||||||
|
@ -165,9 +166,6 @@ export const getCollectionAndItsLatestFile = (
|
||||||
const latestFile = new Map<number, file>();
|
const latestFile = new Map<number, file>();
|
||||||
const collectionMap = new Map<number, collection>();
|
const collectionMap = new Map<number, collection>();
|
||||||
|
|
||||||
collections.forEach((collection) =>
|
|
||||||
collectionMap.set(collection.id, collection)
|
|
||||||
);
|
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
if (!latestFile.has(file.collectionID)) {
|
if (!latestFile.has(file.collectionID)) {
|
||||||
latestFile.set(file.collectionID, file);
|
latestFile.set(file.collectionID, file);
|
||||||
|
@ -176,7 +174,7 @@ export const getCollectionAndItsLatestFile = (
|
||||||
let allCollectionAndItsLatestFile: CollectionAndItsLatestFile[] = [];
|
let allCollectionAndItsLatestFile: CollectionAndItsLatestFile[] = [];
|
||||||
const userID = getData(LS_KEYS.USER).id;
|
const userID = getData(LS_KEYS.USER).id;
|
||||||
|
|
||||||
for (const [_, collection] of collectionMap) {
|
for (const collection of collections) {
|
||||||
if (
|
if (
|
||||||
collection.owner.id != userID ||
|
collection.owner.id != userID ||
|
||||||
collection.type == CollectionType.favorites
|
collection.type == CollectionType.favorites
|
||||||
|
|
Loading…
Reference in a new issue