Tinker
This commit is contained in:
@@ -21,8 +21,8 @@ import {
|
||||
} from "@/new/photos/components/gallery";
|
||||
import type { GalleryBarMode } from "@/new/photos/components/gallery/BarImpl";
|
||||
import {
|
||||
getUniqueFiles,
|
||||
setDerivativeState,
|
||||
uniqueFilesByID,
|
||||
useGalleryReducer,
|
||||
} from "@/new/photos/components/gallery/reducer";
|
||||
import { usePeopleStateSnapshot } from "@/new/photos/components/utils/ml";
|
||||
@@ -436,7 +436,7 @@ export default function Gallery() {
|
||||
() =>
|
||||
setSearchCollectionsAndFiles({
|
||||
collections: collections ?? [],
|
||||
files: getUniqueFiles(files ?? []),
|
||||
files: uniqueFilesByID(files ?? []),
|
||||
}),
|
||||
[collections, files],
|
||||
);
|
||||
@@ -612,7 +612,7 @@ export default function Gallery() {
|
||||
}
|
||||
}
|
||||
const pfSet = new Set(activePerson?.fileIDs ?? []);
|
||||
filteredFiles = getUniqueFiles(
|
||||
filteredFiles = uniqueFilesByID(
|
||||
files.filter(({ id }) => {
|
||||
if (!pfSet.has(id)) return false;
|
||||
return true;
|
||||
@@ -623,13 +623,13 @@ export default function Gallery() {
|
||||
people: filteredVisiblePeople,
|
||||
};
|
||||
} else if (activeCollectionID === TRASH_SECTION) {
|
||||
filteredFiles = getUniqueFiles([
|
||||
filteredFiles = uniqueFilesByID([
|
||||
...trashedFiles,
|
||||
...files.filter((file) => tempDeletedFileIds?.has(file.id)),
|
||||
]);
|
||||
} else {
|
||||
const baseFiles = barMode == "hidden-albums" ? hiddenFiles : files;
|
||||
filteredFiles = getUniqueFiles(
|
||||
filteredFiles = uniqueFilesByID(
|
||||
baseFiles.filter((item) => {
|
||||
if (tempDeletedFileIds?.has(item.id)) {
|
||||
return false;
|
||||
|
||||
@@ -326,19 +326,28 @@ export const setDerivativeState = (
|
||||
};
|
||||
};
|
||||
|
||||
export function getUniqueFiles(files: EnteFile[]) {
|
||||
const idSet = new Set<number>();
|
||||
const uniqueFiles = files.filter((file) => {
|
||||
if (!idSet.has(file.id)) {
|
||||
idSet.add(file.id);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* File IDs themselves are unique across all the files for the user (in fact,
|
||||
* they're unique across all the files in an Ente instance). However, we still
|
||||
* can have multiple entries for the same file ID in our local database because
|
||||
* the unit of account is not actually a file, but a "Collection File": a
|
||||
* collection and file pair.
|
||||
*
|
||||
* For example, if the same file is symlinked into two collections, then we will
|
||||
* have two "Collection File" entries for it, both with the same file ID, but
|
||||
* with different collection IDs.
|
||||
*
|
||||
* This function returns files such that only one of these entries (arbitrarily
|
||||
* picked in case of dupes) is returned.
|
||||
*/
|
||||
export const uniqueFilesByID = (files: EnteFile[]) => {
|
||||
const seen = new Set<number>();
|
||||
return files.filter(({ id }) => {
|
||||
if (seen.has(id)) return false;
|
||||
seen.add(id);
|
||||
return true;
|
||||
});
|
||||
|
||||
return uniqueFiles;
|
||||
}
|
||||
};
|
||||
|
||||
const getArchivedCollectionIDs = (collections: Collection[]) =>
|
||||
new Set<number>(
|
||||
@@ -541,7 +550,7 @@ function getHiddenItemsSummary(
|
||||
.filter((collection) => isDefaultHiddenCollection(collection))
|
||||
.map((collection) => collection.id),
|
||||
);
|
||||
const hiddenItems = getUniqueFiles(
|
||||
const hiddenItems = uniqueFilesByID(
|
||||
hiddenFiles.filter((file) =>
|
||||
defaultHiddenCollectionIds.has(file.collectionID),
|
||||
),
|
||||
@@ -589,7 +598,7 @@ function getSectionSummaries(
|
||||
}
|
||||
|
||||
function getArchivedSectionSummary(files: EnteFile[]): CollectionSummary {
|
||||
const archivedFiles = getUniqueFiles(
|
||||
const archivedFiles = uniqueFilesByID(
|
||||
files.filter((file) => isArchivedFile(file)),
|
||||
);
|
||||
return {
|
||||
@@ -662,7 +671,7 @@ function getAllSectionVisibleFiles(
|
||||
files: EnteFile[],
|
||||
archivedCollections: Set<number>,
|
||||
): EnteFile[] {
|
||||
const allSectionVisibleFiles = getUniqueFiles(
|
||||
const allSectionVisibleFiles = uniqueFilesByID(
|
||||
files.filter((file) => {
|
||||
if (
|
||||
isArchivedFile(file) ||
|
||||
|
||||
Reference in New Issue
Block a user