[web] Show empty albums also (#3313)

Matches the behaviour on mobile.
This commit is contained in:
Manav Rathi
2024-09-17 16:04:28 +05:30
committed by GitHub
5 changed files with 48 additions and 99 deletions

View File

@@ -1069,19 +1069,6 @@ export const getFavCollection = async () => {
}
};
export const getNonEmptyCollections = (
collections: Collection[],
files: EnteFile[],
) => {
const nonEmptyCollectionsIds = new Set<number>();
for (const file of files) {
nonEmptyCollectionsIds.add(file.collectionID);
}
return collections.filter((collection) =>
nonEmptyCollectionsIds.has(collection.id),
);
};
export function sortCollectionSummaries(
collectionSummaries: CollectionSummary[],
sortBy: COLLECTION_LIST_SORT_BY,
@@ -1141,51 +1128,46 @@ export function getCollectionSummaries(
) {
hasUncategorizedCollection = true;
}
if (
collectionFilesCount.get(collection.id) ||
collection.type === CollectionType.uncategorized
) {
let type: CollectionSummaryType;
if (isIncomingShare(collection, user)) {
if (isIncomingCollabShare(collection, user)) {
type = CollectionSummaryType.incomingShareCollaborator;
} else {
type = CollectionSummaryType.incomingShareViewer;
}
} else if (isOutgoingShare(collection, user)) {
type = CollectionSummaryType.outgoingShare;
} else if (isSharedOnlyViaLink(collection)) {
type = CollectionSummaryType.sharedOnlyViaLink;
} else if (isArchivedCollection(collection)) {
type = CollectionSummaryType.archived;
} else if (isDefaultHiddenCollection(collection)) {
type = CollectionSummaryType.defaultHidden;
} else if (isPinnedCollection(collection)) {
type = CollectionSummaryType.pinned;
let type: CollectionSummaryType;
if (isIncomingShare(collection, user)) {
if (isIncomingCollabShare(collection, user)) {
type = CollectionSummaryType.incomingShareCollaborator;
} else {
type = CollectionSummaryType[collection.type];
type = CollectionSummaryType.incomingShareViewer;
}
let CollectionSummaryItemName: string;
if (type === CollectionSummaryType.uncategorized) {
CollectionSummaryItemName = t("UNCATEGORIZED");
} else if (type === CollectionSummaryType.favorites) {
CollectionSummaryItemName = t("FAVORITES");
} else {
CollectionSummaryItemName = collection.name;
}
collectionSummaries.set(collection.id, {
id: collection.id,
name: CollectionSummaryItemName,
latestFile: collectionLatestFiles.get(collection.id),
coverFile: collectionCoverFiles.get(collection.id),
fileCount: collectionFilesCount.get(collection.id) ?? 0,
updationTime: collection.updationTime,
type: type,
order: collection.magicMetadata?.data?.order ?? 0,
});
} else if (isOutgoingShare(collection, user)) {
type = CollectionSummaryType.outgoingShare;
} else if (isSharedOnlyViaLink(collection)) {
type = CollectionSummaryType.sharedOnlyViaLink;
} else if (isArchivedCollection(collection)) {
type = CollectionSummaryType.archived;
} else if (isDefaultHiddenCollection(collection)) {
type = CollectionSummaryType.defaultHidden;
} else if (isPinnedCollection(collection)) {
type = CollectionSummaryType.pinned;
} else {
type = CollectionSummaryType[collection.type];
}
let CollectionSummaryItemName: string;
if (type === CollectionSummaryType.uncategorized) {
CollectionSummaryItemName = t("UNCATEGORIZED");
} else if (type === CollectionSummaryType.favorites) {
CollectionSummaryItemName = t("FAVORITES");
} else {
CollectionSummaryItemName = collection.name;
}
collectionSummaries.set(collection.id, {
id: collection.id,
name: CollectionSummaryItemName,
latestFile: collectionLatestFiles.get(collection.id),
coverFile: collectionCoverFiles.get(collection.id),
fileCount: collectionFilesCount.get(collection.id) ?? 0,
updationTime: collection.updationTime,
type: type,
order: collection.magicMetadata?.data?.order ?? 0,
});
}
if (!hasUncategorizedCollection) {
collectionSummaries.set(

View File

@@ -39,7 +39,6 @@ import {
import {
constructCollectionNameMap,
getCollectionUserFacingName,
getNonEmptyPersonalCollections,
} from "utils/collection";
import { getPersonalFiles } from "utils/file";
import { getAllLocalCollections } from "../collectionService";
@@ -354,10 +353,8 @@ class ExportService {
collectionIdToOwnerIDMap,
);
const nonEmptyPersonalCollections = getNonEmptyPersonalCollections(
collections,
personalFiles,
user,
const personalCollections = collections.filter(
(collection) => collection.owner.id === user?.id,
);
const exportRecord = await this.getExportRecord(exportFolder);
@@ -365,12 +362,11 @@ class ExportService {
convertCollectionIDExportNameObjectToMap(
exportRecord.collectionExportNames,
);
const collectionIDNameMap = constructCollectionNameMap(
nonEmptyPersonalCollections,
);
const collectionIDNameMap =
constructCollectionNameMap(personalCollections);
const renamedCollections = getRenamedExportedCollections(
nonEmptyPersonalCollections,
personalCollections,
exportRecord,
);
@@ -396,7 +392,7 @@ class ExportService {
);
const deletedExportedCollections = getDeletedExportedCollections(
nonEmptyPersonalCollections,
personalCollections,
exportRecord,
);

View File

@@ -28,7 +28,6 @@ import {
ExportedCollectionPaths,
FileExportNames,
} from "types/export";
import { getNonEmptyPersonalCollections } from "utils/collection";
import { getIDBasedSortedFiles, getPersonalFiles } from "utils/file";
import {
getCollectionIDFromFileUID,
@@ -111,13 +110,11 @@ async function migrationV0ToV1(
const personalFiles = getIDBasedSortedFiles(
getPersonalFiles(localFiles, user),
);
const nonEmptyPersonalCollections = getNonEmptyPersonalCollections(
localCollections,
personalFiles,
user,
const personalCollections = localCollections.filter(
(collection) => collection.owner.id === user?.id,
);
await migrateCollectionFolders(
nonEmptyPersonalCollections,
personalCollections,
exportDir,
collectionIDPathMap,
);

View File

@@ -23,7 +23,6 @@ import {
createAlbum,
getAllLocalCollections,
getLocalCollections,
getNonEmptyCollections,
moveToCollection,
removeFromCollection,
restoreToCollection,
@@ -546,24 +545,6 @@ export function getCollectionNameMap(
);
}
export function getNonEmptyPersonalCollections(
collections: Collection[],
personalFiles: EnteFile[],
user: User,
): Collection[] {
if (!user?.id) {
throw Error("user missing");
}
const nonEmptyCollections = getNonEmptyCollections(
collections,
personalFiles,
);
const personalCollections = nonEmptyCollections.filter(
(collection) => collection.owner.id === user?.id,
);
return personalCollections;
}
export function getNonHiddenCollections(
collections: Collection[],
): Collection[] {

View File

@@ -140,19 +140,12 @@ async function totalFileCountCheck(expectedState) {
async function totalCollectionCountCheck(expectedState) {
const collections = await getLocalCollections();
const files = await getLocalFiles();
const nonEmptyCollectionIds = new Set(
files.map((file) => file.collectionID),
);
const nonEmptyCollections = collections.filter((collection) =>
nonEmptyCollectionIds.has(collection.id),
);
if (expectedState["collection_count"] === nonEmptyCollections.length) {
if (expectedState["collection_count"] === collections.length) {
console.log("collection count check passed ✅");
} else {
throw Error(
`total Collection count check failed ❌
expected : ${expectedState["collection_count"]}, got: ${nonEmptyCollections.length}`,
expected : ${expectedState["collection_count"]}, got: ${collections.length}`,
);
}
}