Skip to content

armgit / ente

Public Imported from GitHub
0

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

Align TripMapComponent type with TripMap props and remove unused code

Anand Baburajan7d5b68fd07a3
diff --git a/web/apps/photos/src/components/TripLayout/index.tsx b/web/apps/photos/src/components/TripLayout/index.tsx
index bcd01f3ef6..c265c81297 100644
--- a/web/apps/photos/src/components/TripLayout/index.tsx
+++ b/web/apps/photos/src/components/TripLayout/index.tsx
@@ -90,7 +90,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
const [isInitialLoad, setIsInitialLoad] = useState(true);
const [currentZoom, setCurrentZoom] = useState(7); // Default zoom, will be updated by MapEvents and optimalZoom
const [mapRef, setMapRef] = useState<import("leaflet").Map | null>(null);
- const [targetZoom, setTargetZoom] = useState<number | null>(null);
+ const [, setTargetZoom] = useState<number | null>(null); // Only setter is used by child components
const [scrollProgress, setScrollProgress] = useState(0); // 0 to 1 representing scroll progress
const [hasUserScrolled, setHasUserScrolled] = useState(false); // Track if user has actually scrolled
const [showMobileCover, setShowMobileCover] = useState(true); // Track mobile cover state
@@ -111,36 +111,13 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
const [photoClusters, setPhotoClusters] = useState<JourneyPoint[][]>([]);
const [optimalZoom, setOptimalZoom] = useState(7);
- const [superClusterInfo, setSuperClusterInfo] = useState<{
- superClusters: {
- lat: number;
- lng: number;
- clusterCount: number;
- clustersInvolved: number[];
- image: string;
- }[];
- clusterToSuperClusterMap: Map<number, number>;
- }>({ superClusters: [], clusterToSuperClusterMap: new Map() });
const [TripMapComponent, setTripMapComponent] =
useState<React.ComponentType<{
journeyData: JourneyPoint[];
photoClusters: JourneyPoint[][];
hasPhotoData: boolean;
optimalZoom: number;
- currentZoom: number;
- targetZoom: number | null;
- mapRef: import("leaflet").Map | null;
scrollProgress: number;
- superClusterInfo?: {
- superClusters: {
- lat: number;
- lng: number;
- clusterCount: number;
- clustersInvolved: number[];
- image: string;
- }[];
- clusterToSuperClusterMap: Map<number, number>;
- };
setMapRef: (map: import("leaflet").Map | null) => void;
setCurrentZoom: (zoom: number) => void;
setTargetZoom: (zoom: number | null) => void;
@@ -184,12 +161,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
setPhotoClusters(sortedClusters);
setOptimalZoom(optimalZoomLevel);
-
- // Super clusters disabled for all devices
- setSuperClusterInfo({
- superClusters: [],
- clusterToSuperClusterMap: new Map(),
- });
},
);
}
@@ -313,11 +284,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
photoClusters={photoClusters}
hasPhotoData={hasPhotoData}
optimalZoom={optimalZoom}
- currentZoom={currentZoom}
- targetZoom={targetZoom}
- mapRef={mapRef}
scrollProgress={scrollProgress}
- superClusterInfo={superClusterInfo}
setMapRef={setMapRef}
setCurrentZoom={setCurrentZoom}
setTargetZoom={setTargetZoom}
@@ -508,11 +475,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
photoClusters={photoClusters}
hasPhotoData={hasPhotoData}
optimalZoom={optimalZoom}
- currentZoom={currentZoom}
- targetZoom={targetZoom}
- mapRef={mapRef}
scrollProgress={scrollProgress}
- superClusterInfo={superClusterInfo}
setMapRef={setMapRef}
setCurrentZoom={setCurrentZoom}
setTargetZoom={setTargetZoom}
diff --git a/web/apps/photos/src/components/TripLayout/mapHelpers.ts b/web/apps/photos/src/components/TripLayout/mapHelpers.ts
index 17cb6c39a0..1a4b36ee32 100644
--- a/web/apps/photos/src/components/TripLayout/mapHelpers.ts
+++ b/web/apps/photos/src/components/TripLayout/mapHelpers.ts
@@ -207,305 +207,6 @@ export const createIcon = (
return icon;
};
-// Function to create super-cluster icon with background markers
-export const createSuperClusterIcon = (
- imageSrc: string,
- clusterCount: number,
- size = 45,
- isReached = false,
-): import("leaflet").DivIcon | null => {
- const leaflet = getLeaflet();
- if (typeof window === "undefined" || !leaflet) {
- // Fallback icon for SSR
- return null;
- }
-
- // Create cache key based on all parameters
- const cacheKey = `super_icon_${imageSrc}_${clusterCount}_${size}_${isReached}`;
-
- const cachedIcon = iconCache.get(cacheKey);
- if (cachedIcon) {
- return cachedIcon;
- }
-
- const pinSize = size + 16; // Make it square and bigger
- const pinHeight = pinSize + 12; // Add space for triangle
- const triangleHeight = 10;
- const containerSize = pinSize + 18; // Account for stacked markers
- const hasImage = imageSrc && imageSrc.trim() !== "";
-
- // Generate stacked marker positions for background markers
- const generateStackedMarkerPositions = (count: number) => {
- const positions = [];
- const numBackgroundMarkers = Math.min(count - 1, 3); // Show up to 3 background markers
-
- // Create a stacked effect with slight offsets
- for (let i = 0; i < numBackgroundMarkers; i++) {
- const offsetX = (i + 1) * 4; // Horizontal offset for stack effect
- const offsetY = (i + 1) * 3; // Vertical offset for stack effect
- positions.push({ x: offsetX, y: offsetY });
- }
- return positions;
- };
-
- const backgroundMarkerPositions =
- generateStackedMarkerPositions(clusterCount);
-
- // Define progressively darker gray shades (no transparency)
- const getStackedMarkerColor = (index: number) => {
- // White for first, then progressively darker grays
- const grayShades = ["#ffffff", "#d1d5db", "#b8bcc4", "#9ca3af"];
- return grayShades[Math.min(index, grayShades.length - 1)];
- };
-
- const icon = leaflet.divIcon({
- html: `
- <div class="super-cluster-container" style="
- width: ${containerSize}px;
- height: ${pinHeight + 12}px;
- position: relative;
- cursor: pointer;
- ">
- ${backgroundMarkerPositions
- .map((pos, index) => {
- // Index 0 is second marker (first background), so add 1
- const colorIndex = index + 1;
- const markerColor = getStackedMarkerColor(colorIndex);
- return `
- <!-- Background marker ${index} -->
- <div style="
- position: absolute;
- left: ${pos.x}px;
- top: ${pos.y}px;
- width: ${pinSize}px;
- height: ${pinHeight}px;
- z-index: ${5 - index};
- ">
- <!-- Background pin rounded rectangle -->
- <div style="
- width: ${pinSize}px;
- height: ${pinSize}px;
- border-radius: 16px;
- background: ${markerColor};
- border: 2px solid ${markerColor};
- padding: 4px;
- position: relative;
- overflow: hidden;
- ">
- <!-- Empty background pin -->
- <div style="
- width: 100%;
- height: 100%;
- border-radius: 12px;
- background: ${markerColor};
- "></div>
- </div>
-
- <!-- Background pin triangle -->
- <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 ${markerColor};
- "></div>
- </div>
- `;
- })
- .join("")}
-
- <!-- Main pin container -->
- <div class="photo-pin${isReached ? " reached" : ""}" style="
- width: ${pinSize}px;
- height: ${pinHeight}px;
- position: absolute;
- left: 0px;
- top: 0;
- transition: all 0.3s ease;
- z-index: 10;
- ">
- <!-- Main rounded rectangle container -->
- <div style="
- width: ${pinSize}px;
- height: ${pinSize}px;
- border-radius: 16px;
- background: ${isReached ? "#22c55e" : "white"};
- border: 2px solid ${isReached ? "#22c55e" : "#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='${isReached ? "#22c55e" : "white"}'; this.style.borderColor='${isReached ? "#22c55e" : "#ffffff"}'; this.nextElementSibling.style.borderTopColor='${isReached ? "#22c55e" : "white"}';"
- >
- ${
- hasImage
- ? `
- <!-- Image inside the rounded rectangle -->
- <img
- src="${imageSrc}"
- style="
- width: 100%;
- height: 100%;
- object-fit: cover;
- border-radius: 12px;
- "
- alt="Location"
- />
- `
- : `
- <!-- Loading skeleton when no image -->
- <div style="
- width: 100%;
- height: 100%;
- border-radius: 12px;
- 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>
-
- <!-- Triangle at the bottom -->
- <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 ${isReached ? "#22c55e" : "white"};
- transition: border-top-color 0.3s ease;
- "></div>
- </div>
- </div>
- `,
- className: "super-cluster-pin-marker",
- iconSize: [containerSize, pinHeight + 12],
- iconAnchor: [containerSize / 2, pinHeight + 12],
- popupAnchor: [0, -(pinHeight + 12)],
- });
-
- // Cache the icon
- iconCache.set(cacheKey, icon);
- return icon;
-};
-
-// Calculate super-clusters based on screen collisions
-export const detectScreenCollisions = (
- clusters: JourneyPoint[][],
- zoom: number,
- targetZoom: number | null,
- mapRef: import("leaflet").Map | null,
- optimalZoom: number,
-) => {
- // Use target zoom if we're in the middle of a zoom animation, otherwise use optimal zoom
- const effectiveZoom =
- targetZoom !== null ? targetZoom : mapRef ? zoom : optimalZoom;
-
- // Convert geographic distance to screen pixels
- // At zoom Z, roughly 2^Z * 256 pixels per 360 degrees
- const pixelsPerDegree = (Math.pow(2, effectiveZoom) * 256) / 360;
- // Use a more conservative collision threshold to show more individual clusters
- const collisionThreshold = 50 / pixelsPerDegree; // 50 pixel collision radius
-
- const superClusters: {
- lat: number;
- lng: number;
- clusterCount: number;
- clustersInvolved: number[];
- image: string;
- }[] = [];
- const hiddenClusterIndices = new Set<number>();
-
- // Check each cluster against others for screen-space collision
- clusters.forEach((cluster, i) => {
- if (hiddenClusterIndices.has(i)) return;
-
- const clusterLat =
- cluster.reduce((sum, p) => sum + p.lat, 0) / cluster.length;
- const clusterLng =
- cluster.reduce((sum, p) => sum + p.lng, 0) / cluster.length;
-
- const overlappingClusters = [i];
-
- clusters.forEach((otherCluster, j) => {
- if (i === j || hiddenClusterIndices.has(j)) return;
-
- const otherLat =
- otherCluster.reduce((sum, p) => sum + p.lat, 0) /
- otherCluster.length;
- const otherLng =
- otherCluster.reduce((sum, p) => sum + p.lng, 0) /
- otherCluster.length;
-
- const distance = Math.sqrt(
- Math.pow(clusterLat - otherLat, 2) +
- Math.pow(clusterLng - otherLng, 2),
- );
-
- if (distance < collisionThreshold) {
- overlappingClusters.push(j);
- hiddenClusterIndices.add(j);
- }
- });
-
- // If we found overlapping clusters, create a super-cluster
- if (overlappingClusters.length > 1) {
- hiddenClusterIndices.add(i); // Hide the original cluster too
-
- // Calculate center position of all overlapping clusters
- let totalLat = 0,
- totalLng = 0;
- overlappingClusters.forEach((idx) => {
- const c = clusters[idx];
- if (!c) return;
- totalLat += c.reduce((sum, p) => sum + p.lat, 0) / c.length;
- totalLng += c.reduce((sum, p) => sum + p.lng, 0) / c.length;
- });
-
- // Get the first photo from the first cluster as representative image
- const firstClusterIdx = overlappingClusters[0];
- const firstCluster =
- firstClusterIdx !== undefined
- ? clusters[firstClusterIdx]
- : undefined;
- const representativePhoto = firstCluster?.[0];
- if (!representativePhoto) {
- return;
- }
-
- superClusters.push({
- lat: totalLat / overlappingClusters.length,
- lng: totalLng / overlappingClusters.length,
- clusterCount: overlappingClusters.length,
- clustersInvolved: overlappingClusters,
- image: representativePhoto.image,
- });
- }
- });
-
- // Return visible clusters with their original indices preserved
- const visibleClustersWithIndices = clusters
- .map((cluster, originalIndex) => ({ cluster, originalIndex }))
- .filter((item) => !hiddenClusterIndices.has(item.originalIndex));
-
- return { superClusters, visibleClustersWithIndices };
-};
-
// Calculate map center with first location positioned at 20% from right edge
export const getMapCenter = (
photoClusters: JourneyPoint[][],