π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: optimise thumbnail loading for first load
anandbaburajanb20f075a9ea6
diff --git a/web/apps/photos/src/components/TripTemplate/PhotoFan.tsx b/web/apps/photos/src/components/TripTemplate/PhotoFan.tsxindex 8658565b32..a91f62dc48 100644--- a/web/apps/photos/src/components/TripTemplate/PhotoFan.tsx+++ b/web/apps/photos/src/components/TripTemplate/PhotoFan.tsx@@ -25,14 +25,17 @@ export const PhotoFan = memo<PhotoFanProps>(({onPhotoClick?.(cluster, cluster[1].fileId)}>+ <BackgroundLoadingBox /><ImageWrapper sx={{ transform: 'skewY(-8deg) scale(1.1)' }}>- <Image- src={cluster[1].image}- alt={cluster[1].name}- fill- style={{ objectFit: "cover" }}- sizes="200px"- />+ {cluster[1].image && cluster[1].image.trim() !== "" && (+ <Image+ src={cluster[1].image}+ alt={cluster[1].name}+ fill+style={{ objectFit: "cover", zIndex: 1 }}+ sizes="200px"+ />+ )}</ImageWrapper></PhotoFrameTwo>)}@@ -45,14 +48,17 @@ export const PhotoFan = memo<PhotoFanProps>(({onPhotoClick?.(cluster, cluster[1].fileId)}>+ <BackgroundLoadingBox /><ImageWrapper sx={{ transform: 'skewY(8deg) scale(1.1)' }}>- <Image- src={cluster[1].image}- alt={cluster[1].name}- fill- style={{ objectFit: "cover" }}- sizes="200px"- />+ {cluster[1].image && cluster[1].image.trim() !== "" && (+ <Image+ src={cluster[1].image}+ alt={cluster[1].name}+ fill+ style={{ objectFit: "cover", zIndex: 1 }}+ sizes="200px"+ />+ )}</ImageWrapper></PhotoFrameLeft>)}@@ -63,14 +69,17 @@ export const PhotoFan = memo<PhotoFanProps>(({onPhotoClick?.(cluster, cluster[2].fileId)}>+ <BackgroundLoadingBox /><ImageWrapper sx={{ transform: 'skewY(-8deg) scale(1.1)' }}>- <Image- src={cluster[2].image}- alt={cluster[2].name}- fill- style={{ objectFit: "cover" }}- sizes="200px"- />+ {cluster[2].image && cluster[2].image.trim() !== "" && (+ <Image+ src={cluster[2].image}+ alt={cluster[2].name}+ fill+ style={{ objectFit: "cover", zIndex: 1 }}+ sizes="200px"+ />+ )}</ImageWrapper></PhotoFrameRight>)}@@ -84,13 +93,17 @@ export const PhotoFan = memo<PhotoFanProps>(({onPhotoClick?.(cluster, cluster[0].fileId)}>- <Image- src={cluster[0].image}- alt={cluster[0].name}- fill- style={{ objectFit: "cover" }}- sizes="150px"- />+ {cluster[0].image && cluster[0].image.trim() !== "" ? (+ <Image+ src={cluster[0].image}+ alt={cluster[0].name}+ fill+ style={{ objectFit: "cover" }}+ sizes="150px"+ />+ ) : (+ <LoadingBox />+ )}{cluster.length > 3 && (<CountBadge>@@ -179,4 +192,32 @@ const CountBadge = styled(Box)({fontSize: "11px",fontWeight: "600",boxShadow: "0 1px 3px rgba(0,0,0,0.3)",+});++const LoadingBox = styled(Box)({+ width: "100%",+ height: "100%",+ borderRadius: "12px",+ animation: "skeleton-pulse 1.5s ease-in-out infinite",+ "@keyframes skeleton-pulse": {+ "0%": { backgroundColor: "#ffffff" },+ "50%": { backgroundColor: "#f0f0f0" },+ "100%": { backgroundColor: "#ffffff" }+ },+});++const BackgroundLoadingBox = styled(Box)({+ position: "absolute",+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ borderRadius: "12px",+ zIndex: 0,+ animation: "skeleton-pulse 1.5s ease-in-out infinite",+ "@keyframes skeleton-pulse": {+ "0%": { backgroundColor: "#ffffff" },+ "50%": { backgroundColor: "#f0f0f0" },+ "100%": { backgroundColor: "#ffffff" }+ },});\ No newline at end of filediff --git a/web/apps/photos/src/components/TripTemplate/TripCover.tsx b/web/apps/photos/src/components/TripTemplate/TripCover.tsxindex f97c576ec4..ffce50672a 100644--- a/web/apps/photos/src/components/TripTemplate/TripCover.tsx+++ b/web/apps/photos/src/components/TripTemplate/TripCover.tsx@@ -1,7 +1,7 @@-import { Box, Typography, styled } from "@mui/material";-import { memo } from "react";-import Image from "next/image";+import { Box, Skeleton, styled, Typography } from "@mui/material";import { EnteLogo } from "ente-base/components/EnteLogo";+import Image from "next/image";+import { memo } from "react";import type { JourneyPoint } from "./types";interface TripCoverProps {@@ -11,65 +11,91 @@ interface TripCoverProps {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",- });+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 (- <CoverContainer>- <CoverImageContainer>- <Image- src={coverImageUrl || journeyData[0]?.image || ""}- alt="Trip Cover"- fill- style={{ objectFit: "cover" }}- sizes="(max-width: 768px) 90vw, (max-width: 1200px) 45vw, 600px"- />- <GradientOverlay />+ return (+ <CoverContainer>+ <CoverImageContainer>+ {coverImageUrl ? (+ <>+ <Image+ src={coverImageUrl}+ alt="Trip Cover"+ fill+ style={{ objectFit: "cover" }}+ sizes="(max-width: 768px) 90vw, (max-width: 1200px) 45vw, 600px"+ />+ <GradientOverlay />+ </>+ ) : (+ <Skeleton+ variant="rectangular"+ width="100%"+ height="100%"+ sx={{ bgcolor: "#f5f5f5" }}+ />+ )}- <LogoContainer>- <EnteLogo height={24} />- </LogoContainer>+ <LogoContainer>+ <EnteLogo height={24} />+ </LogoContainer>- <ContentContainer>- <TripTitle>- {albumTitle || "Trip"}- </TripTitle>- <TripSubtitle>- {monthYear} β’ {diffDays} days β’{" "}- {photoClusters.length} locations- </TripSubtitle>- </ContentContainer>- </CoverImageContainer>- </CoverContainer>- );-});+ <ContentContainer>+ {coverImageUrl ? (+ <>+ <TripTitle>{albumTitle || "Trip"}</TripTitle>+ <TripSubtitle>+ {monthYear} β’ {diffDays} days β’{" "}+ {photoClusters.length} locations+ </TripSubtitle>+ </>+ ) : (+ <>+ <Skeleton+ variant="text"+ width="200px"+ height="40px"+ sx={{+ mb: "5px",+ bgcolor: "rgba(255,255,255,0.95)",+ }}+ />+ <Skeleton+ variant="text"+ width="270px"+ height="24px"+ sx={{ bgcolor: "rgba(255,255,255,0.7)" }}+ />+ </>+ )}+ </ContentContainer>+ </CoverImageContainer>+ </CoverContainer>+ );+ },+);// Styled components-const CoverContainer = styled(Box)({- marginBottom: "48px",-});+const CoverContainer = styled(Box)({ marginBottom: "48px" });const CoverImageContainer = styled(Box)({aspectRatio: "16/8",@@ -77,6 +103,7 @@ const CoverImageContainer = styled(Box)({marginBottom: "12px",borderRadius: "24px",overflow: "hidden",+ backgroundColor: "#e0e0e0",});const GradientOverlay = styled(Box)({@@ -105,7 +132,7 @@ const ContentContainer = styled(Box)({const TripTitle = styled(Typography)({fontSize: "30px",fontWeight: "bold",- marginBottom: "12px",+ marginBottom: "16px",component: "h1",});@@ -114,4 +141,4 @@ const TripSubtitle = styled(Typography)({fontSize: "16px",fontWeight: "600",margin: "0",-});\ No newline at end of file+});diff --git a/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts b/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.tsindex 356ccaa31c..e56423c2cf 100644--- a/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts+++ b/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts@@ -18,7 +18,7 @@ export const useThumbnailGeneration = ({thumbnailsGeneratedRef,setJourneyData,}: UseThumbnailGenerationParams) => {- // Generate thumbnails for needed photos+ // Generate thumbnails for needed photos with progressive loadinguseEffect(() => {const generateThumbs = async () => {if (photoClusters.length === 0 || thumbnailsGeneratedRef.current) return;diff --git a/web/apps/photos/src/components/TripTemplate/mapHelpers.ts b/web/apps/photos/src/components/TripTemplate/mapHelpers.tsindex b0d70b2c97..e976c77ef8 100644--- a/web/apps/photos/src/components/TripTemplate/mapHelpers.ts+++ b/web/apps/photos/src/components/TripTemplate/mapHelpers.ts@@ -186,6 +186,7 @@ export const createIcon = (const pinSize = size + 16; // Make it square and biggerconst pinHeight = pinSize + 12; // Add space for triangleconst triangleHeight = 10;+ const hasImage = imageSrc && imageSrc.trim() !== "";const icon = L.divIcon({html: `@@ -212,17 +213,34 @@ export const createIcon = (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"}';">- <!-- Image inside the rounded rectangle -->- <img- src="${imageSrc}"- style="+ ${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%;- object-fit: cover;border-radius: 12px;- "- alt="Location"- />+ 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 -->@@ -276,6 +294,7 @@ export const createSuperClusterIcon = (const pinHeight = pinSize + 12; // Add space for triangleconst triangleHeight = 10;const containerSize = pinSize + 24;+ const hasImage = imageSrc && imageSrc.trim() !== "";const icon = L.divIcon({html: `@@ -310,17 +329,34 @@ export const createSuperClusterIcon = (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"}';">- <!-- Image inside the rounded rectangle -->- <img- src="${imageSrc}"- style="+ ${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%;- object-fit: cover;border-radius: 12px;- "- alt="Location"- />+ 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 -->diff --git a/web/apps/photos/src/components/TripTemplate/utils/dataProcessing.ts b/web/apps/photos/src/components/TripTemplate/utils/dataProcessing.tsindex 5414ca2f25..271591926a 100644--- a/web/apps/photos/src/components/TripTemplate/utils/dataProcessing.ts+++ b/web/apps/photos/src/components/TripTemplate/utils/dataProcessing.ts@@ -126,24 +126,78 @@ export const generateNeededThumbnails = async ({return { thumbnailUpdates };}- const neededFileIds = new Set<number>();+ // Define priority groups with specific file collections+ const priorityGroups: EnteFile[][] = [];++ // Priority 1: Cover image (handled separately in loadCoverImage, skip here)++ // Priority 2: First 3 locations photosfans (first 3 photos from each)+ const firstLocationsFiles: EnteFile[] = [];+ photoClusters.slice(0, 3).forEach((cluster) => {+ cluster.slice(0, 3).forEach((photo) => {+ const file = files.find((f) => f.id === photo.fileId);+ if (file && !firstLocationsFiles.includes(file)) {+ firstLocationsFiles.push(file);+ }+ });+ });+ if (firstLocationsFiles.length > 0) {+ priorityGroups.push(firstLocationsFiles);+ }+ // Priority 3: Map marker photos (first photo from each cluster for markers)+ const mapMarkerFiles: EnteFile[] = [];photoClusters.forEach((cluster) => {+ if (cluster.length > 0 && cluster[0]) {+ const file = files.find((f) => f.id === cluster[0].fileId);+ if (file && !firstLocationsFiles.includes(file) && !mapMarkerFiles.includes(file)) {+ mapMarkerFiles.push(file);+ }+ }+ });+ if (mapMarkerFiles.length > 0) {+ priorityGroups.push(mapMarkerFiles);+ }++ // Priority 4: Rest of locations photosfans (remaining locations, first 3 from each)+ const remainingLocationFiles: EnteFile[] = [];+ photoClusters.slice(3).forEach((cluster) => {cluster.slice(0, 3).forEach((photo) => {- neededFileIds.add(photo.fileId);+ const file = files.find((f) => f.id === photo.fileId);+ if (file &&+ !firstLocationsFiles.includes(file) &&+ !mapMarkerFiles.includes(file) &&+ !remainingLocationFiles.includes(file)) {+ remainingLocationFiles.push(file);+ }});});+ if (remainingLocationFiles.length > 0) {+ priorityGroups.push(remainingLocationFiles);+ }- const filesToProcess = files.filter((file) => neededFileIds.has(file.id));-- for (const file of filesToProcess) {- try {- const thumbnailUrl = await downloadManager.renderableThumbnailURL(file);- if (thumbnailUrl) {- thumbnailUpdates.set(file.id, thumbnailUrl);+ // Process priority groups sequentially with delays+ for (let groupIndex = 0; groupIndex < priorityGroups.length; groupIndex++) {+ const group = priorityGroups[groupIndex];+ if (!group) continue;++ // Process files in parallel within each priority group+ const groupPromises = group.map(async (file) => {+ try {+ const thumbnailUrl = await downloadManager.renderableThumbnailURL(file);+ if (thumbnailUrl) {+ thumbnailUpdates.set(file.id, thumbnailUrl);+ }+ } catch {+ // Silently ignore thumbnail generation errors}- } catch {- // Silently ignore thumbnail generation errors+ });++ await Promise.all(groupPromises);++ // Add small delay between priority groups to allow UI updates+ if (groupIndex < priorityGroups.length - 1) {+ await new Promise(resolve => setTimeout(resolve, 50));}}@@ -165,11 +219,13 @@ export const loadCoverImage = async ({let coverFile: EnteFile | undefined;+ // Priority 1: Use explicit cover ID if setconst coverID = collection?.pubMagicMetadata?.data.coverID;if (coverID) {coverFile = files.find((f) => f.id === coverID);}+ // Priority 2: Use first chronological photo as cover (highest priority)if (!coverFile) {const firstPhoto = journeyData[0];if (!firstPhoto) return null;@@ -179,6 +235,7 @@ export const loadCoverImage = async ({if (!coverFile) return null;try {+ // Load cover image at highest quality first (highest priority)const sourceURLs = await downloadManager.renderableSourceURLs(coverFile);if (sourceURLs.type === "image") {return sourceURLs.imageURL;