Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Remove map dialog from public albums

Anand Baburajanf473bd4a6b59
diff --git a/web/apps/albums/vendor/photos/components/Collections/CollectionMapDialog.tsx b/web/apps/albums/vendor/photos/components/Collections/CollectionMapDialog.tsx
deleted file mode 100644
index 94f083205f..0000000000
--- a/web/apps/albums/vendor/photos/components/Collections/CollectionMapDialog.tsx
+++ /dev/null
@@ -1,2634 +0,0 @@
-import AddIcon from "@mui/icons-material/Add";
-import CloseIcon from "@mui/icons-material/Close";
-import LocationOnIcon from "@mui/icons-material/LocationOn";
-import RemoveIcon from "@mui/icons-material/Remove";
-import {
- Box,
- Dialog,
- DialogContent,
- IconButton,
- Stack,
- styled,
- Typography,
- useMediaQuery,
- type IconButtonProps,
-} from "@mui/material";
-import { useTheme } from "@mui/material/styles";
-import { ensureLocalUser } from "ente-accounts/services/user";
-import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";
-import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
-import { useBaseContext } from "ente-base/context";
-import { downloadManager } from "ente-gallery/services/download";
-import { uniqueFilesByID } from "ente-gallery/utils/file";
-import { type Collection } from "ente-media/collection";
-import { type EnteFile } from "ente-media/file";
-import {
- fileCreationTime,
- fileLocation,
- ItemVisibility,
-} from "ente-media/file-metadata";
-import type { RemotePullOpts } from "ente-new/photos/components/gallery";
-import {
- addToFavoritesCollection,
- isArchivedCollection,
- isHiddenCollection,
- removeFromFavoritesCollection,
-} from "ente-new/photos/services/collection";
-import { type CollectionSummary } from "ente-new/photos/services/collection-summary";
-import { updateFilesVisibility } from "ente-new/photos/services/file";
-import {
- savedCollectionFiles,
- savedCollections,
-} from "ente-new/photos/services/photos-fdb";
-import { t } from "i18next";
-import "leaflet/dist/leaflet.css";
-import type { Dispatch, SetStateAction } from "react";
-import React, {
- startTransition,
- useCallback,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from "react";
-import Supercluster from "supercluster";
-import type { SelectedState } from "utils/file";
-import type { FileListWithViewerProps } from "../FileListWithViewer";
-import { FileListWithViewer } from "../FileListWithViewer";
-import { calculateOptimalZoom } from "../TripLayout/mapHelpers";
-import type { JourneyPoint } from "../TripLayout/types";
-
-interface CollectionMapDialogProps
- extends ModalVisibilityProps,
- Pick<
- FileListWithViewerProps,
- | "onAddSaveGroup"
- | "onMarkTempDeleted"
- | "onAddFileToCollection"
- | "onRemoteFilesPull"
- | "onVisualFeedback"
- | "fileNormalCollectionIDs"
- | "collectionNameByID"
- | "onSelectCollection"
- | "onSelectPerson"
- > {
- collectionSummary: CollectionSummary;
- activeCollection: Collection | undefined;
- onRemotePull?: (opts?: RemotePullOpts) => Promise<void>;
-}
-
-// Describes all map-related state used in the dialog:
-// - mapCenter: current map center, typically derived from the latest file with location
-// - mapIndex/mapPoints/latestFileId: spatial index and its source points, plus the newest file id
-// - filesByID/thumbByFileID: cached file metadata and lazily-fetched thumbnails
-// - isLoading/error: loading/error flags for map data fetches
-
-interface MapDataState {
- mapCenter: [number, number] | null;
- mapIndex: MapIndex | null;
- mapPoints: MapIndexPoint[];
- latestFileId: number | undefined;
- filesByID: Map<number, EnteFile>;
- thumbByFileID: Map<number, string>;
- isLoading: boolean;
- error: string | null;
-}
-
-/**
- * When files are being opened from the the Sidebar, there is ablity to add them as favoriate,
- * archive them or unarchieve them and this interface is for facilitating that. Where the favoruteFileIds
- * hols the existing favorites, pending holds the ones which are in progress for respective ones
- */
-
-interface FavoritesState {
- favoriteFileIDs: Set<number>;
- pendingFavoriteUpdates: Set<number>;
- pendingVisibilityUpdates: Set<number>;
-}
-
-/**
- * Extension of MapDataState that adds mutation functions for map data management.
- * - removeFiles: Removes files from the map index when deleted from FileListWithViewer
- * - updateFileVisibility: Updates file visibility state and removes hidden files from the map
- * - queueThumbnailFetch: Batches and fetches thumbnails on demand for visible files
- */
-
-interface MapDataResult extends MapDataState {
- removeFiles: (fileIDs: number[]) => void;
- updateFileVisibility: (file: EnteFile, visibility: ItemVisibility) => void;
- queueThumbnailFetch: (fileIDs: number[]) => void;
-}
-
-/**
- * Dynamically loaded map components to avoid SSR issues with Leaflet. Normal imports actually caused
- * the app to break in some instances, thus dynamically loading them instead.
- * Loaded lazily in useMapComponents() hook when the dialog opens to ensure window exists.
- */
-interface MapComponents {
- MapContainer: typeof import("react-leaflet").MapContainer;
- TileLayer: typeof import("react-leaflet").TileLayer;
- Marker: typeof import("react-leaflet").Marker;
- useMap: typeof import("react-leaflet").useMap;
-}
-
-/**
- * Represents a geotagged photo point stored in the map spatial index.
- * Each point corresponds to a photo with location metadata.
- * - fileId: Unique identifier for the photo file
- * - lat: Latitude coordinate of the photo location
- * - lng: Longitude coordinate of the photo location
- * - timestamp: Unix timestamp (milliseconds) of when the photo was created
- */
-
-interface MapIndexPoint {
- fileId: number;
- lat: number;
- lng: number;
- timestamp: number;
-}
-
-/**
- * Along with the GeoTagged photos we are also storing a metadata, which changes
- * only when there is change in the stored values, to prevent this from updating
- * each time when there is change. Currently fileCount and updationTime are the
- * two metrics kept to analyse this change.
- */
-
-/**
- * The small payload we attach to a point: fileId points to the photo, and timestamp keeps
- * enough context for sorting or choosing the freshest item in a cluster.
- */
-interface MapPointProperties {
- fileId: number;
- timestamp: number;
-}
-
-/**
- * A GeoJSON feature for a single photo point. GeoJSON is the small, common shape most map
- * libraries expect for geographic data, so we stick with it even when we only need a
- * couple of fields. type stays "Feature" because that is the GeoJSON spec's envelope for
- * real-world points; it does not change our logic, but it keeps the data recognizable to
- * tooling like Supercluster. properties carry the fileId and timestamp (and keep cluster
- * as false), and geometry stores the point in [lng, lat] order for map libs.
- */
-interface MapPointFeature {
- type: "Feature";
- properties: MapPointProperties & { cluster?: false };
- geometry: { type: "Point"; coordinates: [number, number] };
-}
-
-/**
- * Summary info for a cluster: latestTimestamp and latestFileId keep track of the freshest
- * photo inside the cluster so we can choose a representative cover.
- */
-interface MapClusterProperties {
- latestTimestamp: number;
- latestFileId: number;
-}
-
-/**
- * A GeoJSON feature that represents a cluster instead of a single point. properties mark
- * it as a cluster, carry cluster_id for expansion, point_count for the raw size, and
- * point_count_abbreviated for a compact label, while geometry still gives the centroid.
- */
-interface MapClusterFeature {
- type: "Feature";
- properties: MapClusterProperties & {
- cluster: true;
- cluster_id: number;
- point_count: number;
- point_count_abbreviated?: number | string;
- };
- geometry: { type: "Point"; coordinates: [number, number] };
-}
-
-/**
- * Convenience union so callers can handle clusters and single points together.
- */
-type MapFeature = MapClusterFeature | MapPointFeature;
-
-/**
- * The small contract we rely on from Supercluster: load ingests points, getClusters
- * returns mixed clusters/points for bounds and zoom, getLeaves expands a cluster into
- * its points, and getClusterExpansionZoom tells us how far to zoom to break it apart.
- */
-interface MapIndex {
- load(points: MapPointFeature[]): MapIndex;
- getClusters(
- bbox: [number, number, number, number],
- zoom: number,
- ): MapFeature[];
- getLeaves(
- clusterId: number,
- limit: number,
- offset: number,
- ): MapPointFeature[];
- getClusterExpansionZoom(clusterId: number): number;
-}
-
-/**
- * Tuning knobs for building the index: radius controls cluster size in pixels, maxZoom
- * caps clustering depth, map shapes point data into the cluster properties we track,
- * and reduce merges those properties as clusters grow.
- */
-interface MapClusterOptions {
- radius?: number;
- maxZoom?: number;
- map?: (props: MapPointProperties) => MapClusterProperties;
- reduce?: (
- accumulated: MapClusterProperties,
- props: MapClusterProperties,
- ) => void;
-}
-
-type SuperclusterConstructor = new (options?: MapClusterOptions) => MapIndex;
-
-//OpenStreetMap only supports clustering till this zoom level and this tell the supercluster what the max limit is for the zoom.
-const MAX_MAP_ZOOM = 19;
-//Instead of loading just the tiles which are in view, we're actually loading the 15% of the surrounding zone as well for smoother experience.
-//Leaflet LatLngBounds.pad expects a ratio (0.15 = 15%).
-const PREFETCH_BOUNDS_PADDING = 0.15;
-//This count controls how many thumbnails are fetched in each batch when loading images for the markers
-const THUMBNAIL_BATCH_SIZE = 40;
-
-/**
- * This is the first hook which is being loaded when the CollectionMapDialog is mounted
- * Dynamically loads map-related React components (Leaflet) to avoid SSR issues
- * Responsibility: Lazy load map dependencies only when needed (window must exist)
- */
-function useMapComponents() {
- const [mapComponents, setMapComponents] = useState<MapComponents | null>(
- null,
- );
-
- useEffect(() => {
- // Only load on client-side where window exists, and updates the state with the components.
- if (typeof window === "undefined") return;
-
- void import("react-leaflet")
- .then((leaflet) =>
- setMapComponents({
- MapContainer: leaflet.MapContainer,
- TileLayer: leaflet.TileLayer,
- Marker: leaflet.Marker,
- useMap: leaflet.useMap,
- }),
- )
- .catch((e: unknown) => {
- console.error("Failed to load map components", e);
- });
- }, []);
-
- return mapComponents;
-}
-
-/**
- * Retrieves the current authenticated user data and throws error if the user is not loggedIn.
- * Responsibility: Provide user context for favorite/visibility operations
- */
-function useCurrentUser() {
- return useMemo(() => {
- try {
- return ensureLocalUser();
- } catch {
- return undefined;
- }
- }, []);
-}
-
-/**
- *
- * @param files
- * @returns points, latestFileId
- *
- * This function create the inital mapIndexPoint any collection.
- * It's later this points
- * that is being given to the supercluster for the mapping and indexing.
- *
- * This function loops over the entire files which is suspect is not EFFICENT
- * but currently it loads about 1,00,000 images seamlessly which is far better
- * than the earlier implementation we had.
- */
-const buildMapIndexPoints = async (files: EnteFile[]) => {
- const points: MapIndexPoint[] = [];
- let latestTimestamp = -1;
- let latestFileId: number | undefined;
-
- //looping over each file to extract their time and location to create the point
- for (let index = 0; index < files.length; index += 1) {
- const file = files[index];
- if (!file) continue;
- const loc = fileLocation(file);
- if (!loc) continue;
-
- const timestamp = fileCreationTime(file);
- points.push({
- fileId: file.id,
- lat: loc.latitude,
- lng: loc.longitude,
- timestamp,
- });
-
- if (timestamp > latestTimestamp) {
- latestTimestamp = timestamp;
- latestFileId = file.id;
- }
-
- /**
- * This pauses the event loop briefly, so the main thead is not blocked if there are mutliple so many files.
- * This doesn't change the complexisty of this loop, just keep the thread responsive for UI updates, input and rendering.
- */
-
- if (index > 0 && index % 5000 === 0) {
- await new Promise((resolve) => setTimeout(resolve, 0));
- }
- }
-
- return { points, latestFileId };
-};
-
-/**
- *
- * @param points
- * @returns a SuperCluster Spatial Index, using which we can retrive (1)the clusters/points for a particular bbox + zoom level
- * (2) all leaves under a cluster. (3) the maximum zoom for a particular cluster
- *
- * This function converts every MapIndexPoint to a GeoJSON Feature(required for rendering
- * using supercluster)[type MapPointFeature]. NOTE this index is not persisted.
- */
-const buildClusterIndex = (points: MapIndexPoint[]): MapIndex => {
- /**
- * - For every point we load, Supercluster calls map(props) once to decide what
- * cluster metadata that point contributes.
- *
- * - When multiple points are to begrouped into a cluster, Supercluster repeatedly calls
- * reduce(accumulated, props) to merge those per‑point metadata objects into a single cluster summary.
- */
-
- const options: MapClusterOptions = {
- radius: 80,
- maxZoom: MAX_MAP_ZOOM,
- map: (props) => ({
- latestTimestamp: props.timestamp,
- latestFileId: props.fileId,
- }),
- reduce: (accumulated, props) => {
- if (props.latestTimestamp > accumulated.latestTimestamp) {
- accumulated.latestTimestamp = props.latestTimestamp;
- accumulated.latestFileId = props.latestFileId;
- }
- },
- };
-
- const SuperclusterCtor = Supercluster as unknown as SuperclusterConstructor;
- const index = new SuperclusterCtor(options);
-
- // converting MapIndexPoint -> MapPointFeature
- const features: MapPointFeature[] = points.map((point) => ({
- type: "Feature" as const,
- properties: { fileId: point.fileId, timestamp: point.timestamp },
- geometry: {
- type: "Point" as const,
- coordinates: [point.lng, point.lat] as [number, number],
- },
- }));
-
- //builds the spaital cluster hierachy across various zoom level
- index.load(features);
- return index;
-};
-
-const buildMapIndex = (points: MapIndexPoint[]) =>
- points.length > 0 ? buildClusterIndex(points) : null;
-
-const getPointByFileId = (
- points: MapIndexPoint[],
- fileId: number | undefined,
-) => {
- if (fileId === undefined) return undefined;
- return points.find((point) => point.fileId === fileId);
-};
-
-/**
- *
- * @param points
- * @returns MapIndexPoint
- *
- * Though we are computing the latestFile while loadMapData(), sometimes
- * if this latestFile is deleted or archieved by the user then we need
- * to compute a new latestFile, this is the purpose this fn serves.
- */
-const getLatestPointByTimestamp = (
- points: MapIndexPoint[],
-): MapIndexPoint | undefined => {
- let latest: MapIndexPoint | undefined;
- for (const point of points) {
- if (!latest || point.timestamp > latest.timestamp) {
- latest = point;
- }
- }
- return latest;
-};
-
-const getLatestFileIdFromPoints = (points: MapIndexPoint[]) =>
- getLatestPointByTimestamp(points)?.fileId;
-
-/**
- * Loads and manages map data including index, files, and thumbnails.
- * Responsibility: Fetch collection files, build/persist spatial index, prefetch thumbnails on demand.
- */
-function useMapData(
- open: boolean,
- collectionSummary: CollectionSummary,
- activeCollection: Collection | undefined,
- onGenericError: (e: unknown) => void,
-): MapDataResult {
- const [state, setState] = useState<MapDataState>({
- mapCenter: null,
- mapIndex: null,
- mapPoints: [],
- latestFileId: undefined,
- filesByID: new Map(),
- thumbByFileID: new Map(),
- isLoading: false,
- error: null,
- });
-
- //Ref mirroring the filesByID(state) to prevent the stale closure issue with the queueThumbnailFetch useCallback fn().
- const filesByIDRef = useRef<Map<number, EnteFile>>(new Map());
- //Ref mirroring the thumbByFileID state to prevent the same issue as above
- const thumbsByFileIDRef = useRef<Map<number, string>>(new Map());
- //A work queue with the list of fileIDs waiting to have their thumbs fetched.
- const pendingThumbsRef = useRef<Set<number>>(new Set());
- const isThumbnailWorkerRunningRef = useRef(false);
-
- // Track which collection we've loaded to avoid unnecessary reloads
- // Include fileCount to detect when collection content changes
- const loadedCollectionRef = useRef<{
- summaryId: number;
- collectionId: number | undefined;
- fileCount: number;
- updationTime: number | null;
- } | null>(null);
-
- //Syncing the refs with the state for the stale closure prevention.
- useEffect(() => {
- filesByIDRef.current = state.filesByID;
- }, [state.filesByID]);
-
- useEffect(() => {
- thumbsByFileIDRef.current = state.thumbByFileID;
- }, [state.thumbByFileID]);
-
- const queueThumbnailFetch = useCallback((fileIDs: number[]) => {
- if (!fileIDs.length) return;
-
- const pending = pendingThumbsRef.current;
- const existingThumbs = thumbsByFileIDRef.current;
- const filesByID = filesByIDRef.current;
-
- /**
- * Loops through the fileIds for which thumbnails are to fetched,
- * and if thumbs are already generated or that fileId doesn't exist
- * then skipping it.
- *
- * Otherwise adding it to the ref for the fetching process
- */
- for (const fileId of fileIDs) {
- if (existingThumbs.has(fileId)) continue;
- if (!filesByID.has(fileId)) continue;
- pending.add(fileId);
- }
-
- if (isThumbnailWorkerRunningRef.current) return;
- isThumbnailWorkerRunningRef.current = true;
-
- void (async () => {
- while (pendingThumbsRef.current.size > 0) {
- /**
- * Since we're fetching in a batched manner, slicing the THUMBNAIL_BATCH_SIZE for fetching and
- * removing these from the pending list.
- */
-
- const batchIds = Array.from(pendingThumbsRef.current).slice(
- 0,
- THUMBNAIL_BATCH_SIZE,
- );
- batchIds.forEach((id) => pendingThumbsRef.current.delete(id));
-
- const entries = await Promise.all(
- batchIds.map(async (fileId) => {
- const file = filesByIDRef.current.get(fileId);
- if (!file) return [fileId, undefined] as const;
- try {
- const thumb =
- await downloadManager.renderableThumbnailURL(
- file,
- );
- return [fileId, thumb] as const;
- } catch {
- return [fileId, undefined] as const;
- }
- }),
- );
-
- /**
- * Updating the existing state with the newly fetched thumbnails.
- */
- setState((prev) => {
- const updatedThumbMap = new Map(prev.thumbByFileID);
- entries.forEach(([fileId, thumbnailUrl]) => {
- if (!thumbnailUrl || updatedThumbMap.has(fileId))
- return;
- updatedThumbMap.set(fileId, thumbnailUrl);
- });
- return updatedThumbMap.size > prev.thumbByFileID.size
- ? { ...prev, thumbByFileID: updatedThumbMap }
- : prev;
- });
-
- //To yield control between batches os the UI stays responsive
- await new Promise((resolve) => setTimeout(resolve, 0));
- }
-
- isThumbnailWorkerRunningRef.current = false;
- })();
- }, []);
-
- // Clear loaded ref when dialog closes so we reload fresh data next time.
- useEffect(() => {
- if (!open) {
- loadedCollectionRef.current = null;
- pendingThumbsRef.current.clear();
- isThumbnailWorkerRunningRef.current = false;
- }
- }, [open]);
-
- useEffect(() => {
- if (!open) return;
-
- // Skip reload if we already have data for this collection with same file count
- const currentSummaryId = collectionSummary.id;
- const currentCollectionId = activeCollection?.id;
- const currentFileCount = collectionSummary.fileCount;
- const currentUpdationTime = collectionSummary.updationTime ?? null;
- const loaded = loadedCollectionRef.current;
-
- //preventing reloading of the data if it's already loaded.
- if (
- loaded &&
- loaded.summaryId === currentSummaryId &&
- loaded.collectionId === currentCollectionId &&
- loaded.fileCount === currentFileCount &&
- loaded.updationTime === currentUpdationTime
- ) {
- return;
- }
-
- const loadMapData = async () => {
- //In this ref we are actually setting a new Set() so clearing that before any compute happens.
- pendingThumbsRef.current.clear();
- setState((prev) => ({ ...prev, isLoading: true, error: null }));
-
- try {
- const files = await getFilesForCollection(
- collectionSummary,
- activeCollection,
- );
-
- //Creating a id <- file mapping to drive renders and update the UI, changes to this will result in UI re-renders
- const filesByID = new Map(files.map((file) => [file.id, file]));
- //ref mirrow for using in the useCallbacks
- filesByIDRef.current = filesByID;
-
- const { points, latestFileId } =
- await buildMapIndexPoints(files);
-
- //mapIndex has the SuperCluster Spatial Index
- const mapIndex = buildMapIndex(points);
-
- const latestPoint =
- getPointByFileId(points, latestFileId) ?? points[0];
-
- const mapCenter: [number, number] | null = latestPoint
- ? [latestPoint.lat, latestPoint.lng]
- : null;
-
- setState({
- filesByID,
- mapCenter,
- mapIndex,
- mapPoints: points,
- latestFileId,
- thumbByFileID: new Map(),
- isLoading: false,
- error: null,
- });
-
- // Mark this collection as loaded
- loadedCollectionRef.current = {
- summaryId: currentSummaryId,
- collectionId: currentCollectionId,
- fileCount: currentFileCount,
- updationTime: currentUpdationTime,
- };
-
- const coverId = collectionSummary.coverFile?.id ?? latestFileId;
- if (coverId !== undefined) {
- queueThumbnailFetch([coverId]);
- }
-
- return;
- } catch (e) {
- setState((prev) => ({
- ...prev,
- isLoading: false,
- error: t("something_went_wrong"),
- }));
- onGenericError(e);
- } finally {
- // Ensure we never leave the dialog stuck in a loading state
- setState((prev) =>
- prev.isLoading ? { ...prev, isLoading: false } : prev,
- );
- }
- };
-
- void loadMapData();
- }, [
- open,
- collectionSummary,
- activeCollection,
- onGenericError,
- queueThumbnailFetch,
- ]);
-
- /**
- * This function is used to update the map view, after a file has been
- * deleted by the user. The deleted file is removed from the mapPoints
- * and then a new mapIndex is built
- */
- const removeFiles = useCallback((fileIDs: number[]) => {
- if (!fileIDs.length) return;
- setState((prev) => {
- const ids = new Set(fileIDs);
- const filesByID = new Map(prev.filesByID);
- const thumbByFileID = new Map(prev.thumbByFileID);
- ids.forEach((id) => {
- filesByID.delete(id);
- thumbByFileID.delete(id);
- });
- const mapPoints = prev.mapPoints.filter(
- (point) => !ids.has(point.fileId),
- );
- //Rebuilding the mapIndex after removing the point from the mapPoints
- const mapIndex = buildMapIndex(mapPoints);
-
- let latestFileId = prev.latestFileId;
- if (latestFileId && ids.has(latestFileId)) {
- latestFileId = getLatestFileIdFromPoints(mapPoints);
- }
- return {
- ...prev,
- filesByID,
- thumbByFileID,
- mapIndex,
- mapPoints,
- latestFileId,
- mapCenter: mapPoints.length ? prev.mapCenter : null,
- };
- });
- }, []);
-
- /**
- * This function is used to update the visiblity of a file from
- * archive to unarchive or vice-versa.
- */
- const updateFileVisibility = useCallback(
- (file: EnteFile, visibility: ItemVisibility) => {
- setState((prev) => {
- //If the file ID is not in the fileByID or the magicMetadata for the file doesn't exist then return prev state
- if (!prev.filesByID.has(file.id)) return prev;
- if (!file.magicMetadata) return prev;
-
- const updatedMagicMetadata = {
- ...file.magicMetadata,
- data: { ...file.magicMetadata.data, visibility },
- };
-
- const updatedFile: EnteFile = {
- ...file,
- magicMetadata: updatedMagicMetadata,
- };
- const filesByID = new Map(prev.filesByID);
- filesByID.set(file.id, updatedFile);
-
- let mapPoints = prev.mapPoints;
- let mapIndex = prev.mapIndex;
- let latestFileId = prev.latestFileId;
-
- //If the file is not visible then removing it from the mapPoints and creating a new Supercluster Spatial Mapping
- if (visibility !== ItemVisibility.visible) {
- const filtered = prev.mapPoints.filter(
- (point) => point.fileId !== file.id,
- );
- if (filtered.length !== prev.mapPoints.length) {
- mapPoints = filtered;
- mapIndex = buildMapIndex(mapPoints);
- if (latestFileId === file.id) {
- latestFileId = getLatestFileIdFromPoints(mapPoints);
- }
- }
- } else if (!prev.mapPoints.some((p) => p.fileId === file.id)) {
- //If the file was previously hidden then adding it back to the existing list.
- const loc = fileLocation(file);
- if (loc) {
- const timestamp = fileCreationTime(file);
- mapPoints = [
- ...prev.mapPoints,
- {
- fileId: file.id,
- lat: loc.latitude,
- lng: loc.longitude,
- timestamp,
- },
- ];
-
- //Recomputing the latest file, since there are possiblities of change
- mapIndex = buildMapIndex(mapPoints);
- const latestPoint =
- latestFileId !== undefined
- ? getPointByFileId(prev.mapPoints, latestFileId)
- : undefined;
- if (!latestPoint || timestamp > latestPoint.timestamp) {
- latestFileId = file.id;
- }
- }
- }
-
- //Recomputing the map center in case the latestFile has changed.
- let mapCenter = prev.mapCenter;
- if (!mapPoints.length) {
- mapCenter = null;
- } else if (!mapCenter) {
- const centerPoint =
- latestFileId !== undefined
- ? mapPoints.find(
- (point) => point.fileId === latestFileId,
- )
- : mapPoints[0];
- if (centerPoint) {
- mapCenter = [centerPoint.lat, centerPoint.lng];
- }
- }
-
- return {
- ...prev,
- filesByID,
- mapPoints,
- mapIndex,
- latestFileId,
- mapCenter,
- };
- });
- },
- [],
- );
-
- return { ...state, removeFiles, updateFileVisibility, queueThumbnailFetch };
-}
-
-/**
- * Manages favorite files state and handles favorite/visibility updates
- * Responsibility: Load user's favorites, toggle favorite status, update file visibility
- */
-function useFavorites(
- open: boolean,
- user: ReturnType<typeof useCurrentUser>,
-): FavoritesState & {
- handleToggleFavorite: (file: EnteFile) => Promise<void>;
- handleFileVisibilityUpdate: (
- file: EnteFile,
- visibility: ItemVisibility,
- ) => Promise<void>;
-} {
- //Set to store the ids of files which are currenly favorited
- const [favoriteFileIDs, setFavoriteFileIDs] = useState<Set<number>>(
- new Set(),
- );
- //Set to store the IDs of the files which are in-flight for updation(favorite/unfavorite)
- const [pendingFavoriteUpdates, setPendingFavoriteUpdates] = useState<
- Set<number>
- >(new Set());
- //Set to store the IDs of the files which are in-flight for updation(archive/unarchive)
- const [pendingVisibilityUpdates, setPendingVisibilityUpdates] = useState<
- Set<number>
- >(new Set());
-
- useEffect(() => {
- if (!open || !user) return;
-
- /**
- * Each collectionFile has a collectionID associated with them, checking whether
- * that id matches with the id of each collectionFiles and if so then adding it to the
- * favoriteFileIDs.
- */
- const loadFavorites = async () => {
- const collections = await savedCollections();
- const collectionFiles = await savedCollectionFiles();
-
- for (const collection of collections) {
- if (
- collection.type === "favorites" &&
- collection.owner.id === user.id
- ) {
- const favoriteIDs = new Set(
- collectionFiles
- .filter((f) => f.collectionID === collection.id)
- .map((f) => f.id),
- );
- setFavoriteFileIDs(favoriteIDs);
- break;
- }
- }
- };
-
- void loadFavorites();
- }, [open, user]);
-
- // Helper to add/remove from Set immutably - avoids recreating Set when unnecessary
- const addToSet = useCallback((set: Set<number>, id: number) => {
- if (set.has(id)) return set;
- const next = new Set(set);
- next.add(id);
- return next;
- }, []);
-
- const removeFromSet = useCallback((set: Set<number>, id: number) => {
- if (!set.has(id)) return set;
- const next = new Set(set);
- next.delete(id);
- return next;
- }, []);
-
- const handleToggleFavorite = useCallback(
- async (file: EnteFile) => {
- if (!user) return;
- const fileID = file.id;
-
- // Check favorite status at call time to avoid stale closure
- const isFavorite = favoriteFileIDs.has(fileID);
-
- setPendingFavoriteUpdates((prev) => addToSet(prev, fileID));
- try {
- const action = isFavorite
- ? removeFromFavoritesCollection
- : addToFavoritesCollection;
- await action([file]);
- setFavoriteFileIDs((prev) =>
- isFavorite
- ? removeFromSet(prev, fileID)
- : addToSet(prev, fileID),
- );
- } finally {
- setPendingFavoriteUpdates((prev) =>
- removeFromSet(prev, fileID),
- );
- }
- },
- [user, favoriteFileIDs, addToSet, removeFromSet],
- );
-
- const handleFileVisibilityUpdate = useCallback(
- async (file: EnteFile, visibility: ItemVisibility) => {
- const fileID = file.id;
- setPendingVisibilityUpdates((prev) => addToSet(prev, fileID));
- try {
- await updateFilesVisibility([file], visibility);
- } finally {
- setPendingVisibilityUpdates((prev) =>
- removeFromSet(prev, fileID),
- );
- }
- },
- [addToSet, removeFromSet],
- );
-
- return {
- favoriteFileIDs,
- pendingFavoriteUpdates,
- pendingVisibilityUpdates,
- handleToggleFavorite,
- handleFileVisibilityUpdate,
- };
-}
-
-/**
- * Manages the lifecycle of the currently visible journey photos.
- *
- * Tracks the ordered list of visible photos and exposes a setter to update them.
- * It's the visiblePhotos that are being shown in the Sidebar to the left of the map
- *
- * @returns An object containing the visible photos array and setter.
- */
-function useVisiblePhotos() {
- const [visiblePhotos, setVisiblePhotos] = useState<JourneyPoint[]>([]);
- const [isVisiblePhotosUpdating, setIsVisiblePhotosUpdating] =
- useState(false);
-
- return {
- visiblePhotos,
- setVisiblePhotos,
- isVisiblePhotosUpdating,
- setIsVisiblePhotosUpdating,
- };
-}
-
-/**
- * Creates a marker icon for individual photos (no badge)
- * Used only in CollectionMapDialog for consistent styling
- */
-function createMarkerIcon(
- imageSrc: string,
- size: number,
-): import("leaflet").DivIcon | null {
- if (typeof window === "undefined") return null;
-
- // eslint-disable-next-line @typescript-eslint/no-require-imports
- const leaflet = require("leaflet") as typeof import("leaflet");
-
- const pinSize = size + 16; // Add padding for consistent sizing with TripLayout
- const triangleHeight = 10;
- const pinHeight = pinSize + triangleHeight + 2;
- const hasImage = imageSrc && imageSrc.trim() !== "";
-
- // Border radius matching TripLayout style
- const outerBorderRadius = 16;
- const innerBorderRadius = 12;
-
- return leaflet.divIcon({
- html: `
- <div class="photo-pin" style="
- width: ${pinSize}px;
- height: ${pinHeight}px;
- position: relative;
- cursor: pointer;
- transition: all 0.3s ease;
- filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
- ">
- <div style="
- width: ${pinSize}px;
- height: ${pinSize}px;
- border-radius: ${outerBorderRadius}px;
- background: white;
- border: 2px solid #ffffff;
- padding: 4px;
- position: relative;
- overflow: hidden;
- transition: background-color 0.3s ease, border-color 0.3s ease;
- "
- onmouseover="this.style.background='#22c55e'; this.style.borderColor='#22c55e'; this.nextElementSibling.style.borderTopColor='#22c55e';"
- onmouseout="this.style.background='white'; this.style.borderColor='#ffffff'; this.nextElementSibling.style.borderTopColor='white';"
- >
- ${
- hasImage
- ? `<img src="${imageSrc}" style="width:100%;height:100%;object-fit:cover;border-radius:${innerBorderRadius}px;" alt="Location" />`
- : `<div style="width:100%;height:100%;border-radius:${innerBorderRadius}px;animation:skeleton-pulse 1.5s ease-in-out infinite;"></div>
- <style>@keyframes skeleton-pulse{0%{background-color:#ffffff}50%{background-color:#f0f0f0}100%{background-color:#ffffff}}</style>`
- }
- </div>
- <div style="
- position: absolute;
- bottom: 2px;
- left: 50%;
- transform: translateX(-50%);
- width: 0;
- height: 0;
- border-left: ${triangleHeight}px solid transparent;
- border-right: ${triangleHeight}px solid transparent;
- border-top: ${triangleHeight}px solid white;
- transition: border-top-color 0.3s ease;
- "></div>
- </div>
- `,
- className: "collection-marker",
- iconSize: [pinSize, pinHeight],
- iconAnchor: [pinSize / 2, pinHeight],
- popupAnchor: [0, -pinHeight],
- });
-}
-
-/**
- * Creates a cluster icon with badge popping out of the container
- * Used only in CollectionMapDialog for cluster markers
- */
-function createClusterIcon(
- imageSrc: string,
- size: number,
- clusterCount: number,
- interactive = true,
-): import("leaflet").DivIcon | null {
- if (typeof window === "undefined") return null;
-
- // eslint-disable-next-line @typescript-eslint/no-require-imports
- const leaflet = require("leaflet") as typeof import("leaflet");
-
- const pinSize = size + 16; // Add padding for consistent sizing with TripLayout
- const triangleHeight = 10;
- const pinHeight = pinSize + triangleHeight + 2;
- const hasImage = imageSrc && imageSrc.trim() !== "";
- const badgeOverflow = 6;
-
- // Border radius matching TripLayout style
- const outerBorderRadius = 16;
- const innerBorderRadius = 12;
-
- const hoverHandlers = interactive
- ? "onmouseover=\"this.style.background='#22c55e'; this.style.borderColor='#22c55e'; this.parentElement.querySelector('.triangle').style.borderTopColor='#22c55e';\" onmouseout=\"this.style.background='white'; this.style.borderColor='#ffffff'; this.parentElement.querySelector('.triangle').style.borderTopColor='white';\""
- : "";
-
- const badgeLabel =
- clusterCount >= 2000
- ? `${Math.floor((clusterCount - 1) / 1000)}K+`
- : clusterCount >= 1000
- ? "1K+"
- : clusterCount > 999
- ? `${Math.floor(clusterCount / 100)}00+`
- : `${clusterCount}`;
-
- return leaflet.divIcon({
- html: `
- <div class="photo-pin" style="
- width: ${pinSize}px;
- height: ${pinHeight}px;
- position: relative;
- cursor: ${interactive ? "pointer" : "default"};
- transition: all 0.3s ease;
- overflow: visible;
- filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
- ">
- <div style="
- width: ${pinSize}px;
- height: ${pinSize}px;
- border-radius: ${outerBorderRadius}px;
- background: white;
- border: 2px solid #ffffff;
- padding: 4px;
- position: relative;
- overflow: hidden;
- transition: background-color 0.3s ease, border-color 0.3s ease;
- "
- ${hoverHandlers}
- >
- ${
- hasImage
- ? `<img src="${imageSrc}" style="width:100%;height:100%;object-fit:cover;border-radius:${innerBorderRadius}px;" alt="Location" />`
- : `<div style="width:100%;height:100%;border-radius:${innerBorderRadius}px;animation:skeleton-pulse 1.5s ease-in-out infinite;"></div>
- <style>@keyframes skeleton-pulse{0%{background-color:#ffffff}50%{background-color:#f0f0f0}100%{background-color:#ffffff}}</style>`
- }
- </div>
- <div style="
- position: absolute;
- top: -${badgeOverflow}px;
- right: -${badgeOverflow}px;
- background: #22c55e;
- color: #ffffff;
- border-radius: 7px;
- padding: 4px 7px;
- font-size: 12px;
- font-weight: 700;
- line-height: 1;
- box-shadow: 0 2px 6px rgba(0,0,0,0.2);
- z-index: 1;
- ">
- ${badgeLabel}
- </div>
- <style>
- .leaflet-marker-icon.collection-cluster-marker { overflow: visible !important; }
- </style>
- <div class="triangle" style="
- position: absolute;
- bottom: 2px;
- left: 50%;
- transform: translateX(-50%);
- width: 0;
- height: 0;
- border-left: ${triangleHeight}px solid transparent;
- border-right: ${triangleHeight}px solid transparent;
- border-top: ${triangleHeight}px solid white;
- transition: border-top-color 0.3s ease;
- "></div>
- </div>
- `,
- className: "collection-cluster-marker",
- iconSize: [pinSize + badgeOverflow, pinHeight + badgeOverflow],
- iconAnchor: [pinSize / 2, pinHeight],
- popupAnchor: [0, -pinHeight],
- });
-}
-
-// ============================================================================
-// Helper Functions
-// ============================================================================
-
-/**
- * Returns true if the file is visible (not archived or hidden).
- */
-function isFileVisible(file: EnteFile): boolean {
- const visibility = file.magicMetadata?.data.visibility;
- // Files without visibility metadata are considered visible (default state)
- return visibility === undefined || visibility === ItemVisibility.visible;
-}
-
-/**
- * Loads every locally stored file, filters those belonging to the
- * target collection, removes duplicates by ID, filters out hidden/archived
- * files, and returns the unique set of visible files. For "All", it also
- * excludes files that belong to hidden or archived collections.
- */
-async function getFilesForCollection(
- collectionSummary: CollectionSummary,
- activeCollection: Collection | undefined,
-): Promise<EnteFile[]> {
- if (collectionSummary.type === "all") {
- const [allFiles, collections] = await Promise.all([
- savedCollectionFiles(),
- savedCollections(),
- ]);
- // Filter out hidden and archived files to prevent leaking items users expect to remain hidden.
- const visibleFiles = allFiles.filter(isFileVisible);
- const hiddenCollectionIDs = new Set(
- collections
- .filter(isHiddenCollection)
- .map((collection) => collection.id),
- );
- const archivedCollectionIDs = new Set(
- collections
- .filter(isArchivedCollection)
- .map((collection) => collection.id),
- );
- const hiddenFileIDs = new Set(
- allFiles
- .filter((file) => hiddenCollectionIDs.has(file.collectionID))
- .map((file) => file.id),
- );
- const archivedFileIDs = new Set(
- allFiles
- .filter((file) => archivedCollectionIDs.has(file.collectionID))
- .map((file) => file.id),
- );
- const filtered = visibleFiles.filter(
- (file) =>
- !hiddenFileIDs.has(file.id) && !archivedFileIDs.has(file.id),
- );
- return uniqueFilesByID(filtered);
- }
- const allFiles = await savedCollectionFiles();
- // Filter out hidden and archived files to prevent leaking items users expect to remain hidden.
- const visibleFiles = allFiles.filter(isFileVisible);
- if (!activeCollection) {
- return [];
- }
- const filtered = visibleFiles.filter(
- (file) => file.collectionID === activeCollection.id,
- );
- return uniqueFilesByID(filtered);
-}
-
-// ============================================================================
-// Main Component
-// ============================================================================
-
-/**
- * Main dialog component that displays a collection's photos on an interactive map
- * Responsibility: Coordinate all hooks, manage dialog state, render map layout or loading states
- */
-export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
- open,
- onClose,
- collectionSummary,
- activeCollection,
- onRemotePull,
- onAddSaveGroup,
- onMarkTempDeleted,
- onAddFileToCollection,
- onRemoteFilesPull,
- onVisualFeedback,
- fileNormalCollectionIDs,
- collectionNameByID,
- onSelectCollection,
- onSelectPerson,
-}) => {
- const { onGenericError } = useBaseContext();
- const mapComponents = useMapComponents();
- const user = useCurrentUser();
- const [isFileViewerOpen, setIsFileViewerOpen] = useState(false);
- const optimalZoom = calculateOptimalZoom();
-
- const {
- mapCenter,
- mapIndex,
- mapPoints,
- latestFileId,
- filesByID,
- thumbByFileID,
- isLoading,
- error,
- removeFiles: removeFilesFromMap,
- updateFileVisibility,
- queueThumbnailFetch,
- } = useMapData(open, collectionSummary, activeCollection, onGenericError);
-
- const {
- visiblePhotos,
- setVisiblePhotos,
- isVisiblePhotosUpdating,
- setIsVisiblePhotosUpdating,
- } = useVisiblePhotos();
-
- const {
- favoriteFileIDs,
- pendingFavoriteUpdates,
- pendingVisibilityUpdates,
- handleToggleFavorite,
- handleFileVisibilityUpdate,
- } = useFavorites(open, user);
-
- useEffect(() => {
- if (!open) {
- setIsVisiblePhotosUpdating(false);
- }
- }, [open, setIsVisiblePhotosUpdating]);
-
- const handleSetFileViewerOpen: Dispatch<SetStateAction<boolean>> =
- useCallback(
- (next) => {
- const nextValue =
- typeof next === "function"
- ? (next as (prev: boolean) => boolean)(isFileViewerOpen)
- : next;
- setIsFileViewerOpen(nextValue);
- },
- [isFileViewerOpen],
- );
-
- // Convert visible JourneyPoints to EnteFiles for FileListWithViewer
- const visibleFiles = useMemo(() => {
- return visiblePhotos
- .map((p) => filesByID.get(p.fileId))
- .filter((f): f is EnteFile => f !== undefined);
- }, [visiblePhotos, filesByID]);
-
- const handleRemotePull = useCallback(
- () =>
- onRemotePull ? onRemotePull({ silent: true }) : Promise.resolve(),
- [onRemotePull],
- );
- const visualFeedback = useMemo(() => onVisualFeedback, [onVisualFeedback]);
-
- // Empty selection state since we don't support selection in map view
- const emptySelected = useMemo<SelectedState>(
- () => ({
- ownCount: 0,
- count: 0,
- context: undefined,
- collectionID: activeCollection?.id ?? collectionSummary.id,
- }),
- [activeCollection?.id, collectionSummary.id],
- );
-
- /**
- * Since the map view actually doesn't support the selecting from the sidebar
- * adding a empty function, other wise the setSelection must be made optional
- * which is a more system wide change and unncessary.
- */
- const noOpSetSelected = useCallback(() => {
- /* no-op */
- }, []);
-
- const handleMarkTempDeleted = useCallback(
- (files: EnteFile[]) => {
- //Triggering the gallery reducer's markTempDeleted
- onMarkTempDeleted?.(files);
-
- //remove the deleted files from the visible photos which are shown in the sidebar
- const idsToRemove = new Set(files.map((file) => file.id));
- setVisiblePhotos((prev) =>
- prev.filter((photo) => !idsToRemove.has(photo.fileId)),
- );
- removeFilesFromMap([...idsToRemove]);
- },
- [onMarkTempDeleted, removeFilesFromMap, setVisiblePhotos],
- );
-
- const handleFileVisibilityUpdateWithLocalState = useCallback(
- async (file: EnteFile, visibility: ItemVisibility) => {
- await handleFileVisibilityUpdate(file, visibility);
- const updatedMagicMetadata = file.magicMetadata
- ? {
- ...file.magicMetadata,
- data: { ...file.magicMetadata.data, visibility },
- }
- : undefined;
- const updatedFile =
- updatedMagicMetadata !== undefined
- ? { ...file, magicMetadata: updatedMagicMetadata }
- : file;
- updateFileVisibility(updatedFile, visibility);
- },
- [handleFileVisibilityUpdate, updateFileVisibility],
- );
-
- const body = useMemo(() => {
- if (isLoading) {
- return (
- <CenteredBox>
- <ActivityIndicator size="28px" />
- </CenteredBox>
- );
- }
-
- if (error) {
- return (
- <CenteredBox>
- <Typography variant="body" color="text.secondary">
- {error}
- </Typography>
- </CenteredBox>
- );
- }
-
- // Wait for map components to load (they're dynamically imported)
- if (!mapComponents) {
- return (
- <CenteredBox>
- <ActivityIndicator size="28px" />
- </CenteredBox>
- );
- }
-
- if (!mapPoints.length || !mapCenter || !mapIndex) {
- return (
- <CenteredBox onClose={onClose} closeLabel={t("close")}>
- <Typography variant="body" color="text.secondary">
- {t("no_geotagged_photos")}
- </Typography>
- </CenteredBox>
- );
- }
-
- return (
- <MapLayout
- collectionSummary={collectionSummary}
- visiblePhotos={visiblePhotos}
- visibleFiles={visibleFiles}
- mapIndex={mapIndex}
- latestFileId={latestFileId}
- thumbByFileID={thumbByFileID}
- mapComponents={mapComponents}
- mapCenter={mapCenter}
- optimalZoom={optimalZoom}
- onClose={onClose}
- onVisiblePhotosChange={setVisiblePhotos}
- onVisiblePhotosLoadingChange={setIsVisiblePhotosUpdating}
- visiblePhotosUpdating={isVisiblePhotosUpdating}
- onPrefetchThumbnails={queueThumbnailFetch}
- user={user}
- favoriteFileIDs={favoriteFileIDs}
- pendingFavoriteUpdates={pendingFavoriteUpdates}
- pendingVisibilityUpdates={pendingVisibilityUpdates}
- onToggleFavorite={handleToggleFavorite}
- onFileVisibilityUpdate={
- handleFileVisibilityUpdateWithLocalState
- }
- onRemotePull={handleRemotePull}
- onVisualFeedback={visualFeedback}
- onAddSaveGroup={onAddSaveGroup}
- onMarkTempDeleted={handleMarkTempDeleted}
- onAddFileToCollection={onAddFileToCollection}
- onRemoteFilesPull={onRemoteFilesPull}
- fileNormalCollectionIDs={fileNormalCollectionIDs}
- collectionNameByID={collectionNameByID}
- onSelectCollection={onSelectCollection}
- onSelectPerson={onSelectPerson}
- selected={emptySelected}
- setSelected={noOpSetSelected}
- onSetOpenFileViewer={handleSetFileViewerOpen}
- />
- );
- }, [
- collectionSummary,
- emptySelected,
- error,
- favoriteFileIDs,
- handleFileVisibilityUpdateWithLocalState,
- handleRemotePull,
- handleToggleFavorite,
- visualFeedback,
- isLoading,
- mapCenter,
- mapComponents,
- mapIndex,
- mapPoints,
- latestFileId,
- noOpSetSelected,
- optimalZoom,
- onAddFileToCollection,
- onAddSaveGroup,
- onRemoteFilesPull,
- pendingFavoriteUpdates,
- pendingVisibilityUpdates,
- setIsVisiblePhotosUpdating,
- setVisiblePhotos,
- collectionNameByID,
- fileNormalCollectionIDs,
- handleMarkTempDeleted,
- onSelectCollection,
- onSelectPerson,
- thumbByFileID,
- queueThumbnailFetch,
- user,
- visibleFiles,
- visiblePhotos,
- isVisiblePhotosUpdating,
- onClose,
- handleSetFileViewerOpen,
- ]);
-
- return (
- <Dialog
- fullScreen
- keepMounted
- open={open}
- onClose={onClose}
- sx={{
- // When the FileViewer is open, lower this dialog's z-index below
- // PhotoSwipe's z-index (1199) so that FileViewer appears on top.
- // This avoids the visual glitch caused by closing/reopening the
- // dialog during transitions.
- ...(isFileViewerOpen && {
- zIndex: (theme) =>
- `calc(${theme.zIndex.drawer} - 2) !important`,
- }),
- }}
- >
- <Box
- sx={{
- position: "relative",
- width: "100vw",
- height: "100vh",
- bgcolor: "background.default",
- }}
- >
- <DialogContent sx={{ padding: "0 !important", height: "100%" }}>
- {body}
- </DialogContent>
- </Box>
- </Dialog>
- );
-};
-
-// ============================================================================
-// Layout Components
-// ============================================================================
-
-/**
- * Main layout container for map and sidebar
- * Responsibility: Position sidebar and map canvas side-by-side
- */
-interface MapLayoutProps {
- collectionSummary: CollectionSummary;
- visiblePhotos: JourneyPoint[];
- visibleFiles: EnteFile[];
- visiblePhotosUpdating: boolean;
- mapIndex: MapIndex | null;
- latestFileId: number | undefined;
- thumbByFileID: Map<number, string>;
- mapComponents: MapComponents;
- mapCenter: [number, number];
- optimalZoom: number;
- onClose: () => void;
- onVisiblePhotosChange: (photosInView: JourneyPoint[]) => void;
- onVisiblePhotosLoadingChange: (loading: boolean) => void;
- onPrefetchThumbnails: (fileIDs: number[]) => void;
- user: ReturnType<typeof useCurrentUser>;
- favoriteFileIDs: Set<number>;
- pendingFavoriteUpdates: Set<number>;
- pendingVisibilityUpdates: Set<number>;
- onToggleFavorite: (file: EnteFile) => Promise<void>;
- onFileVisibilityUpdate: (
- file: EnteFile,
- visibility: ItemVisibility,
- ) => Promise<void>;
- onRemotePull: () => Promise<void>;
- onVisualFeedback: () => void;
- onAddSaveGroup: FileListWithViewerProps["onAddSaveGroup"];
- onMarkTempDeleted?: FileListWithViewerProps["onMarkTempDeleted"];
- onAddFileToCollection?: FileListWithViewerProps["onAddFileToCollection"];
- onRemoteFilesPull?: FileListWithViewerProps["onRemoteFilesPull"];
- fileNormalCollectionIDs?: FileListWithViewerProps["fileNormalCollectionIDs"];
- collectionNameByID?: FileListWithViewerProps["collectionNameByID"];
- onSelectCollection?: FileListWithViewerProps["onSelectCollection"];
- onSelectPerson?: FileListWithViewerProps["onSelectPerson"];
- onSetOpenFileViewer?: (open: boolean) => void;
- selected: SelectedState;
- setSelected: () => void;
-}
-
-function MapLayout({
- collectionSummary,
- visiblePhotos,
- visibleFiles,
- visiblePhotosUpdating,
- mapIndex,
- latestFileId,
- thumbByFileID,
- mapComponents,
- mapCenter,
- optimalZoom,
- onClose,
- onVisiblePhotosChange,
- onVisiblePhotosLoadingChange,
- onPrefetchThumbnails,
- user,
- favoriteFileIDs,
- pendingFavoriteUpdates,
- pendingVisibilityUpdates,
- onToggleFavorite,
- onFileVisibilityUpdate,
- onRemotePull,
- onVisualFeedback,
- onAddSaveGroup,
- onMarkTempDeleted,
- onAddFileToCollection,
- onRemoteFilesPull,
- fileNormalCollectionIDs,
- collectionNameByID,
- onSelectCollection,
- onSelectPerson,
- onSetOpenFileViewer,
- selected,
- setSelected,
-}: MapLayoutProps) {
- return (
- <Box sx={{ position: "relative", height: "100%", width: "100%" }}>
- <CollectionSidebar
- collectionSummary={collectionSummary}
- visibleCount={visiblePhotos.length}
- visibleFiles={visibleFiles}
- isVisiblePhotosUpdating={visiblePhotosUpdating}
- latestFileId={latestFileId}
- thumbByFileID={thumbByFileID}
- onClose={onClose}
- user={user}
- favoriteFileIDs={favoriteFileIDs}
- pendingFavoriteUpdates={pendingFavoriteUpdates}
- pendingVisibilityUpdates={pendingVisibilityUpdates}
- onToggleFavorite={onToggleFavorite}
- onFileVisibilityUpdate={onFileVisibilityUpdate}
- onRemotePull={onRemotePull}
- onVisualFeedback={onVisualFeedback}
- onAddSaveGroup={onAddSaveGroup}
- onMarkTempDeleted={onMarkTempDeleted}
- onAddFileToCollection={onAddFileToCollection}
- onRemoteFilesPull={onRemoteFilesPull}
- fileNormalCollectionIDs={fileNormalCollectionIDs}
- collectionNameByID={collectionNameByID}
- onSelectCollection={onSelectCollection}
- onSelectPerson={onSelectPerson}
- selected={selected}
- setSelected={setSelected}
- onSetOpenFileViewer={onSetOpenFileViewer}
- />
- <Box sx={{ width: "100%", height: "100%" }}>
- <MapCanvas
- mapComponents={mapComponents}
- mapCenter={mapCenter}
- mapIndex={mapIndex}
- optimalZoom={optimalZoom}
- thumbByFileID={thumbByFileID}
- onVisiblePhotosChange={onVisiblePhotosChange}
- onVisiblePhotosLoadingChange={onVisiblePhotosLoadingChange}
- onPrefetchThumbnails={onPrefetchThumbnails}
- />
- </Box>
- </Box>
- );
-}
-
-// ============================================================================
-// Sidebar Components
-// ============================================================================
-
-/**
- * Sidebar displaying collection details and photo thumbnails using FileListWithViewer
- * Responsibility: Show collection cover, header, and file list with integrated viewer
- */
-interface CollectionSidebarProps {
- collectionSummary: CollectionSummary;
- visibleCount: number;
- visibleFiles: EnteFile[];
- isVisiblePhotosUpdating: boolean;
- latestFileId: number | undefined;
- thumbByFileID: Map<number, string>;
- onClose: () => void;
- user: ReturnType<typeof useCurrentUser>;
- favoriteFileIDs: Set<number>;
- pendingFavoriteUpdates: Set<number>;
- pendingVisibilityUpdates: Set<number>;
- onToggleFavorite: (file: EnteFile) => Promise<void>;
- onFileVisibilityUpdate: (
- file: EnteFile,
- visibility: ItemVisibility,
- ) => Promise<void>;
- onRemotePull: () => Promise<void>;
- onVisualFeedback: () => void;
- onAddSaveGroup: FileListWithViewerProps["onAddSaveGroup"];
- onMarkTempDeleted?: FileListWithViewerProps["onMarkTempDeleted"];
- onAddFileToCollection?: FileListWithViewerProps["onAddFileToCollection"];
- onRemoteFilesPull?: FileListWithViewerProps["onRemoteFilesPull"];
- fileNormalCollectionIDs?: FileListWithViewerProps["fileNormalCollectionIDs"];
- collectionNameByID?: FileListWithViewerProps["collectionNameByID"];
- onSelectCollection?: FileListWithViewerProps["onSelectCollection"];
- onSelectPerson?: FileListWithViewerProps["onSelectPerson"];
- onSetOpenFileViewer?: (open: boolean) => void;
- selected: SelectedState;
- setSelected: () => void;
-}
-
-// Fixed height for the cover image container (px)
-const COVER_IMAGE_HEIGHT = 320;
-const MOBILE_SIDEBAR_HEIGHT = "50%";
-// Mobile has less padding: 8px top + 12px bottom + 2px margin = 22px
-// Desktop has more padding: 16px top + 16px bottom + 2px margin = 34px
-// Use desktop value for consistency in the virtualized list
-const COVER_HEADER_HEIGHT = COVER_IMAGE_HEIGHT + 34;
-
-function CollectionSidebar({
- collectionSummary,
- visibleFiles,
- isVisiblePhotosUpdating,
- latestFileId,
- thumbByFileID,
- onClose,
- user,
- favoriteFileIDs,
- pendingFavoriteUpdates,
- pendingVisibilityUpdates,
- onToggleFavorite,
- onFileVisibilityUpdate,
- onRemotePull,
- onVisualFeedback,
- onAddSaveGroup,
- onMarkTempDeleted,
- onAddFileToCollection,
- onRemoteFilesPull,
- fileNormalCollectionIDs,
- collectionNameByID,
- onSelectCollection,
- onSelectPerson,
- onSetOpenFileViewer,
- selected,
- setSelected,
-}: CollectionSidebarProps) {
- const [currentDate, setCurrentDate] = useState<string | undefined>(
- undefined,
- );
- const [scrollOffset, setScrollOffset] = useState(0);
- const shouldShowCover = collectionSummary.type !== "all";
- const theme = useTheme();
- const isDarkMode = theme.palette.mode === "dark";
- const isMobile = useMediaQuery(theme.breakpoints.down("md"));
-
- // Get cover image: prioritize collection's coverFile, fallback to first photo
- const coverFile = collectionSummary.coverFile;
- const coverImageUrl = useMemo(() => {
- const coverThumb = coverFile && thumbByFileID.get(coverFile.id);
- if (coverThumb) return coverThumb;
-
- const fallbackId = latestFileId;
- return fallbackId ? thumbByFileID.get(fallbackId) : undefined;
- }, [coverFile, latestFileId, thumbByFileID]);
-
- // Create header component for FileListWithViewer (cover scrolls with content)
- const coverHeader = useMemo(() => {
- if (!shouldShowCover) return undefined;
- return {
- component: (
- <MapCover
- name={collectionSummary.name}
- coverImageUrl={coverImageUrl}
- totalCount={collectionSummary.fileCount}
- onClose={onClose}
- />
- ),
- height: COVER_HEADER_HEIGHT,
- extendToInlineEdges: true,
- };
- }, [
- shouldShowCover,
- collectionSummary.name,
- collectionSummary.fileCount,
- coverImageUrl,
- onClose,
- ]);
-
- // Handle scroll events from the file list
- const handleScroll = useCallback((offset: number) => {
- setScrollOffset(offset);
- }, []);
-
- // Handle visible date changes from the file list
- const handleVisibleDateChange = useCallback((date: string | undefined) => {
- setCurrentDate(date);
- }, []);
-
- // Only show sticky date after scrolling past the cover header, or always for "All"
- const showStickyHeader =
- !shouldShowCover ||
- (scrollOffset > COVER_HEADER_HEIGHT && !!currentDate);
- const hasScrolled = scrollOffset > 0;
- const hideDateForAllNoScroll = !shouldShowCover && !hasScrolled;
- const hideDateForMobileNoScroll = isMobile && !hasScrolled;
- const visibleDate =
- currentDate && !hideDateForAllNoScroll && !hideDateForMobileNoScroll
- ? currentDate
- : undefined;
-
- return (
- <SidebarWrapper>
- <SidebarContainer>
- <StickyDateHeader
- visible={showStickyHeader}
- variant={shouldShowCover ? "overlay" : "static"}
- >
- <Box
- sx={{
- display: "flex",
- justifyContent: "space-between",
- alignItems: "center",
- }}
- >
- <Box>
- <Typography
- variant="body"
- sx={{ fontWeight: 700, fontSize: "18px" }}
- >
- {collectionSummary.name}
- </Typography>
- <Typography
- variant="small"
- sx={{ color: "text.muted", fontSize: "14px" }}
- >
- {t("photos_count", {
- count: collectionSummary.fileCount,
- })}
- {visibleDate && ` · ${visibleDate}`}
- </Typography>
- </Box>
- <Box
- sx={{
- display: "flex",
- alignItems: "center",
- gap: 1,
- }}
- >
- <IconButton
- onClick={onClose}
- size="small"
- sx={{
- color: "text.secondary",
- bgcolor: "fill.faint",
- "&:hover": { bgcolor: "fill.muted" },
- }}
- >
- <CloseIcon />
- </IconButton>
- </Box>
- </Box>
- </StickyDateHeader>
- <FileListContainer>
- {visibleFiles.length > 0 ? (
- <FileListWithViewer
- files={visibleFiles}
- user={user}
- favoriteFileIDs={favoriteFileIDs}
- pendingFavoriteUpdates={pendingFavoriteUpdates}
- pendingVisibilityUpdates={pendingVisibilityUpdates}
- onToggleFavorite={onToggleFavorite}
- onFileVisibilityUpdate={onFileVisibilityUpdate}
- onRemotePull={onRemotePull}
- onVisualFeedback={onVisualFeedback}
- onAddSaveGroup={onAddSaveGroup}
- onMarkTempDeleted={onMarkTempDeleted}
- onAddFileToCollection={onAddFileToCollection}
- onRemoteFilesPull={onRemoteFilesPull}
- fileNormalCollectionIDs={fileNormalCollectionIDs}
- collectionNameByID={collectionNameByID}
- onSelectCollection={onSelectCollection}
- onSelectPerson={onSelectPerson}
- enableImageEditing={false}
- enableDownload={true}
- activeCollectionID={collectionSummary.id}
- selected={selected}
- setSelected={setSelected}
- onSetOpenFileViewer={onSetOpenFileViewer}
- listBorderRadius={isMobile ? "0" : "0 0 32px 32px"}
- header={coverHeader}
- onScroll={handleScroll}
- onVisibleDateChange={handleVisibleDateChange}
- />
- ) : isVisiblePhotosUpdating ? null : (
- <EmptyState>
- {shouldShowCover && (
- <MapCover
- name={collectionSummary.name}
- coverImageUrl={coverImageUrl}
- totalCount={collectionSummary.fileCount}
- onClose={onClose}
- />
- )}
- <EmptyStateMessage>
- <Typography
- variant="body"
- sx={{ fontWeight: 600 }}
- >
- {t("no_photos_found_here")}
- </Typography>
- <Typography
- variant="small"
- color="text.secondary"
- >
- {t("zoom_out_to_see_photos")}
- </Typography>
- </EmptyStateMessage>
- </EmptyState>
- )}
- </FileListContainer>
- </SidebarContainer>
- {isDarkMode && <SidebarGradient />}
- </SidebarWrapper>
- );
-}
-
-// ============================================================================
-// Map Components
-// ============================================================================
-
-/**
- * Renders the Leaflet map with markers, clusters, and controls
- * Responsibility: Display interactive map with photo markers and handle viewport changes
- */
-interface MapCanvasProps {
- mapComponents: MapComponents;
- mapCenter: [number, number];
- mapIndex: MapIndex | null;
- optimalZoom: number;
- thumbByFileID: Map<number, string>;
- onVisiblePhotosChange: (photosInView: JourneyPoint[]) => void;
- onVisiblePhotosLoadingChange: (loading: boolean) => void;
- onPrefetchThumbnails: (fileIDs: number[]) => void;
-}
-
-const openStreetMapAttribution =
- '&copy; <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener noreferrer">OpenStreetMap</a> contributors';
-
-const leafletAttributionPrefix =
- '<a href="https://leafletjs.com" target="_blank" rel="noopener noreferrer">Leaflet</a>';
-
-const MapCanvas = React.memo(function MapCanvas({
- mapComponents,
- mapCenter,
- mapIndex,
- optimalZoom,
- thumbByFileID,
- onVisiblePhotosChange,
- onVisiblePhotosLoadingChange,
- onPrefetchThumbnails,
-}: MapCanvasProps) {
- const { MapContainer, TileLayer, Marker, useMap } = mapComponents;
-
- return (
- <MapCanvasContainer>
- <MapContainer
- center={mapCenter}
- zoom={optimalZoom}
- scrollWheelZoom
- zoomControl={false}
- style={{ width: "100%", height: "100%" }}
- >
- <TileLayer
- attribution={openStreetMapAttribution}
- url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
- maxZoom={MAX_MAP_ZOOM}
- updateWhenZooming
- />
- <MapControls useMap={useMap} />
- {mapIndex && (
- <MapClusters
- useMap={useMap}
- mapIndex={mapIndex}
- thumbByFileID={thumbByFileID}
- onVisiblePhotosChange={onVisiblePhotosChange}
- onVisiblePhotosLoadingChange={
- onVisiblePhotosLoadingChange
- }
- onPrefetchThumbnails={onPrefetchThumbnails}
- Marker={Marker}
- />
- )}
- </MapContainer>
- </MapCanvasContainer>
- );
-});
-
-/**
- * Floating map control buttons (open in Maps, zoom in/out)
- * Responsibility: Provide map navigation and external link controls
- */
-interface MapControlsProps {
- useMap: typeof import("react-leaflet").useMap;
-}
-
-const MapControls = React.memo(function MapControls({
- useMap,
-}: MapControlsProps) {
- const map = useMap();
-
- useEffect(() => {
- map.attributionControl.setPrefix(leafletAttributionPrefix);
- }, [map]);
-
- const handleOpenInMaps = useCallback(() => {
- const center = map.getCenter();
- const url = `https://www.google.com/maps?q=${center.lat},${center.lng}&z=${map.getZoom()}`;
- window.open(url, "_blank", "noopener,noreferrer");
- }, [map]);
-
- const handleZoomIn = useCallback(() => map.zoomIn(), [map]);
- const handleZoomOut = useCallback(() => map.zoomOut(), [map]);
-
- return (
- <>
- {/* Zoom controls: top left on mobile, bottom right on desktop */}
- <Stack
- spacing={1}
- sx={(theme) => ({
- position: "absolute",
- left: 24,
- top: 24,
- zIndex: 1000,
- [theme.breakpoints.up("md")]: {
- left: "auto",
- top: "auto",
- right: 24,
- bottom: 48,
- },
- })}
- >
- <FloatingIconButton onClick={handleZoomIn}>
- <AddIcon />
- </FloatingIconButton>
- <FloatingIconButton onClick={handleZoomOut}>
- <RemoveIcon />
- </FloatingIconButton>
- {/* Location button: hidden on mobile, shown in stack on desktop */}
- <FloatingIconButton
- onClick={handleOpenInMaps}
- sx={(theme) => ({
- display: "none",
- [theme.breakpoints.up("md")]: { display: "flex" },
- })}
- >
- <LocationOnIcon />
- </FloatingIconButton>
- </Stack>
-
- {/* Location button: top right on mobile only */}
- <FloatingIconButton
- onClick={handleOpenInMaps}
- sx={(theme) => ({
- position: "absolute",
- right: 24,
- top: 24,
- zIndex: 1000,
- [theme.breakpoints.up("md")]: { display: "none" },
- })}
- >
- <LocationOnIcon />
- </FloatingIconButton>
- </>
- );
-});
-
-interface MapClustersProps {
- useMap: typeof import("react-leaflet").useMap;
- mapIndex: MapIndex;
- thumbByFileID: Map<number, string>;
- onVisiblePhotosChange: (photosInView: JourneyPoint[]) => void;
- onVisiblePhotosLoadingChange: (loading: boolean) => void;
- onPrefetchThumbnails: (fileIDs: number[]) => void;
- Marker: typeof import("react-leaflet").Marker;
-}
-
-const MapClusters = React.memo(function MapClusters({
- useMap,
- mapIndex,
- thumbByFileID,
- onVisiblePhotosChange,
- onVisiblePhotosLoadingChange,
- onPrefetchThumbnails,
- Marker,
-}: MapClustersProps) {
- const map = useMap();
- const [features, setFeatures] = useState<MapFeature[]>([]);
- const previousVisibleIdsRef = useRef<Set<number>>(new Set());
- const visibleRequestIdRef = useRef(0);
- const iconCacheRef = useRef(
- new Map<string, ReturnType<typeof createMarkerIcon>>(),
- );
-
- const isClusterFeature = useCallback(
- (feature: MapFeature): feature is MapClusterFeature =>
- feature.properties.cluster === true,
- [],
- );
-
- const updateVisibleLeaves = useCallback(
- async (
- requestId: number,
- clusters: MapFeature[],
- bounds: { contains: (latlng: [number, number]) => boolean },
- ) => {
- if (requestId !== visibleRequestIdRef.current) return;
- onVisiblePhotosLoadingChange(true);
-
- const inBounds = (lat: number, lng: number) =>
- bounds.contains([lat, lng]);
-
- const leaves: MapPointFeature[] = [];
- let processedClusters = 0;
-
- for (const feature of clusters) {
- if (requestId !== visibleRequestIdRef.current) return;
-
- if (isClusterFeature(feature)) {
- const clusterProps = feature.properties;
- const totalLeaves = clusterProps.point_count;
- const batchSize = 1000;
- for (
- let offset = 0;
- offset < totalLeaves;
- offset += batchSize
- ) {
- if (requestId !== visibleRequestIdRef.current) return;
- const clusterLeaves = mapIndex.getLeaves(
- clusterProps.cluster_id,
- batchSize,
- offset,
- );
- clusterLeaves.forEach((leaf) => {
- const [lng, lat] = leaf.geometry.coordinates;
- if (inBounds(lat, lng)) {
- leaves.push(leaf);
- }
- });
- await new Promise((resolve) => setTimeout(resolve, 0));
- }
- processedClusters += 1;
- if (processedClusters % 5 === 0) {
- await new Promise((resolve) => setTimeout(resolve, 0));
- }
- } else {
- const [lng, lat] = feature.geometry.coordinates;
- if (inBounds(lat, lng)) {
- leaves.push(feature);
- }
- }
- }
-
- if (requestId !== visibleRequestIdRef.current) return;
-
- leaves.sort(
- (a, b) => b.properties.timestamp - a.properties.timestamp,
- );
-
- const visibleIds = new Set(
- leaves.map((leaf) => leaf.properties.fileId),
- );
- const previousIds = previousVisibleIdsRef.current;
- const idsChanged =
- visibleIds.size !== previousIds.size ||
- [...visibleIds].some((id) => !previousIds.has(id));
-
- if (idsChanged) {
- previousVisibleIdsRef.current = visibleIds;
- const nextVisiblePhotos = leaves.map((leaf) => {
- const [lng, lat] = leaf.geometry.coordinates;
- return {
- lat,
- lng,
- name: "",
- country: "",
- timestamp: new Date(
- leaf.properties.timestamp / 1000,
- ).toISOString(),
- image: "",
- fileId: leaf.properties.fileId,
- };
- });
- startTransition(() => {
- onVisiblePhotosChange(nextVisiblePhotos);
- });
- }
-
- if (requestId === visibleRequestIdRef.current) {
- onVisiblePhotosLoadingChange(false);
- }
- },
- [
- isClusterFeature,
- mapIndex,
- onVisiblePhotosChange,
- onVisiblePhotosLoadingChange,
- ],
- );
-
- const updateClusters = useCallback(() => {
- const bounds = map.getBounds();
- const zoom = Math.round(map.getZoom());
- const bbox: [number, number, number, number] = [
- bounds.getWest(),
- bounds.getSouth(),
- bounds.getEast(),
- bounds.getNorth(),
- ];
-
- const nextZoom = Math.min(zoom + 1, MAX_MAP_ZOOM);
- const clusters = mapIndex.getClusters(bbox, zoom);
- setFeatures(clusters);
-
- const requestId = ++visibleRequestIdRef.current;
- void updateVisibleLeaves(requestId, clusters, bounds);
-
- const prefetchBounds = bounds.pad(PREFETCH_BOUNDS_PADDING);
- const prefetchBbox: [number, number, number, number] = [
- prefetchBounds.getWest(),
- prefetchBounds.getSouth(),
- prefetchBounds.getEast(),
- prefetchBounds.getNorth(),
- ];
-
- const prefetchTargets = new Set<number>();
- const collectTargets = (items: MapFeature[]) => {
- items.forEach((feature) => {
- if (isClusterFeature(feature)) {
- prefetchTargets.add(feature.properties.latestFileId);
- } else {
- prefetchTargets.add(feature.properties.fileId);
- }
- });
- };
-
- collectTargets(clusters);
- collectTargets(mapIndex.getClusters(prefetchBbox, nextZoom));
-
- if (prefetchTargets.size > 0) {
- onPrefetchThumbnails(Array.from(prefetchTargets));
- }
- }, [
- isClusterFeature,
- map,
- mapIndex,
- onPrefetchThumbnails,
- updateVisibleLeaves,
- ]);
-
- useEffect(() => {
- iconCacheRef.current.clear();
- previousVisibleIdsRef.current = new Set();
- visibleRequestIdRef.current += 1;
- }, [mapIndex]);
-
- const handleClusterClick = useCallback(
- (lat: number, lng: number, expansionZoom: number) => {
- map.setView([lat, lng], expansionZoom, { animate: true });
- },
- [map],
- );
-
- useEffect(() => {
- updateClusters();
- }, [updateClusters]);
-
- useEffect(() => {
- map.on("moveend", updateClusters);
- map.on("zoomend", updateClusters);
- return () => {
- map.off("moveend", updateClusters);
- map.off("zoomend", updateClusters);
- };
- }, [map, updateClusters]);
-
- const currentZoom = Math.round(map.getZoom());
-
- return (
- <>
- {features.map((feature) => {
- const [lng, lat] = feature.geometry.coordinates;
- const isCluster = isClusterFeature(feature);
-
- if (isCluster) {
- const clusterProps = feature.properties;
- const clusterId = clusterProps.cluster_id;
- const count = clusterProps.point_count;
- const expansionZoom = Math.min(
- mapIndex.getClusterExpansionZoom(clusterId),
- MAX_MAP_ZOOM,
- );
- const isInteractive = expansionZoom > currentZoom;
- const thumb =
- thumbByFileID.get(clusterProps.latestFileId) ?? "";
- const cacheKey = `cluster-${clusterId}-${count}-${thumb}-${isInteractive ? "i" : "n"}`;
- let icon = iconCacheRef.current.get(cacheKey);
- if (!icon) {
- icon = createClusterIcon(
- thumb,
- 68,
- count,
- isInteractive,
- );
- if (icon) {
- iconCacheRef.current.set(cacheKey, icon);
- }
- }
- return (
- <Marker
- key={`cluster-${clusterId}`}
- position={[lat, lng]}
- icon={icon ?? undefined}
- eventHandlers={
- isInteractive
- ? {
- click: () =>
- handleClusterClick(
- lat,
- lng,
- expansionZoom,
- ),
- }
- : undefined
- }
- />
- );
- }
-
- const fileId = feature.properties.fileId;
- const thumb = thumbByFileID.get(fileId) ?? "";
- const cacheKey = `point-${fileId}-${thumb}`;
- let icon = iconCacheRef.current.get(cacheKey);
- if (!icon) {
- icon = createMarkerIcon(thumb, 68);
- if (icon) {
- iconCacheRef.current.set(cacheKey, icon);
- }
- }
- return (
- <Marker
- key={`point-${fileId}`}
- position={[lat, lng]}
- icon={icon ?? undefined}
- />
- );
- })}
- </>
- );
-});
-
-// ============================================================================
-// UI Components
-// ============================================================================
-
-/**
- * Styled floating action button with consistent styling
- * Responsibility: Provide consistent button styling for map controls
- */
-const FloatingIconButton: React.FC<IconButtonProps> = ({ sx, ...props }) => {
- const baseSx = {
- bgcolor: (theme: {
- vars: { palette: { background: { paper: string } } };
- }) => theme.vars.palette.background.paper,
- boxShadow: (theme: { shadows: string[] }) => theme.shadows[4],
- width: 48,
- height: 48,
- borderRadius: "16px",
- transition: "transform 0.2s ease-out",
- "&:hover": {
- bgcolor: (theme: {
- vars: { palette: { background: { paper: string } } };
- }) => theme.vars.palette.background.paper,
- transform: "scale(1.05)",
- },
- };
-
- const mergedSx =
- sx == null
- ? baseSx
- : Array.isArray(sx)
- ? // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- [baseSx, ...sx]
- : [baseSx, sx];
-
- return <IconButton {...props} sx={mergedSx} />;
-};
-
-/**
- * Centered container for loading/error states with optional close button
- * Responsibility: Display centered content like loading spinners or error messages
- */
-interface CenteredBoxProps extends React.PropsWithChildren {
- onClose?: () => void;
- closeLabel?: string;
-}
-
-function CenteredBox({ children, onClose, closeLabel }: CenteredBoxProps) {
- return (
- <CenteredBoxContainer>
- {onClose && (
- <IconButton
- aria-label={closeLabel ?? "Close"}
- onClick={onClose}
- sx={{ position: "absolute", top: 16, right: 16 }}
- >
- <CloseIcon />
- </IconButton>
- )}
- {children}
- </CenteredBoxContainer>
- );
-}
-
-/**
- * Empty state placeholder for when no photos are visible
- * Responsibility: Display empty state message when no photos match filters
- */
-function EmptyState({ children }: React.PropsWithChildren) {
- return <EmptyStateContainer>{children}</EmptyStateContainer>;
-}
-
-// ============================================================================
-// Map Cover Component
-// ============================================================================
-
-/**
- * Hero image cover for the collection with title and memory count
- * Responsibility: Display collection cover image, name, and visible memory count
- */
-interface MapCoverProps {
- name: string;
- coverImageUrl: string | undefined;
- totalCount: number;
- onClose: () => void;
-}
-
-const MapCover = React.memo(function MapCover({
- name,
- coverImageUrl,
- totalCount,
- onClose,
-}: MapCoverProps) {
- return (
- <CoverContainer>
- <CoverImageContainer>
- <img
- src={coverImageUrl}
- alt="Cover"
- style={{
- position: "absolute",
- inset: 0,
- width: "100%",
- height: "100%",
- objectFit: "cover",
- objectPosition: "Center",
- }}
- />
- <CoverGradientOverlay />
-
- <CoverCloseButton aria-label="Close" onClick={onClose}>
- <CloseIcon sx={{ fontSize: 20 }} />
- </CoverCloseButton>
-
- <CoverContentContainer>
- <CoverTitle>{name}</CoverTitle>
- <CoverSubtitle>
- {t("photos_count", { count: totalCount })}
- </CoverSubtitle>
- </CoverContentContainer>
- </CoverImageContainer>
- </CoverContainer>
- );
-});
-
-const MapCanvasContainer = styled(Box)(({ theme }) => ({
- width: "100%",
- height: "100%",
- [theme.breakpoints.down("md")]: {
- "& .leaflet-bottom.leaflet-right": { bottom: MOBILE_SIDEBAR_HEIGHT },
- },
-}));
-
-const CoverContainer = styled(Box)(({ theme }) => ({
- width: "100%",
- flexShrink: 0,
- paddingTop: "16px",
- paddingBottom: "16px",
- [theme.breakpoints.down("md")]: {
- padding: "8px",
- paddingTop: "20px",
- paddingBottom: "12px",
- },
-}));
-
-const CoverImageContainer = styled(Box)(({ theme }) => ({
- height: `${COVER_IMAGE_HEIGHT}px`,
- position: "relative",
- overflow: "hidden",
- backgroundColor: "#333",
- borderRadius: "36px 36px 24px 24px",
- marginTop: "2px",
- [theme.breakpoints.down("md")]: { borderRadius: "20px 20px 20px 20px" },
-}));
-
-const CoverGradientOverlay = styled(Box)({
- position: "absolute",
- inset: 0,
- background:
- "linear-gradient(to bottom, rgba(0,0,0,0.4), transparent 35%, transparent 60%, rgba(0,0,0,0.75))",
-});
-
-const CoverCloseButton = styled(IconButton)({
- position: "absolute",
- top: "12px",
- right: "12px",
- color: "white",
- backgroundColor: "rgba(0, 0, 0, 0.3)",
- "&:hover": { backgroundColor: "rgba(0, 0, 0, 0.5)" },
-});
-
-const CoverContentContainer = styled(Box)({
- position: "absolute",
- bottom: 0,
- left: 0,
- right: 0,
- padding: "24px",
- paddingLeft: "18px",
- color: "white",
-});
-
-const CoverTitle = styled(Typography)({
- fontSize: "22px",
- fontWeight: "bold",
- marginBottom: "6px",
- lineHeight: 1.2,
-});
-
-const CoverSubtitle = styled(Typography)({
- color: "rgba(255, 255, 255, 0.85)",
- fontSize: "14px",
- fontWeight: "500",
-});
-
-// ============================================================================
-// Sidebar Styled Components
-// ============================================================================
-
-const SidebarWrapper = styled(Box)(({ theme }) => ({
- position: "absolute",
- left: 0,
- top: "auto",
- bottom: 0,
- right: 0,
- width: "100%",
- height: MOBILE_SIDEBAR_HEIGHT,
- zIndex: 1000,
- [theme.breakpoints.up("md")]: {
- left: 16,
- top: 16,
- bottom: 16,
- right: "auto",
- height: "auto",
- width: "30%",
- maxWidth: "600px",
- minWidth: "450px",
- },
-}));
-
-const SidebarContainer = styled(Box)(({ theme }) => ({
- position: "relative",
- width: "100%",
- height: "100%",
- backgroundColor: theme.vars.palette.background.paper,
- boxShadow: theme.shadows[10],
- display: "flex",
- flexDirection: "column",
- overflow: "hidden",
- borderRadius: "24px 24px 0 0",
- [theme.breakpoints.up("md")]: { borderRadius: "48px" },
-}));
-
-const SidebarGradient = styled(Box)(({ theme }) => ({
- position: "absolute",
- bottom: 0,
- left: 0,
- right: 0,
- height: "80px",
- background:
- "linear-gradient(to top, rgba(0,0,0,1) 0%, rgba(0,0,0,0.65) 2%, rgba(0,0,0,0) 100%)",
- pointerEvents: "none",
- borderRadius: "0",
- [theme.breakpoints.up("md")]: {
- height: "150px",
- borderRadius: "0 0 48px 48px",
- },
-}));
-
-const FileListContainer = styled(Box)(({ theme }) => ({
- flex: 1,
- minHeight: 0,
- position: "relative",
- display: "flex",
- flexDirection: "column",
- paddingLeft: "8px",
- paddingRight: "8px",
- paddingTop: "0px",
- paddingBottom: "calc(env(safe-area-inset-bottom, 0px) + 16px)",
- [theme.breakpoints.up("md")]: {
- paddingTop: "0px",
- paddingLeft: "16px",
- paddingRight: "16px",
- paddingBottom: "18px",
- },
-}));
-
-const StickyDateHeader = styled(Box)<{
- visible: boolean;
- variant: "overlay" | "static";
-}>(({ theme, visible, variant }) => {
- const isStatic = variant === "static";
- return {
- position: isStatic ? "relative" : "absolute",
- top: 0,
- left: 0,
- right: 0,
- zIndex: 10,
- backgroundColor: theme.vars.palette.background.paper,
- padding: "28px 24px 24px 24px",
- borderBottom: `1px solid ${theme.vars.palette.divider}`,
- opacity: isStatic || visible ? 1 : 0,
- transform: isStatic || visible ? "translateY(0)" : "translateY(-10px)",
- pointerEvents: isStatic || visible ? "auto" : "none",
- transition: isStatic
- ? "none"
- : "opacity 0.25s ease-out, transform 0.25s ease-out",
- [theme.breakpoints.down("md")]: { padding: "24px 20px 20px 20px" },
- };
-});
-
-const CenteredBoxContainer = styled(Box)({
- width: "100%",
- height: "100%",
- minHeight: "420px",
- position: "relative",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- gap: 8,
- flexDirection: "column",
- textAlign: "center",
-});
-
-const EmptyStateContainer = styled(Box)(({ theme }) => ({
- minHeight: "100%",
- position: "relative",
- display: "flex",
- flexDirection: "column",
- alignItems: "stretch",
- justifyContent: "flex-start",
- paddingTop: 0,
- paddingBottom: theme.spacing(4),
- color: theme.vars.palette.text.secondary,
- overflow: "auto",
-}));
-
-const EmptyStateMessage = styled(Box)(({ theme }) => ({
- position: "absolute",
- top: "50%",
- left: "50%",
- transform: "translate(-50%, -50%)",
- display: "flex",
- flexDirection: "column",
- alignItems: "center",
- justifyContent: "center",
- textAlign: "center",
- gap: theme.spacing(1),
-}));
diff --git a/web/apps/albums/vendor/photos/components/FileListWithViewer.tsx b/web/apps/albums/vendor/photos/components/FileListWithViewer.tsx
index d3b9fcc9b2..2c737d07ab 100644
--- a/web/apps/albums/vendor/photos/components/FileListWithViewer.tsx
+++ b/web/apps/albums/vendor/photos/components/FileListWithViewer.tsx
@@ -1,8 +1,4 @@
-import { IconButton, Tooltip, styled } from "@mui/material";
-import { useColorScheme, useTheme } from "@mui/material/styles";
-import { CollectionMapDialog } from "components/Collections/CollectionMapDialog";
-import { useModalVisibility } from "ente-base/components/utils/modal";
-import { useBaseContext } from "ente-base/context";
+import { styled } from "@mui/material";
import { isSameDay } from "ente-base/date";
import { formattedDate } from "ente-base/i18n-date";
import type { AddSaveGroup } from "ente-gallery/components/utils/save-groups";
@@ -15,11 +11,8 @@ import { downloadAndSaveFiles } from "ente-gallery/services/save";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
-import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
import { moveToTrash } from "ente-new/photos/services/collection";
-import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
-import { updateMapEnabled } from "ente-new/photos/services/settings";
import { t } from "i18next";
import { useCallback, useEffect, useMemo, useState } from "react";
import AutoSizer from "react-virtualized-auto-sizer";
@@ -56,8 +49,6 @@ export type FileListWithViewerProps = {
* pull from remote.
*/
onRemotePull: () => Promise<void>;
- activeCollectionSummary?: CollectionSummary;
- activeCollection?: Collection;
/**
* If set, the file viewer will open to this file index on mount/update.
* Set to undefined after the navigation is complete.
@@ -160,8 +151,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
setSelected,
activeCollectionID,
activePersonID,
- activeCollectionSummary,
- activeCollection,
favoriteFileIDs,
emailByUserID,
listBorderRadius,
@@ -209,17 +198,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
const [highlightCommentID, setHighlightCommentID] = useState<
string | undefined
>(undefined);
- const { show: showMapDialog, props: mapDialogVisibilityProps } =
- useModalVisibility();
- const { onGenericError } = useBaseContext();
- const { mapEnabled } = useSettingsSnapshot();
- const { mode: colorSchemeMode, systemMode } = useColorScheme();
- const theme = useTheme();
- const resolvedMode =
- colorSchemeMode === "system"
- ? systemMode
- : (colorSchemeMode ?? theme.palette.mode);
- const isDarkMode = resolvedMode === "dark";
// Handle pending navigation from feed item clicks
useEffect(() => {
@@ -296,51 +274,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
};
}, [enableImageEditing]);
- const shouldShowMapButton =
- modePlus !== "search" &&
- activeCollectionSummary?.type === "all" &&
- (activeCollectionSummary.fileCount > 0 || files.length > 0);
-
- const handleShowMap = useCallback(async () => {
- if (!activeCollectionSummary) return;
- if (!mapEnabled) {
- try {
- await updateMapEnabled(true);
- } catch (e) {
- onGenericError(e);
- return;
- }
- }
- showMapDialog();
- }, [activeCollectionSummary, mapEnabled, onGenericError, showMapDialog]);
-
- const headerWithMap = useMemo(() => {
- if (!shouldShowMapButton || !header) return header;
- return {
- ...header,
- component: (
- <HeaderWithMap>
- <HeaderMain>{header.component}</HeaderMain>
- <Tooltip title={t("map")}>
- <IconButton
- className="map-button"
- size="small"
- aria-label={t("map")}
- onClick={handleShowMap}
- >
- <MapIcon
- src="/images/gallery-globe/globe.svg"
- alt=""
- aria-hidden
- $isDarkMode={isDarkMode}
- />
- </IconButton>
- </Tooltip>
- </HeaderWithMap>
- ),
- };
- }, [header, handleShowMap, isDarkMode, shouldShowMapButton]);
-
return (
<Container>
<AutoSizer>
@@ -351,7 +284,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
mode,
modePlus,
layout,
- header: headerWithMap,
+ header,
footer,
user,
disableGrouping,
@@ -365,7 +298,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
listBorderRadius,
onScroll,
onVisibleDateChange,
- collectionSummary: activeCollectionSummary,
onContextMenuAction,
onContextMenuOpenChange,
showAddPersonAction,
@@ -418,25 +350,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
onAddFileToCollection={onAddFileToCollection}
activeCollectionID={activeCollectionID}
/>
- {shouldShowMapButton && (
- <CollectionMapDialog
- {...mapDialogVisibilityProps}
- collectionSummary={activeCollectionSummary}
- activeCollection={activeCollection}
- onRemotePull={onRemotePull}
- {...{
- onAddSaveGroup,
- onMarkTempDeleted,
- onAddFileToCollection,
- onRemoteFilesPull,
- onVisualFeedback,
- fileNormalCollectionIDs,
- collectionNameByID,
- onSelectCollection,
- onSelectPerson,
- }}
- />
- )}
</Container>
);
};
@@ -446,33 +359,6 @@ const Container = styled("div")`
width: 100%;
`;
-const HeaderWithMap = styled("div")`
- display: flex;
- align-items: center;
- justify-content: flex-start;
- gap: 12px;
- width: 100%;
- & > .map-button {
- flex-shrink: 0;
- margin-left: auto;
- }
-`;
-
-const HeaderMain = styled("div")`
- flex: 1;
- min-width: 0;
-`;
-
-const MapIcon = styled("img")<{ $isDarkMode: boolean }>(
- ({ theme, $isDarkMode }) => ({
- display: "block",
- width: 24,
- height: 24,
- filter:
- $isDarkMode || theme.palette.mode === "dark" ? "invert(1)" : "none",
- }),
-);
-
/**
* See: [Note: Timeline date string]
*/