π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refactor: split main file into componenets
anandbaburajan0c067cecb4ed
diff --git a/web/apps/photos/src/components/TripTemplate/MapContainer.tsx b/web/apps/photos/src/components/TripTemplate/MapContainer.tsxnew file mode 100644index 0000000000..6412ef43b6--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/MapContainer.tsx@@ -0,0 +1,16 @@+import dynamic from "next/dynamic";++export const MapContainer = dynamic(+ () => import("react-leaflet").then((mod) => mod.MapContainer),+ { ssr: false },+);++export const TileLayer = dynamic(+ () => import("react-leaflet").then((mod) => mod.TileLayer),+ { ssr: false },+);++export const Marker = dynamic(+ () => import("react-leaflet").then((mod) => mod.Marker),+ { ssr: false },+);\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/MapEvents.tsx b/web/apps/photos/src/components/TripTemplate/MapEvents.tsxnew file mode 100644index 0000000000..e113392b6c--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/MapEvents.tsx@@ -0,0 +1,34 @@+import { memo, useEffect } from "react";+import { useMap } from "react-leaflet";+import L from "leaflet";++interface MapEventsProps {+ setMapRef: (map: L.Map) => void;+ setCurrentZoom: (zoom: number) => void;+ setTargetZoom: (zoom: number | null) => void;+}++export const MapEvents = memo<MapEventsProps>(({+ setMapRef,+ setCurrentZoom,+ setTargetZoom,+}) => {+ const map = useMap();++ useEffect(() => {+ setMapRef(map);++ const handleZoomEnd = () => {+ setCurrentZoom(map.getZoom());+ setTargetZoom(null);+ };++ map.on("zoomend", handleZoomEnd);++ return () => {+ map.off("zoomend", handleZoomEnd);+ };+ }, [map, setMapRef, setCurrentZoom, setTargetZoom]);++ return null;+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/PhotoFan.tsx b/web/apps/photos/src/components/TripTemplate/PhotoFan.tsxnew file mode 100644index 0000000000..7432f7e772--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/PhotoFan.tsx@@ -0,0 +1,206 @@+import { memo } from "react";+import Image from "next/image";+import { JourneyPoint } from "./types";++interface PhotoFanProps {+ cluster: JourneyPoint[];+ onPhotoClick?: (cluster: JourneyPoint[], fileId: number) => void;+}++export const PhotoFan = memo<PhotoFanProps>(({+ cluster,+ onPhotoClick,+}) => {+ if (cluster.length === 0) {+ return null;+ }++ return (+ <div+ className="photo-fan-hover"+ style={{+ position: "relative",+ width: "180px",+ height: "240px",+ }}+ >+ {cluster.length === 2 && cluster[1] && (+ <div+ onClick={() =>+ cluster[1] &&+ onPhotoClick?.(cluster, cluster[1].fileId)+ }+ style={{+ position: "absolute",+ border: "2px solid white",+ boxShadow:+ "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",+ zIndex: 10,+ width: "180px",+ height: "207px",+ borderRadius: "14px",+ overflow: "hidden",+ transform: "translateX(33px) skewY(8deg)",+ top: "50%",+ left: "0",+ marginTop: "-103.5px",+ cursor: "pointer",+ }}+ >+ <div+ style={{+ position: "relative",+ width: "100%",+ height: "100%",+ transform: "skewY(-8deg) scale(1.1)",+ }}+ >+ <Image+ src={cluster[1].image}+ alt={cluster[1].name}+ fill+ style={{ objectFit: "cover" }}+ sizes="200px"+ />+ </div>+ </div>+ )}+ {cluster.length >= 3 && (+ <>+ {cluster[1] && (+ <div+ onClick={() =>+ cluster[1] &&+ onPhotoClick?.(cluster, cluster[1].fileId)+ }+ style={{+ position: "absolute",+ border: "2px solid white",+ boxShadow:+ "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",+ zIndex: 10,+ width: "180px",+ height: "207px",+ borderRadius: "14px",+ overflow: "hidden",+ transform: "translateX(-33px) skewY(-8deg)",+ top: "16.5px",+ left: "0",+ cursor: "pointer",+ }}+ >+ <div+ style={{+ position: "relative",+ width: "100%",+ height: "100%",+ transform: "skewY(8deg) scale(1.1)",+ }}+ >+ <Image+ src={cluster[1].image}+ alt={cluster[1].name}+ fill+ style={{ objectFit: "cover" }}+ sizes="200px"+ />+ </div>+ </div>+ )}+ {cluster[2] && (+ <div+ onClick={() =>+ cluster[2] &&+ onPhotoClick?.(cluster, cluster[2].fileId)+ }+ style={{+ position: "absolute",+ border: "2px solid white",+ boxShadow:+ "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",+ zIndex: 10,+ width: "180px",+ height: "207px",+ borderRadius: "14px",+ overflow: "hidden",+ transform: "translateX(33px) skewY(8deg)",+ top: "16.5px",+ left: "0",+ cursor: "pointer",+ }}+ >+ <div+ style={{+ position: "relative",+ width: "100%",+ height: "100%",+ transform: "skewY(-8deg) scale(1.1)",+ }}+ >+ <Image+ src={cluster[2].image}+ alt={cluster[2].name}+ fill+ style={{ objectFit: "cover" }}+ sizes="200px"+ />+ </div>+ </div>+ )}+ </>+ )}++ {cluster[0] && (+ <div+ onClick={() =>+ cluster[0] &&+ onPhotoClick?.(cluster, cluster[0].fileId)+ }+ style={{+ position: "relative",+ width: "100%",+ height: "100%",+ border: "2px solid white",+ boxShadow:+ "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",+ zIndex: 20,+ borderRadius: "14px",+ overflow: "hidden",+ cursor: "pointer",+ }}+ >+ <Image+ src={cluster[0].image}+ alt={cluster[0].name}+ fill+ style={{ objectFit: "cover" }}+ sizes="150px"+ />++ {cluster.length > 3 && (+ <div+ style={{+ position: "absolute",+ bottom: "6px",+ right: "6px",+ background: "white",+ color: "black",+ borderRadius: "6px",+ padding: "4px 6px",+ minHeight: "20px",+ display: "inline-flex",+ alignItems: "center",+ justifyContent: "center",+ fontSize: "11px",+ fontWeight: "600",+ boxShadow: "0 1px 3px rgba(0,0,0,0.3)",+ }}+ >+ +{cluster.length - 3}+ </div>+ )}+ </div>+ )}+ </div>+ );+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/TimelineBaseLine.tsx b/web/apps/photos/src/components/TripTemplate/TimelineBaseLine.tsxnew file mode 100644index 0000000000..e13b584573--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/TimelineBaseLine.tsx@@ -0,0 +1,62 @@+import { memo } from "react";++interface TimelineBaseLineProps {+ locationPositions: { top: number; center: number }[];+}++export const TimelineBaseLine = memo<TimelineBaseLineProps>(({+ locationPositions,+}) => {+ const timelineContainer = document.querySelector("#timeline-container");+ if (!timelineContainer || locationPositions.length === 0) {+ return null;+ }++ const locationElements =+ timelineContainer.querySelectorAll(".timeline-location");+ if (locationElements.length === 0) {+ return null;+ }++ const lastLocation = locationElements[+ locationElements.length - 1+ ] as HTMLElement;+ const lastLocationRect = lastLocation.getBoundingClientRect();+ const heightToLastDot =+ lastLocation.offsetTop + lastLocationRect.height / 2;++ const firstLocationCenter = locationPositions[0]?.center || 0;++ return (+ <>+ {/* Long dashed line from trip started dot to first location */}+ <div+ style={{+ position: "absolute",+ left: "50%",+ transform: "translateX(-1.5px)",+ width: "3px",+ backgroundImage:+ "linear-gradient(to bottom, #d1d5db 58%, transparent 58%)",+ backgroundSize: "100% 22px",+ backgroundRepeat: "repeat-y",+ top: "-60px",+ height: `${firstLocationCenter + 60}px`,+ zIndex: 0,+ }}+ />+ {/* Solid line from first location to end */}+ <div+ style={{+ position: "absolute",+ left: "50%",+ transform: "translateX(-1.5px)",+ width: "3px",+ backgroundColor: "#d1d5db",+ top: `${firstLocationCenter}px`,+ height: `${heightToLastDot - firstLocationCenter}px`,+ }}+ />+ </>+ );+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/TimelineLocation.tsx b/web/apps/photos/src/components/TripTemplate/TimelineLocation.tsxnew file mode 100644index 0000000000..ac398b5810--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/TimelineLocation.tsx@@ -0,0 +1,253 @@+import { memo } from "react";+import { JourneyPoint } from "./types";+import { PhotoFan } from "./PhotoFan";++interface TimelineLocationProps {+ cluster: JourneyPoint[];+ index: number;+ photoClusters: JourneyPoint[][];+ scrollProgress: number;+ journeyData: JourneyPoint[];+ onRef: (el: HTMLDivElement | null) => void;+ onPhotoClick?: (cluster: JourneyPoint[], fileId: number) => void;+}++// Component for timeline location item+export const TimelineLocation = memo<TimelineLocationProps>(({+ cluster,+ index,+ photoClusters,+ scrollProgress,+ journeyData,+ onRef,+ onPhotoClick,+}) => {+ const isLeft = index % 2 === 0;+ const firstPhoto = cluster[0];+ if (!firstPhoto) return null;+ const sortedData = [...journeyData].sort(+ (a, b) =>+ new Date(a.timestamp).getTime() -+ new Date(b.timestamp).getTime(),+ );+ const firstData = sortedData[0];+ if (!firstData) return null;+ const firstDate = new Date(firstData.timestamp);+ const photoDate = new Date(firstPhoto.timestamp);++ const firstDateOnly = new Date(+ firstDate.getFullYear(),+ firstDate.getMonth(),+ firstDate.getDate(),+ );+ const photoDateOnly = new Date(+ photoDate.getFullYear(),+ photoDate.getMonth(),+ photoDate.getDate(),+ );+ const diffTime = photoDateOnly.getTime() - firstDateOnly.getTime();+ const dayNumber = Math.floor(diffTime / (1000 * 60 * 60 * 24)) + 1;++ const isReached =+ scrollProgress >= index / Math.max(1, photoClusters.length - 1);++ return (+ <div+ ref={onRef}+ id={`location-${index}`}+ className="timeline-location"+ style={{+ position: "relative",+ display: "flex",+ alignItems: "center",+ marginBottom:+ index === photoClusters.length - 1 ? "24px" : "192px",+ }}+ >+ <div+ style={{+ position: "absolute",+ left: "50%",+ top: "50%",+ transform: "translate(-50%, -50%)",+ width: "24px",+ height: "40px",+ borderRadius: "50%",+ zIndex: 10,+ backgroundColor: "white",+ }}+ ></div>+ <div+ className="timeline-dot"+ style={{+ position: "absolute",+ left: "50%",+ top: "50%",+ transform: "translate(-50%, -50%)",+ borderRadius: "50%",+ border: "2px solid white",+ zIndex: 20,+ width: "12px",+ height: "12px",+ transition: "all 0.3s",+ backgroundColor: isReached ? "#10b981" : "#111827",+ boxShadow: isReached+ ? "0 0 0 3px rgba(34, 197, 94, 0.3), 0 0 0 6px rgba(34, 197, 94, 0.15)"+ : "none",+ }}+ ></div>++ {isLeft ? (+ <>+ <div+ style={{+ width: "50%",+ paddingRight: "32px",+ paddingTop: "58px",+ textAlign: "right",+ }}+ >+ <div+ style={{+ display: "inline-flex",+ alignItems: "center",+ border: "1px solid #e5e7eb",+ borderRadius: "8px",+ padding: "4px 12px",+ marginBottom: "10px",+ }}+ >+ <span+ style={{+ fontSize: "11px",+ fontWeight: "600",+ color: "#4b5563",+ textTransform: "uppercase",+ letterSpacing: "0.15em",+ }}+ >+ DAY {dayNumber} β’{" "}+ {new Date(firstPhoto.timestamp)+ .toLocaleDateString("en-US", {+ month: "long",+ day: "numeric",+ })+ .toUpperCase()}+ </span>+ </div>+ <h3+ style={{+ fontSize: "20px",+ fontWeight: "600",+ color: "#111827",+ textAlign: "right",+ margin: "0",+ lineHeight: "1.2",+ }}+ >+ {firstPhoto.name}+ </h3>+ <p+ style={{+ fontSize: "14px",+ color: "#6b7280",+ textAlign: "right",+ margin: "4px 0 0 0",+ }}+ >+ {firstPhoto.country}+ </p>+ </div>+ <div+ style={{+ width: "50%",+ paddingLeft:+ cluster.length >= 3 ? "72px" : "40px",+ }}+ >+ <PhotoFan+ cluster={cluster}+ onPhotoClick={onPhotoClick}+ />+ </div>+ </>+ ) : (+ <>+ <div+ style={{+ width: "50%",+ display: "flex",+ justifyContent: "flex-end",+ paddingRight:+ cluster.length >= 3 ? "72px" : "40px",+ }}+ >+ <PhotoFan+ cluster={cluster}+ onPhotoClick={onPhotoClick}+ />+ </div>+ <div+ style={{+ width: "50%",+ paddingLeft: "32px",+ paddingTop: "58px",+ textAlign: "left",+ }}+ >+ <div+ style={{+ display: "inline-flex",+ alignItems: "center",+ border: "1px solid #e5e7eb",+ borderRadius: "8px",+ padding: "4px 12px",+ marginBottom: "10px",+ }}+ >+ <span+ style={{+ fontSize: "11px",+ fontWeight: "600",+ color: "#4b5563",+ textTransform: "uppercase",+ letterSpacing: "0.15em",+ }}+ >+ DAY {dayNumber} β’{" "}+ {new Date(firstPhoto.timestamp)+ .toLocaleDateString("en-US", {+ month: "long",+ day: "numeric",+ })+ .toUpperCase()}+ </span>+ </div>+ <h3+ style={{+ fontSize: "20px",+ fontWeight: "600",+ color: "#111827",+ textAlign: "left",+ margin: "0",+ lineHeight: "1.2",+ }}+ >+ {firstPhoto.name}+ </h3>+ <p+ style={{+ fontSize: "14px",+ color: "#6b7280",+ textAlign: "left",+ margin: "4px 0 0 0",+ }}+ >+ {firstPhoto.country}+ </p>+ </div>+ </>+ )}+ </div>+ );+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/TimelineProgressLine.tsx b/web/apps/photos/src/components/TripTemplate/TimelineProgressLine.tsxnew file mode 100644index 0000000000..4da07364a5--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/TimelineProgressLine.tsx@@ -0,0 +1,49 @@+import { memo } from "react";+import { JourneyPoint } from "./types";++interface TimelineProgressLineProps {+ locationPositions: { top: number; center: number }[];+ scrollProgress: number;+ hasUserScrolled: boolean;+ photoClusters: JourneyPoint[][];+}++export const TimelineProgressLine = memo<TimelineProgressLineProps>(({+ locationPositions,+ scrollProgress,+ hasUserScrolled,+ photoClusters,+}) => {+ if (photoClusters.length === 0 || locationPositions.length === 0) {+ return null;+ }++ const firstPosition = locationPositions[0];+ const lastPosition = locationPositions[locationPositions.length - 1];+ if (!firstPosition || !lastPosition) {+ return null;+ }+ const firstLocationCenter = firstPosition.center;+ const lastLocationCenter = lastPosition.center;++ if (scrollProgress <= 0 || !hasUserScrolled) {+ return null;+ }++ return (+ <div+ style={{+ position: "absolute",+ left: "50%",+ transform: "translateX(-1.5px)",+ width: "3px",+ backgroundColor: "#10b981",+ top: `${firstLocationCenter}px`,+ height: `${+ (lastLocationCenter - firstLocationCenter) *+ scrollProgress+ }px`,+ }}+ />+ );+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/TripCover.tsx b/web/apps/photos/src/components/TripTemplate/TripCover.tsxnew file mode 100644index 0000000000..049a67f260--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/TripCover.tsx@@ -0,0 +1,111 @@+import { memo } from "react";+import Image from "next/image";+import { EnteLogo } from "ente-base/components/EnteLogo";+import { JourneyPoint } from "./types";++interface TripCoverProps {+ journeyData: JourneyPoint[];+ photoClusters: JourneyPoint[][];+ albumTitle?: string;+ coverImageUrl?: string | null;+}++export const TripCover = memo<TripCoverProps>(({+ journeyData,+ photoClusters,+ albumTitle,+ coverImageUrl,+}) => {+ const sortedData = [...journeyData].sort(+ (a, b) =>+ new Date(a.timestamp).getTime() -+ new Date(b.timestamp).getTime(),+ );+ const firstData = sortedData[0];+ const lastData = sortedData[sortedData.length - 1];+ if (!firstData || !lastData) {+ return null;+ }+ const firstDate = new Date(firstData.timestamp);+ const lastDate = new Date(lastData.timestamp);+ const diffTime = Math.abs(lastDate.getTime() - firstDate.getTime());+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));+ const monthYear = firstDate.toLocaleDateString("en-US", {+ month: "long",+ year: "numeric",+ });++ return (+ <div style={{ marginBottom: "48px" }}>+ <div+ style={{+ aspectRatio: "16/8",+ position: "relative",+ marginBottom: "12px",+ borderRadius: "24px",+ overflow: "hidden",+ }}+ >+ <Image+ src={coverImageUrl || journeyData[0]?.image || ""}+ alt="Trip Cover"+ fill+ style={{ objectFit: "cover" }}+ sizes="(max-width: 768px) 90vw, (max-width: 1200px) 45vw, 600px"+ />+ <div+ style={{+ position: "absolute",+ inset: 0,+ background:+ "linear-gradient(to bottom, rgba(0,0,0,0.4), transparent 30%, transparent 70%, rgba(0,0,0,0.7))",+ }}+ ></div>++ {/* Ente logo */}+ <div+ style={{+ position: "absolute",+ top: "20px",+ left: "20px",+ color: "#22c55e",+ }}+ >+ <EnteLogo height={24} />+ </div>++ <div+ style={{+ position: "absolute",+ bottom: 0,+ left: 0,+ right: 0,+ padding: "24px",+ color: "white",+ }}+ >+ <h1+ style={{+ fontSize: "30px",+ fontWeight: "bold",+ marginBottom: "2px",+ }}+ >+ {albumTitle || "Trip"}+ </h1>+ <p+ style={{+ color: "rgba(255, 255, 255, 0.8)",+ fontSize: "16px",+ fontWeight: "600",+ margin: "0",+ }}+ >+ {monthYear} β’ {diffDays} days β’{" "}+ {photoClusters.length} locations+ </p>+ </div>+ </div>+ </div>+ );+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/TripStartedSection.tsx b/web/apps/photos/src/components/TripTemplate/TripStartedSection.tsxnew file mode 100644index 0000000000..230b318e0c--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/TripStartedSection.tsx@@ -0,0 +1,80 @@+import { memo } from "react";+import { JourneyPoint } from "./types";++interface TripStartedSectionProps {+ journeyData: JourneyPoint[];+}++export const TripStartedSection = memo<TripStartedSectionProps>(({ journeyData }) => {+ const sortedData = [...journeyData].sort(+ (a, b) =>+ new Date(a.timestamp).getTime() -+ new Date(b.timestamp).getTime(),+ );+ const firstData = sortedData[0];+ if (!firstData) {+ return null;+ }+ const firstDate = new Date(firstData.timestamp);++ return (+ <div+ style={{+ position: "relative",+ marginTop: "32px",+ marginBottom: "100px",+ textAlign: "center",+ zIndex: 1,+ }}+ >+ <div+ style={{+ fontSize: "20px",+ fontWeight: "600",+ color: "#111827",+ marginBottom: "2px",+ lineHeight: "1.2",+ backgroundColor: "white",+ padding: "4px 8px",+ borderRadius: "4px",+ display: "inline-block",+ }}+ >+ Trip started+ </div>+ <br />+ <div+ style={{+ fontSize: "14px",+ color: "#6b7280",+ backgroundColor: "white",+ padding: "2px 6px",+ borderRadius: "4px",+ display: "inline-block",+ marginTop: "0px",+ }}+ >+ {firstDate.toLocaleDateString("en-US", {+ month: "long",+ day: "2-digit",+ })}+ </div>++ {/* Starting dot after some space */}+ <div+ style={{+ position: "absolute",+ left: "50%",+ top: "80px",+ transform: "translate(-50%, 0)",+ borderRadius: "50%",+ border: "2px solid white",+ zIndex: 20,+ width: "12px",+ height: "12px",+ backgroundColor: "#d1d5db",+ }}+ ></div>+ </div>+ );+});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate.tsx b/web/apps/photos/src/components/TripTemplate/index.tsxsimilarity index 69%rename from web/apps/photos/src/components/TripTemplate.tsxrename to web/apps/photos/src/components/TripTemplate/index.tsxindex 5cf3f31f22..c9df5154b2 100644--- a/web/apps/photos/src/components/TripTemplate.tsx+++ b/web/apps/photos/src/components/TripTemplate/index.tsx@@ -2,7 +2,6 @@ import AddPhotoAlternateOutlinedIcon from "@mui/icons-material/AddPhotoAlternateimport FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";import ShareIcon from "@mui/icons-material/Share";import { DownloadStatusNotifications } from "components/DownloadStatusNotifications";-import { EnteLogo } from "ente-base/components/EnteLogo";import { useIsTouchscreen } from "ente-base/components/utils/hooks";import { useSaveGroups } from "ente-gallery/components/utils/save-groups";import { FileViewer } from "ente-gallery/components/viewer/FileViewer";@@ -14,9 +13,7 @@ import { fileFileName } from "ente-media/file-metadata";import { t } from "i18next";import L from "leaflet";import dynamic from "next/dynamic";-import Image from "next/image";import {- memo,startTransition,useCallback,useEffect,@@ -24,22 +21,18 @@ import {useRef,useState,} from "react";-import { useMap } from "react-leaflet";--// Throttle utility function-const throttle = <T extends (...args: unknown[]) => void>(- func: T,- limit: number,-): T => {- let inThrottle = false;- return ((...args: unknown[]) => {- if (!inThrottle) {- func(...(args as Parameters<T>));- inThrottle = true;- setTimeout(() => (inThrottle = false), limit);- }- }) as T;-};++// Import extracted components+import { TripCover } from "./TripCover";+import { TripStartedSection } from "./TripStartedSection";+import { TimelineProgressLine } from "./TimelineProgressLine";+import { TimelineBaseLine } from "./TimelineBaseLine";+import { TimelineLocation } from "./TimelineLocation";+import { MapEvents } from "./MapEvents";++// Import types and utils+import type { JourneyPoint } from "./types";+import { getLocationName, iconCache, throttle } from "./utils";// Dynamically import react-leaflet components to prevent SSR issuesconst MapContainer = dynamic(@@ -55,888 +48,6 @@ const Marker = dynamic({ ssr: false },);-interface JourneyPoint {- lat: number;- lng: number;- name: string;- country: string;- timestamp: string;- image: string;- fileId: number;-}--// Geocoding cache to avoid repeated API calls-const geocodingCache = new Map<string, { place: string; country: string }>();--// Icon cache to avoid recreating identical icons-const iconCache = new Map<string, L.DivIcon>();--interface GeocodingResponse {- features?: {- properties?: {- locality?: string;- neighbourhood?: string;- county?: string;- region?: string;- name?: string;- country?: string;- };- }[];-}--// Reverse geocoding function using Stadia Maps with caching-// Works without API key for localhost development-const getLocationName = async (- lat: number,- lng: number,- photoIndex?: number,-): Promise<{ place: string; country: string }> => {- // Round coordinates to 3 decimal places for cache key (~100m precision)- const roundedLat = Math.round(lat * 1000) / 1000;- const roundedLng = Math.round(lng * 1000) / 1000;- const cacheKey = `${roundedLat},${roundedLng}`;-- // Check cache first- const cached = geocodingCache.get(cacheKey);- if (cached) {- return cached;- }-- try {- const response = await fetch(- `https://api.stadiamaps.com/geocoding/v1/reverse?point.lat=${lat}&point.lon=${lng}`,- );-- if (!response.ok) {- throw new Error(`HTTP error! status: ${response.status}`);- }-- const data = (await response.json()) as GeocodingResponse;-- // Extract location name from the response- const feature = data.features?.[0];- let result: { place: string; country: string };-- if (feature?.properties) {- const props = feature.properties;-- // Build location name with city and state/region for better context- const city = props.locality || props.neighbourhood;-- // Get location name- const locationName =- city || props.county || props.region || props.name || "Unknown";-- // Get country info- const country = props.country || "Unknown";-- result = { place: locationName, country: country };- } else {- // Fallback if no location found- result = {- place: photoIndex- ? `Location ${photoIndex}`- : `Location ${lat.toFixed(2)}, ${lng.toFixed(2)}`,- country: "Unknown",- };- }-- // Cache the result- geocodingCache.set(cacheKey, result);- return result;- } catch {- // Fallback on error- const fallbackResult = {- place: photoIndex ? `Location ${photoIndex}` : `Unknown Location`,- country: "Unknown",- };- // Cache the fallback to avoid repeated failures- geocodingCache.set(cacheKey, fallbackResult);- return fallbackResult;- }-};--// Component to handle map events inside MapContainer-const MapEvents = memo(- ({- setMapRef,- setCurrentZoom,- setTargetZoom,- }: {- setMapRef: (map: L.Map) => void;- setCurrentZoom: (zoom: number) => void;- setTargetZoom: (zoom: number | null) => void;- }) => {- const map = useMap();-- useEffect(() => {- setMapRef(map);-- const handleZoomEnd = () => {- setCurrentZoom(map.getZoom());- setTargetZoom(null);- };-- map.on("zoomend", handleZoomEnd);-- return () => {- map.off("zoomend", handleZoomEnd);- };- }, [map, setMapRef, setCurrentZoom, setTargetZoom]);-- return null;- },-);--// Component for the trip cover section only-const TripCover = memo(- ({- journeyData,- photoClusters,- albumTitle,- coverImageUrl,- }: {- journeyData: JourneyPoint[];- photoClusters: JourneyPoint[][];- albumTitle?: string;- coverImageUrl?: string | null;- }) => {- const sortedData = [...journeyData].sort(- (a, b) =>- new Date(a.timestamp).getTime() -- new Date(b.timestamp).getTime(),- );- const firstData = sortedData[0];- const lastData = sortedData[sortedData.length - 1];- if (!firstData || !lastData) {- return null;- }- const firstDate = new Date(firstData.timestamp);- const lastDate = new Date(lastData.timestamp);- const diffTime = Math.abs(lastDate.getTime() - firstDate.getTime());- const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));- const monthYear = firstDate.toLocaleDateString("en-US", {- month: "long",- year: "numeric",- });-- return (- <div style={{ marginBottom: "48px" }}>- <div- style={{- aspectRatio: "16/8",- position: "relative",- marginBottom: "12px",- borderRadius: "24px",- overflow: "hidden",- }}- >- <Image- src={coverImageUrl || journeyData[0]?.image || ""}- alt="Trip Cover"- fill- style={{ objectFit: "cover" }}- sizes="(max-width: 768px) 90vw, (max-width: 1200px) 45vw, 600px"- />- <div- style={{- position: "absolute",- inset: 0,- background:- "linear-gradient(to bottom, rgba(0,0,0,0.4), transparent 30%, transparent 70%, rgba(0,0,0,0.7))",- }}- ></div>-- {/* Ente logo */}- <div- style={{- position: "absolute",- top: "20px",- left: "20px",- color: "#22c55e",- }}- >- <EnteLogo height={24} />- </div>-- <div- style={{- position: "absolute",- bottom: 0,- left: 0,- right: 0,- padding: "24px",- color: "white",- }}- >- <h1- style={{- fontSize: "30px",- fontWeight: "bold",- marginBottom: "2px",- }}- >- {albumTitle || "Trip"}- </h1>- <p- style={{- color: "rgba(255, 255, 255, 0.8)",- fontSize: "16px",- fontWeight: "600",- margin: "0",- }}- >- {monthYear} β’ {diffDays} days β’{" "}- {photoClusters.length} locations- </p>- </div>- </div>- </div>- );- },-);--// Component for the trip started section-const TripStartedSection = memo(- ({ journeyData }: { journeyData: JourneyPoint[] }) => {- const sortedData = [...journeyData].sort(- (a, b) =>- new Date(a.timestamp).getTime() -- new Date(b.timestamp).getTime(),- );- const firstData = sortedData[0];- if (!firstData) {- return null;- }- const firstDate = new Date(firstData.timestamp);-- return (- <div- style={{- position: "relative",- marginTop: "32px",- marginBottom: "100px",- textAlign: "center",- zIndex: 1,- }}- >- <div- style={{- fontSize: "20px",- fontWeight: "600",- color: "#111827",- marginBottom: "2px",- lineHeight: "1.2",- backgroundColor: "white",- padding: "4px 8px",- borderRadius: "4px",- display: "inline-block",- }}- >- Trip started- </div>- <br />- <div- style={{- fontSize: "14px",- color: "#6b7280",- backgroundColor: "white",- padding: "2px 6px",- borderRadius: "4px",- display: "inline-block",- marginTop: "0px",- }}- >- {firstDate.toLocaleDateString("en-US", {- month: "long",- day: "2-digit",- })}- </div>-- {/* Starting dot after some space */}- <div- style={{- position: "absolute",- left: "50%",- top: "80px",- transform: "translate(-50%, 0)",- borderRadius: "50%",- border: "2px solid white",- zIndex: 20,- width: "12px",- height: "12px",- backgroundColor: "#d1d5db",- }}- ></div>- </div>- );- },-);--// Component for the timeline progress line-const TimelineProgressLine = memo(- ({- locationPositions,- scrollProgress,- hasUserScrolled,- photoClusters,- }: {- locationPositions: { top: number; center: number }[];- scrollProgress: number;- hasUserScrolled: boolean;- photoClusters: JourneyPoint[][];- }) => {- if (photoClusters.length === 0 || locationPositions.length === 0) {- return null;- }-- const firstPosition = locationPositions[0];- const lastPosition = locationPositions[locationPositions.length - 1];- if (!firstPosition || !lastPosition) {- return null;- }- const firstLocationCenter = firstPosition.center;- const lastLocationCenter = lastPosition.center;-- if (scrollProgress <= 0 || !hasUserScrolled) {- return null;- }-- return (- <div- style={{- position: "absolute",- left: "50%",- transform: "translateX(-1.5px)",- width: "3px",- backgroundColor: "#10b981",- top: `${firstLocationCenter}px`,- height: `${- (lastLocationCenter - firstLocationCenter) *- scrollProgress- }px`,- }}- />- );- },-);--// Component for timeline base line-const TimelineBaseLine = memo(- ({- locationPositions,- }: {- locationPositions: { top: number; center: number }[];- }) => {- const timelineContainer = document.querySelector("#timeline-container");- if (!timelineContainer || locationPositions.length === 0) {- return null;- }-- const locationElements =- timelineContainer.querySelectorAll(".timeline-location");- if (locationElements.length === 0) {- return null;- }-- const lastLocation = locationElements[- locationElements.length - 1- ] as HTMLElement;- const lastLocationRect = lastLocation.getBoundingClientRect();- const heightToLastDot =- lastLocation.offsetTop + lastLocationRect.height / 2;-- const firstLocationCenter = locationPositions[0]?.center || 0;-- return (- <>- {/* Long dashed line from trip started dot to first location */}- <div- style={{- position: "absolute",- left: "50%",- transform: "translateX(-1.5px)",- width: "3px",- backgroundImage:- "linear-gradient(to bottom, #d1d5db 58%, transparent 58%)",- backgroundSize: "100% 22px",- backgroundRepeat: "repeat-y",- top: "-60px",- height: `${firstLocationCenter + 60}px`,- zIndex: 0,- }}- />- {/* Solid line from first location to end */}- <div- style={{- position: "absolute",- left: "50%",- transform: "translateX(-1.5px)",- width: "3px",- backgroundColor: "#d1d5db",- top: `${firstLocationCenter}px`,- height: `${heightToLastDot - firstLocationCenter}px`,- }}- />- </>- );- },-);--// Component for photo fan display-const PhotoFan = memo(- ({- cluster,- onPhotoClick,- }: {- cluster: JourneyPoint[];- onPhotoClick?: (cluster: JourneyPoint[], fileId: number) => void;- }) => {- if (cluster.length === 0) {- return null;- }-- return (- <div- className="photo-fan-hover"- style={{- position: "relative",- width: "180px",- height: "240px",- }}- >- {cluster.length === 2 && cluster[1] && (- <div- onClick={() =>- cluster[1] &&- onPhotoClick?.(cluster, cluster[1].fileId)- }- style={{- position: "absolute",- border: "2px solid white",- boxShadow:- "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",- zIndex: 10,- width: "180px",- height: "207px",- borderRadius: "14px",- overflow: "hidden",- transform: "translateX(33px) skewY(8deg)",- top: "50%",- left: "0",- marginTop: "-103.5px",- cursor: "pointer",- }}- >- <div- style={{- position: "relative",- width: "100%",- height: "100%",- transform: "skewY(-8deg) scale(1.1)",- }}- >- <Image- src={cluster[1].image}- alt={cluster[1].name}- fill- style={{ objectFit: "cover" }}- sizes="200px"- />- </div>- </div>- )}- {cluster.length >= 3 && (- <>- {cluster[1] && (- <div- onClick={() =>- cluster[1] &&- onPhotoClick?.(cluster, cluster[1].fileId)- }- style={{- position: "absolute",- border: "2px solid white",- boxShadow:- "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",- zIndex: 10,- width: "180px",- height: "207px",- borderRadius: "14px",- overflow: "hidden",- transform: "translateX(-33px) skewY(-8deg)",- top: "16.5px",- left: "0",- cursor: "pointer",- }}- >- <div- style={{- position: "relative",- width: "100%",- height: "100%",- transform: "skewY(8deg) scale(1.1)",- }}- >- <Image- src={cluster[1].image}- alt={cluster[1].name}- fill- style={{ objectFit: "cover" }}- sizes="200px"- />- </div>- </div>- )}- {cluster[2] && (- <div- onClick={() =>- cluster[2] &&- onPhotoClick?.(cluster, cluster[2].fileId)- }- style={{- position: "absolute",- border: "2px solid white",- boxShadow:- "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",- zIndex: 10,- width: "180px",- height: "207px",- borderRadius: "14px",- overflow: "hidden",- transform: "translateX(33px) skewY(8deg)",- top: "16.5px",- left: "0",- cursor: "pointer",- }}- >- <div- style={{- position: "relative",- width: "100%",- height: "100%",- transform: "skewY(-8deg) scale(1.1)",- }}- >- <Image- src={cluster[2].image}- alt={cluster[2].name}- fill- style={{ objectFit: "cover" }}- sizes="200px"- />- </div>- </div>- )}- </>- )}-- {cluster[0] && (- <div- onClick={() =>- cluster[0] &&- onPhotoClick?.(cluster, cluster[0].fileId)- }- style={{- position: "relative",- width: "100%",- height: "100%",- border: "2px solid white",- boxShadow:- "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",- zIndex: 20,- borderRadius: "14px",- overflow: "hidden",- cursor: "pointer",- }}- >- <Image- src={cluster[0].image}- alt={cluster[0].name}- fill- style={{ objectFit: "cover" }}- sizes="150px"- />-- {cluster.length > 3 && (- <div- style={{- position: "absolute",- bottom: "6px",- right: "6px",- background: "white",- color: "black",- borderRadius: "6px",- padding: "4px 6px",- minHeight: "20px",- display: "inline-flex",- alignItems: "center",- justifyContent: "center",- fontSize: "11px",- fontWeight: "600",- boxShadow: "0 1px 3px rgba(0,0,0,0.3)",- }}- >- +{cluster.length - 3}- </div>- )}- </div>- )}- </div>- );- },-);--// Component for timeline location item-const TimelineLocation = memo(- ({- cluster,- index,- photoClusters,- scrollProgress,- journeyData,- onRef,- onPhotoClick,- }: {- cluster: JourneyPoint[];- index: number;- photoClusters: JourneyPoint[][];- scrollProgress: number;- journeyData: JourneyPoint[];- onRef: (el: HTMLDivElement | null) => void;- onPhotoClick?: (cluster: JourneyPoint[], fileId: number) => void;- }) => {- const isLeft = index % 2 === 0;- const firstPhoto = cluster[0];- if (!firstPhoto) return null;- const sortedData = [...journeyData].sort(- (a, b) =>- new Date(a.timestamp).getTime() -- new Date(b.timestamp).getTime(),- );- const firstData = sortedData[0];- if (!firstData) return null;- const firstDate = new Date(firstData.timestamp);- const photoDate = new Date(firstPhoto.timestamp);-- const firstDateOnly = new Date(- firstDate.getFullYear(),- firstDate.getMonth(),- firstDate.getDate(),- );- const photoDateOnly = new Date(- photoDate.getFullYear(),- photoDate.getMonth(),- photoDate.getDate(),- );- const diffTime = photoDateOnly.getTime() - firstDateOnly.getTime();- const dayNumber = Math.floor(diffTime / (1000 * 60 * 60 * 24)) + 1;-- const isReached =- scrollProgress >= index / Math.max(1, photoClusters.length - 1);-- return (- <div- ref={onRef}- id={`location-${index}`}- className="timeline-location"- style={{- position: "relative",- display: "flex",- alignItems: "center",- marginBottom:- index === photoClusters.length - 1 ? "24px" : "192px",- }}- >- <div- style={{- position: "absolute",- left: "50%",- top: "50%",- transform: "translate(-50%, -50%)",- width: "24px",- height: "40px",- borderRadius: "50%",- zIndex: 10,- backgroundColor: "white",- }}- ></div>- <div- className="timeline-dot"- style={{- position: "absolute",- left: "50%",- top: "50%",- transform: "translate(-50%, -50%)",- borderRadius: "50%",- border: "2px solid white",- zIndex: 20,- width: "12px",- height: "12px",- transition: "all 0.3s",- backgroundColor: isReached ? "#10b981" : "#111827",- boxShadow: isReached- ? "0 0 0 3px rgba(34, 197, 94, 0.3), 0 0 0 6px rgba(34, 197, 94, 0.15)"- : "none",- }}- ></div>-- {isLeft ? (- <>- <div- style={{- width: "50%",- paddingRight: "32px",- paddingTop: "58px",- textAlign: "right",- }}- >- <div- style={{- display: "inline-flex",- alignItems: "center",- border: "1px solid #e5e7eb",- borderRadius: "8px",- padding: "4px 12px",- marginBottom: "10px",- }}- >- <span- style={{- fontSize: "11px",- fontWeight: "600",- color: "#4b5563",- textTransform: "uppercase",- letterSpacing: "0.15em",- }}- >- DAY {dayNumber} β’{" "}- {new Date(firstPhoto.timestamp)- .toLocaleDateString("en-US", {- month: "long",- day: "numeric",- })- .toUpperCase()}- </span>- </div>- <h3- style={{- fontSize: "20px",- fontWeight: "600",- color: "#111827",- textAlign: "right",- margin: "0",- lineHeight: "1.2",- }}- >- {firstPhoto.name}- </h3>- <p- style={{- fontSize: "14px",- color: "#6b7280",- textAlign: "right",- margin: "4px 0 0 0",- }}- >- {firstPhoto.country}- </p>- </div>- <div- style={{- width: "50%",- paddingLeft:- cluster.length >= 3 ? "72px" : "40px",- }}- >- <PhotoFan- cluster={cluster}- onPhotoClick={onPhotoClick}- />- </div>- </>- ) : (- <>- <div- style={{- width: "50%",- display: "flex",- justifyContent: "flex-end",- paddingRight:- cluster.length >= 3 ? "72px" : "40px",- }}- >- <PhotoFan- cluster={cluster}- onPhotoClick={onPhotoClick}- />- </div>- <div- style={{- width: "50%",- paddingLeft: "32px",- paddingTop: "58px",- textAlign: "left",- }}- >- <div- style={{- display: "inline-flex",- alignItems: "center",- border: "1px solid #e5e7eb",- borderRadius: "8px",- padding: "4px 12px",- marginBottom: "10px",- }}- >- <span- style={{- fontSize: "11px",- fontWeight: "600",- color: "#4b5563",- textTransform: "uppercase",- letterSpacing: "0.15em",- }}- >- DAY {dayNumber} β’{" "}- {new Date(firstPhoto.timestamp)- .toLocaleDateString("en-US", {- month: "long",- day: "numeric",- })- .toUpperCase()}- </span>- </div>- <h3- style={{- fontSize: "20px",- fontWeight: "600",- color: "#111827",- textAlign: "left",- margin: "0",- lineHeight: "1.2",- }}- >- {firstPhoto.name}- </h3>- <p- style={{- fontSize: "14px",- color: "#6b7280",- textAlign: "left",- margin: "4px 0 0 0",- }}- >- {firstPhoto.country}- </p>- </div>- </>- )}- </div>- );- },-);-interface TripTemplateProps {files: EnteFile[];collection?: Collection;@@ -2639,14 +1750,6 @@ export const TripTemplate: React.FC<TripTemplateProps> = ({photoClusters[clusterIdx] || [],);- // Find the most recent photo/place- const mostRecentPhotos = [- ...allPhotosInSuperCluster,- ].sort((a, b) => {- const timeA = new Date(a.timestamp).getTime();- const timeB = new Date(b.timestamp).getTime();- return timeB - timeA;- });// Check if this super-cluster has been reachedconst firstClusterIndex =@@ -2776,4 +1879,4 @@ export const TripTemplate: React.FC<TripTemplateProps> = ({/></div>);-};+};\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/types.ts b/web/apps/photos/src/components/TripTemplate/types.tsnew file mode 100644index 0000000000..fbb9a8cb1e--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/types.ts@@ -0,0 +1,36 @@+import { type Collection } from "ente-media/collection";+import { type EnteFile } from "ente-media/file";++export interface JourneyPoint {+ lat: number;+ lng: number;+ name: string;+ country: string;+ timestamp: string;+ image: string;+ fileId: number;+}++export interface GeocodingResponse {+ features?: {+ properties?: {+ locality?: string;+ neighbourhood?: string;+ county?: string;+ region?: string;+ name?: string;+ country?: string;+ };+ }[];+}++export interface TripTemplateProps {+ files: EnteFile[];+ collection?: Collection;+ albumTitle?: string;+ user?: { id: number; email: string; token: string; [key: string]: unknown };+ enableDownload?: boolean;+ onSetOpenFileViewer?: (open: boolean) => void;+ onRemotePull?: () => Promise<void>;+ onAddPhotos?: () => void;+}\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/utils.ts b/web/apps/photos/src/components/TripTemplate/utils.tsnew file mode 100644index 0000000000..21fec9ba36--- /dev/null+++ b/web/apps/photos/src/components/TripTemplate/utils.ts@@ -0,0 +1,104 @@+import L from "leaflet";+import { GeocodingResponse } from "./types";++// Geocoding cache to avoid repeated API calls+export const geocodingCache = new Map<string, { place: string; country: string }>();++// Icon cache to avoid recreating identical icons+export const iconCache = new Map<string, L.DivIcon>();++// Throttle function for performance optimization+export const throttle = <T extends (...args: any[]) => void>(+ func: T,+ delay: number+): ((...args: Parameters<T>) => void) => {+ let timeoutId: NodeJS.Timeout | null = null;+ let lastExecTime = 0;++ return (...args: Parameters<T>) => {+ const currentTime = Date.now();++ if (currentTime - lastExecTime > delay) {+ func(...args);+ lastExecTime = currentTime;+ } else {+ if (timeoutId) clearTimeout(timeoutId);+ timeoutId = setTimeout(() => {+ func(...args);+ lastExecTime = Date.now();+ }, delay - (currentTime - lastExecTime));+ }+ };+};++// Reverse geocoding function using Stadia Maps with caching+// Works without API key for localhost development+export const getLocationName = async (+ lat: number,+ lng: number,+ photoIndex?: number,+): Promise<{ place: string; country: string }> => {+ // Round coordinates to 3 decimal places for cache key (~100m precision)+ const roundedLat = Math.round(lat * 1000) / 1000;+ const roundedLng = Math.round(lng * 1000) / 1000;+ const cacheKey = `${roundedLat},${roundedLng}`;++ // Check cache first+ const cached = geocodingCache.get(cacheKey);+ if (cached) {+ return cached;+ }++ try {+ const response = await fetch(+ `https://api.stadiamaps.com/geocoding/v1/reverse?point.lat=${lat}&point.lon=${lng}`,+ );++ if (!response.ok) {+ throw new Error(`HTTP error! status: ${response.status}`);+ }++ const data = (await response.json()) as GeocodingResponse;++ // Extract location name from the response+ const feature = data.features?.[0];+ let result: { place: string; country: string };++ if (feature?.properties) {+ const props = feature.properties;++ // Build location name with city and state/region for better context+ const city = props.locality || props.neighbourhood;++ // Get location name+ const locationName =+ city || props.county || props.region || props.name || "Unknown";++ // Get country info+ const country = props.country || "Unknown";++ result = { place: locationName, country: country };+ } else {+ // Fallback if no location found+ result = {+ place: photoIndex+ ? `Location ${photoIndex}`+ : `Location ${lat.toFixed(2)}, ${lng.toFixed(2)}`,+ country: "Unknown",+ };+ }++ // Cache the result+ geocodingCache.set(cacheKey, result);+ return result;+ } catch {+ // Fallback on error+ const fallbackResult = {+ place: photoIndex ? `Location ${photoIndex}` : `Unknown Location`,+ country: "Unknown",+ };+ // Cache the fallback to avoid repeated failures+ geocodingCache.set(cacheKey, fallbackResult);+ return fallbackResult;+ }+};\ No newline at end of file