Move
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { stashRedirect } from "@/accounts/services/redirect";
|
||||
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
|
||||
import { ALL_SECTION } from "@/new/photos/services/collection";
|
||||
import { createFileCollectionIDs } from "@/new/photos/services/file";
|
||||
import { getLocalFiles } from "@/new/photos/services/files";
|
||||
import { AppContext } from "@/new/photos/types/context";
|
||||
import { VerticallyCentered } from "@ente/shared/components/Container";
|
||||
@@ -28,7 +29,7 @@ import {
|
||||
DefaultDeduplicateContext,
|
||||
} from "types/deduplicate";
|
||||
import { SelectedState } from "types/gallery";
|
||||
import { constructFileToCollectionMap, getSelectedFiles } from "utils/file";
|
||||
import { getSelectedFiles } from "utils/file";
|
||||
|
||||
export const DeduplicateContext = createContext<DeduplicateContextType>(
|
||||
DefaultDeduplicateContext,
|
||||
@@ -114,7 +115,7 @@ export default function Deduplicate() {
|
||||
}, [duplicates]);
|
||||
|
||||
const fileToCollectionsMap = useMemoSingleThreaded(() => {
|
||||
return constructFileToCollectionMap(duplicateFiles);
|
||||
return createFileCollectionIDs(duplicateFiles);
|
||||
}, [duplicateFiles]);
|
||||
|
||||
const deleteFileHelper = async () => {
|
||||
|
||||
@@ -140,12 +140,7 @@ import {
|
||||
getSelectedCollection,
|
||||
handleCollectionOps,
|
||||
} from "utils/collection";
|
||||
import {
|
||||
FILE_OPS_TYPE,
|
||||
constructFileToCollectionMap,
|
||||
getSelectedFiles,
|
||||
handleFileOps,
|
||||
} from "utils/file";
|
||||
import { FILE_OPS_TYPE, getSelectedFiles, handleFileOps } from "utils/file";
|
||||
import { getSessionExpiredMessage } from "utils/ui";
|
||||
import { getLocalFamilyData } from "utils/user/family";
|
||||
|
||||
@@ -339,6 +334,7 @@ export default function Gallery() {
|
||||
const defaultHiddenCollectionIDs = state.defaultHiddenCollectionIDs;
|
||||
const hiddenFileIDs = state.hiddenFileIDs;
|
||||
const collectionNameMap = state.allCollectionNameByID;
|
||||
const fileToCollectionsMap = state.fileCollectionIDs;
|
||||
const collectionSummaries = state.collectionSummaries;
|
||||
const hiddenCollectionSummaries = state.hiddenCollectionSummaries;
|
||||
|
||||
@@ -746,10 +742,6 @@ export default function Gallery() {
|
||||
};
|
||||
}, [selectAll, clearSelection]);
|
||||
|
||||
const fileToCollectionsMap = useMemoSingleThreaded(() => {
|
||||
return constructFileToCollectionMap(files);
|
||||
}, [files]);
|
||||
|
||||
const showSessionExpiredMessage = () => {
|
||||
setDialogMessage(getSessionExpiredMessage(logout));
|
||||
};
|
||||
|
||||
@@ -517,17 +517,6 @@ export function getIDBasedSortedFiles(files: EnteFile[]) {
|
||||
return files.sort((a, b) => a.id - b.id);
|
||||
}
|
||||
|
||||
export function constructFileToCollectionMap(files: EnteFile[]) {
|
||||
const fileToCollectionsMap = new Map<number, number[]>();
|
||||
(files ?? []).forEach((file) => {
|
||||
if (!fileToCollectionsMap.get(file.id)) {
|
||||
fileToCollectionsMap.set(file.id, []);
|
||||
}
|
||||
fileToCollectionsMap.get(file.id).push(file.collectionID);
|
||||
});
|
||||
return fileToCollectionsMap;
|
||||
}
|
||||
|
||||
export const shouldShowAvatar = (file: EnteFile, user: User) => {
|
||||
if (!file || !user) {
|
||||
return false;
|
||||
|
||||
@@ -29,6 +29,7 @@ import type {
|
||||
CollectionSummaryType,
|
||||
} from "../../services/collection/ui";
|
||||
import {
|
||||
createFileCollectionIDs,
|
||||
getLatestVersionFiles,
|
||||
groupFilesByCollectionID,
|
||||
} from "../../services/file";
|
||||
@@ -119,6 +120,10 @@ export interface GalleryState {
|
||||
* collections.
|
||||
*/
|
||||
allCollectionNameByID: Map<number, string>;
|
||||
/**
|
||||
* A list of collection IDs to which a file belongs, indexed by file ID.
|
||||
*/
|
||||
fileCollectionIDs: Map<number, number[]>;
|
||||
|
||||
/*--< Derived UI state >--*/
|
||||
|
||||
@@ -194,6 +199,7 @@ const initialGalleryState: GalleryState = {
|
||||
hiddenFileIDs: new Set(),
|
||||
favoriteFileIDs: new Set(),
|
||||
allCollectionNameByID: new Map(),
|
||||
fileCollectionIDs: new Map(),
|
||||
collectionSummaries: new Map(),
|
||||
hiddenCollectionSummaries: new Map(),
|
||||
filteredData: [],
|
||||
@@ -236,6 +242,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
|
||||
allCollectionNameByID: createCollectionNameByID(
|
||||
action.allCollections,
|
||||
),
|
||||
fileCollectionIDs: createFileCollectionIDs(action.files),
|
||||
collectionSummaries: deriveCollectionSummaries(
|
||||
action.user,
|
||||
collections,
|
||||
@@ -323,6 +330,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
|
||||
state.collections,
|
||||
files,
|
||||
),
|
||||
fileCollectionIDs: createFileCollectionIDs(action.files),
|
||||
collectionSummaries: deriveCollectionSummaries(
|
||||
ensure(state.user),
|
||||
state.collections,
|
||||
@@ -345,6 +353,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
|
||||
state.collections,
|
||||
files,
|
||||
),
|
||||
fileCollectionIDs: createFileCollectionIDs(action.files),
|
||||
collectionSummaries: deriveCollectionSummaries(
|
||||
ensure(state.user),
|
||||
state.collections,
|
||||
@@ -363,6 +372,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
|
||||
state.collections,
|
||||
files,
|
||||
),
|
||||
fileCollectionIDs: createFileCollectionIDs(files),
|
||||
// TODO: Consider batching this instead of doing it per file
|
||||
// upload to speed up uploads. Perf test first though.
|
||||
collectionSummaries: deriveCollectionSummaries(
|
||||
|
||||
@@ -14,6 +14,19 @@ export const groupFilesByCollectionID = (files: EnteFile[]) =>
|
||||
return result;
|
||||
}, new Map<number, EnteFile[]>());
|
||||
|
||||
/**
|
||||
* Construct a map from file IDs to the list of collections (IDs) to which the
|
||||
* file belongs.
|
||||
*/
|
||||
export const createFileCollectionIDs = (files: EnteFile[]) =>
|
||||
files.reduce((result, file) => {
|
||||
const id = file.id;
|
||||
let fs = result.get(id);
|
||||
if (!fs) result.set(id, (fs = []));
|
||||
fs.push(file.collectionID);
|
||||
return result;
|
||||
}, new Map<number, number[]>());
|
||||
|
||||
export function getLatestVersionFiles(files: EnteFile[]) {
|
||||
const latestVersionFiles = new Map<string, EnteFile>();
|
||||
files.forEach((file) => {
|
||||
|
||||
Reference in New Issue
Block a user