remove empty collections
This commit is contained in:
parent
b9964513f9
commit
ddcc80419c
|
@ -20,6 +20,7 @@ import {
|
||||||
getFavItemIds,
|
getFavItemIds,
|
||||||
getLocalCollections,
|
getLocalCollections,
|
||||||
getCollectionUpdationTime,
|
getCollectionUpdationTime,
|
||||||
|
getNonEmptyCollections,
|
||||||
} from 'services/collectionService';
|
} from 'services/collectionService';
|
||||||
import constants from 'utils/strings/constants';
|
import constants from 'utils/strings/constants';
|
||||||
import AlertBanner from './components/AlertBanner';
|
import AlertBanner from './components/AlertBanner';
|
||||||
|
@ -160,12 +161,13 @@ export default function Gallery(props) {
|
||||||
const encryptionKey = await getActualKey();
|
const encryptionKey = await getActualKey();
|
||||||
const collections = await syncCollections(token, encryptionKey);
|
const collections = await syncCollections(token, encryptionKey);
|
||||||
const { data, isUpdated } = await syncData(token, collections);
|
const { data, isUpdated } = await syncData(token, collections);
|
||||||
|
const nonEmptyCollections = getNonEmptyCollections(collections, data);
|
||||||
const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
|
const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
|
||||||
collections,
|
collections,
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
const favItemIds = await getFavItemIds(data);
|
const favItemIds = await getFavItemIds(data);
|
||||||
setCollections(collections);
|
setCollections(nonEmptyCollections);
|
||||||
if (isUpdated) {
|
if (isUpdated) {
|
||||||
setData(data);
|
setData(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,3 +362,16 @@ const setLocalFavoriteCollection = async (collections: collection[]) => {
|
||||||
await localForage.setItem(FAV_COLLECTION, favCollection[0]);
|
await localForage.setItem(FAV_COLLECTION, favCollection[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getNonEmptyCollections = (
|
||||||
|
collections: collection[],
|
||||||
|
files: file[]
|
||||||
|
) => {
|
||||||
|
const nonEmptyCollectionsIds = new Set<number>();
|
||||||
|
for (let file of files) {
|
||||||
|
nonEmptyCollectionsIds.add(file.collectionID);
|
||||||
|
}
|
||||||
|
return collections.filter((collection) =>
|
||||||
|
nonEmptyCollectionsIds.has(collection.id)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue