remove empty collections
This commit is contained in:
parent
b9964513f9
commit
ddcc80419c
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue