Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat(CollectionMapDialog):only-images-in-view-showup-onsidebar

Aswin Asok71e415a28fbf
diff --git a/web/apps/photos/package.json b/web/apps/photos/package.json
index 7a2e61a554..50a93c88bb 100644
--- a/web/apps/photos/package.json
+++ b/web/apps/photos/package.json
@@ -16,6 +16,7 @@
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-leaflet": "^5.0.0",
+ "react-leaflet-cluster": "^4.0.0",
"react-select": "^5.10.2",
"react-top-loading-bar": "^3.0.2",
"react-virtualized-auto-sizer": "^1.0.26",
diff --git a/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx b/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx
index 5de5c333fa..4fd06ae38e 100644
--- a/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx
@@ -1,3 +1,4 @@
+import { keyframes } from "@emotion/react";
import AddIcon from "@mui/icons-material/Add";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import CloseIcon from "@mui/icons-material/Close";
@@ -186,6 +187,47 @@ const MapControls: React.FC<MapControlsProps> = ({ useMap, onClose }) => {
);
};
+interface MapViewportListenerProps {
+ useMap: typeof import("react-leaflet").useMap;
+ photos: JourneyPoint[];
+ onVisiblePhotosChange: (photosInView: JourneyPoint[]) => void;
+}
+
+const MapViewportListener: React.FC<MapViewportListenerProps> = ({
+ useMap,
+ photos,
+ onVisiblePhotosChange,
+}) => {
+ const map = useMap();
+
+ const updateVisiblePhotos = useCallback(() => {
+ const bounds = map.getBounds();
+ const inView = photos.filter((photo) =>
+ bounds.contains([photo.lat, photo.lng]),
+ );
+ onVisiblePhotosChange(inView);
+ }, [map, onVisiblePhotosChange, photos]);
+
+ useEffect(() => {
+ if (!photos.length) {
+ onVisiblePhotosChange([]);
+ return;
+ }
+ updateVisiblePhotos();
+ }, [photos, onVisiblePhotosChange, updateVisiblePhotos]);
+
+ useEffect(() => {
+ map.on("moveend", updateVisiblePhotos);
+ map.on("zoomend", updateVisiblePhotos);
+ return () => {
+ map.off("moveend", updateVisiblePhotos);
+ map.off("zoomend", updateVisiblePhotos);
+ };
+ }, [map, updateVisiblePhotos]);
+
+ return null;
+};
+
export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
open,
onClose,
@@ -211,6 +253,8 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
const [thumbByFileID, setThumbByFileID] = useState<Map<number, string>>(
new Map(),
); // map storing the file thumbnails against the fileID for showing the file thumbnails in the left sidebar
+ const [visiblePhotos, setVisiblePhotos] = useState<JourneyPoint[]>([]);
+ const [visiblePhotosWave, setVisiblePhotosWave] = useState(0);
// FileViewer state
const [openFileViewer, setOpenFileViewer] = useState(false);
@@ -234,7 +278,7 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
const photosByDate = useMemo(() => {
const groups = new Map<string, JourneyPoint[]>();
- mapPhotos.forEach((p) => {
+ visiblePhotos.forEach((p) => {
const dateLabel = formatDateLabel(p.timestamp);
if (!groups.has(dateLabel)) {
groups.set(dateLabel, []);
@@ -242,7 +286,15 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
groups.get(dateLabel)!.push(p);
});
return Array.from(groups.entries());
- }, [mapPhotos]);
+ }, [visiblePhotos]);
+
+ const visiblePhotoOrder = useMemo(() => {
+ return new Map(visiblePhotos.map((p, index) => [p.fileId, index]));
+ }, [visiblePhotos]);
+
+ useEffect(() => {
+ setVisiblePhotosWave((wave) => wave + 1);
+ }, [visiblePhotos]);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -528,7 +580,7 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
gap: 0.5,
}}
>
- {mapPhotos.length}{" "}
+ {visiblePhotos.length}{" "}
{t("memories", {
defaultValue: "memories",
})}
@@ -553,54 +605,90 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
</Box>
{/* Scrollable photo content */}
<Stack spacing={1.5}>
- {photosByDate.map(([dateLabel, photos]) => (
- <Stack key={dateLabel} spacing={0.75}>
- <Box
- sx={{
- position: "sticky",
- top: 56,
- bgcolor: (theme) =>
- theme.vars.palette.background.paper,
- zIndex: 2,
- py: 1.5,
- ml: -2,
- mr: -2,
- pr: 2,
- }}
- >
- <Typography
- variant="small"
- color="text.secondary"
+ {visiblePhotos.length ? (
+ photosByDate.map(([dateLabel, photos]) => (
+ <Stack key={dateLabel} spacing={0.75}>
+ <Box
+ sx={{
+ position: "sticky",
+ top: 56,
+ bgcolor: (theme) =>
+ theme.vars.palette.background
+ .paper,
+ zIndex: 2,
+ py: 1.5,
+ ml: -2,
+ mr: -2,
+ pr: 2,
+ }}
>
- {dateLabel}
- </Typography>
- </Box>
- <ThumbRow>
- {photos.map((p, idx) => {
- const thumb = thumbByFileID.get(
- p.fileId,
- );
- if (!thumb) {
+ <Typography
+ variant="small"
+ color="text.secondary"
+ >
+ {dateLabel}
+ </Typography>
+ </Box>
+ <ThumbRow>
+ {photos.map((p, idx) => {
+ const thumb = thumbByFileID.get(
+ p.fileId,
+ );
+ const photoOrderIndex =
+ visiblePhotoOrder.get(
+ p.fileId,
+ ) ?? idx;
+ const animationDelay =
+ photoOrderIndex * 30;
+ if (!thumb) {
+ return (
+ <PlaceholderThumb
+ key={`${p.fileId}-${visiblePhotosWave}`}
+ animationDelay={
+ animationDelay
+ }
+ />
+ );
+ }
return (
- <PlaceholderThumb
- key={p.fileId}
+ <ThumbImage
+ key={`${p.fileId}-${visiblePhotosWave}`}
+ src={thumb}
+ alt={t("view_on_map")}
+ onClick={() =>
+ handlePhotoClick(
+ p.fileId,
+ )
+ }
+ animationDelay={
+ animationDelay
+ }
/>
);
- }
- return (
- <ThumbImage
- key={`${thumb}-${idx}`}
- src={thumb}
- alt={t("view_on_map")}
- onClick={() =>
- handlePhotoClick(p.fileId)
- }
- />
- );
+ })}
+ </ThumbRow>
+ </Stack>
+ ))
+ ) : (
+ <NoVisiblePhotos>
+ <Typography
+ variant="body"
+ sx={{ fontWeight: 600 }}
+ >
+ {t("no_photos_found_here", {
+ defaultValue: "No photos found here",
})}
- </ThumbRow>
- </Stack>
- ))}
+ </Typography>
+ <Typography
+ variant="small"
+ color="text.secondary"
+ >
+ {t("zoom_out_to_see_photos", {
+ defaultValue: "Zoom out to see photos",
+ })}
+ </Typography>
+ </NoVisiblePhotos>
+ )}
</Stack>
</Box>
{/* Map container on the right */}
@@ -619,6 +707,11 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
updateWhenZooming
/>
<MapControls useMap={useMap} onClose={onClose} />
+ <MapViewportListener
+ useMap={useMap}
+ photos={mapPhotos}
+ onVisiblePhotosChange={setVisiblePhotos}
+ />
{clusterMeta.map((cluster, index) => {
const icon = createIcon(
cluster.thumbnail ?? "",
@@ -738,6 +831,17 @@ const CenteredBox: React.FC<CenteredBoxProps> = ({
</Box>
);
+const cascadeFadeIn = keyframes`
+ from {
+ opacity: 0;
+ transform: translate3d(0, 8px, 0) scale(0.99);
+ }
+ to {
+ opacity: 1;
+ transform: translate3d(0, 0, 0) scale(1);
+ }
+`;
+
const ThumbRow: React.FC<React.PropsWithChildren> = ({ children }) => (
<Box
sx={{
@@ -752,14 +856,34 @@ const ThumbRow: React.FC<React.PropsWithChildren> = ({ children }) => (
</Box>
);
+const NoVisiblePhotos: React.FC<React.PropsWithChildren> = ({ children }) => (
+ <Box
+ sx={{
+ minHeight: "100%",
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ justifyContent: "center",
+ textAlign: "center",
+ py: 4,
+ color: (theme) => theme.vars.palette.text.secondary,
+ gap: 0.5,
+ }}
+ >
+ {children}
+ </Box>
+);
+
const ThumbImage = ({
src,
alt,
onClick,
+ animationDelay,
}: {
src: string;
alt: string;
onClick?: () => void;
+ animationDelay: number;
}) => (
<Box
component="img"
@@ -775,12 +899,16 @@ const ThumbImage = ({
border: (theme) => `1px solid ${theme.palette.divider}`,
cursor: onClick ? "pointer" : "default",
transition: "transform 0.15s ease-in-out",
+ opacity: 0,
+ transformOrigin: "top left",
+ animation: `${cascadeFadeIn} 200ms ease-out forwards`,
+ animationDelay: `${animationDelay}ms`,
"&:hover": onClick ? { transform: "scale(1.02)" } : {},
}}
/>
);
-const PlaceholderThumb = () => (
+const PlaceholderThumb = ({ animationDelay }: { animationDelay: number }) => (
<Box
sx={{
width: 140,
@@ -789,6 +917,10 @@ const PlaceholderThumb = () => (
flexShrink: 0,
bgcolor: (theme) => theme.vars.palette.fill.faint,
border: (theme) => `1px solid ${theme.palette.divider}`,
+ opacity: 0,
+ transformOrigin: "top left",
+ animation: `${cascadeFadeIn} 200ms ease-out forwards`,
+ animationDelay: `${animationDelay}ms`,
}}
/>
);
diff --git a/web/yarn.lock b/web/yarn.lock
index 83c9690127..bad4a7f0f2 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -2965,6 +2965,11 @@ leaflet-defaulticon-compatibility@^0.1.2:
resolved "https://registry.yarnpkg.com/leaflet-defaulticon-compatibility/-/leaflet-defaulticon-compatibility-0.1.2.tgz#f5e1a5841aeab9d1682d17887348855a741b3c2a"
integrity sha512-IrKagWxkTwzxUkFIumy/Zmo3ksjuAu3zEadtOuJcKzuXaD76Gwvg2Z1mLyx7y52ykOzM8rAH5ChBs4DnfdGa6Q==
+leaflet.markercluster@^1.5.3:
+ version "1.5.3"
+ resolved "https://registry.yarnpkg.com/leaflet.markercluster/-/leaflet.markercluster-1.5.3.tgz#9cdb52a4eab92671832e1ef9899669e80efc4056"
+ integrity sha512-vPTw/Bndq7eQHjLBVlWpnGeLa3t+3zGiuM7fJwCkiMFq+nmRuG3RI3f7f4N4TDX7T4NpbAXpR2+NTRSEGfCSeA==
+
leaflet@^1.9.4:
version "1.9.4"
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d"
@@ -3490,6 +3495,13 @@ react-is@^19.1.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-19.2.0.tgz#ddc3b4a4e0f3336c3847f18b806506388d7b9973"
integrity sha512-x3Ax3kNSMIIkyVYhWPyO09bu0uttcAIoecO/um/rKGQ4EltYWVYtyiGkS/3xMynrbVQdS69Jhlv8FXUEZehlzA==
+react-leaflet-cluster@^4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/react-leaflet-cluster/-/react-leaflet-cluster-4.0.0.tgz#8a1025fbf4c7f3d39458c4b14f85b992aa4f9a59"
+ integrity sha512-Lu75+KOu2ruGyAx8LoCQvlHuw+3CLLJQGEoSk01ymsDN/YnCiRV6ChkpsvaruVyYBPzUHwiskFw4Jo7WHj5qNw==
+ dependencies:
+ leaflet.markercluster "^1.5.3"
+
react-leaflet@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/react-leaflet/-/react-leaflet-5.0.0.tgz#945d40bad13b69e8606278b19446b00bab57376a"