remove empty collections

This commit is contained in:
Abhinav-grd 2021-03-15 23:00:49 +05:30
parent b9964513f9
commit ddcc80419c
2 changed files with 16 additions and 1 deletions

View file

@ -20,6 +20,7 @@ import {
getFavItemIds,
getLocalCollections,
getCollectionUpdationTime,
getNonEmptyCollections,
} from 'services/collectionService';
import constants from 'utils/strings/constants';
import AlertBanner from './components/AlertBanner';
@ -160,12 +161,13 @@ export default function Gallery(props) {
const encryptionKey = await getActualKey();
const collections = await syncCollections(token, encryptionKey);
const { data, isUpdated } = await syncData(token, collections);
const nonEmptyCollections = getNonEmptyCollections(collections, data);
const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
collections,
data
);
const favItemIds = await getFavItemIds(data);
setCollections(collections);
setCollections(nonEmptyCollections);
if (isUpdated) {
setData(data);
}

View file

@ -362,3 +362,16 @@ const setLocalFavoriteCollection = async (collections: collection[]) => {
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)
);
};