Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix: update timeline and map on new photo upload

anandbaburajan93e5d5ea702d
diff --git a/web/apps/photos/src/components/TripTemplate/hooks/useLocationFetching.ts b/web/apps/photos/src/components/TripTemplate/hooks/useLocationFetching.ts
index ac5ccd4d67..4df3c3ce69 100644
--- a/web/apps/photos/src/components/TripTemplate/hooks/useLocationFetching.ts
+++ b/web/apps/photos/src/components/TripTemplate/hooks/useLocationFetching.ts
@@ -1,4 +1,4 @@
-import { useEffect } from "react";
+import { useEffect, useRef } from "react";
import type { JourneyPoint } from "../types";
import { fetchLocationNames } from "../utils/dataProcessing";
@@ -21,11 +21,33 @@ export const useLocationFetching = ({
setJourneyData,
setIsLoadingLocations,
}: UseLocationFetchingParams) => {
+ const processedPhotoIdsRef = useRef<Set<number>>(new Set());
+
// Fetch location names for clusters
useEffect(() => {
const fetchNames = async () => {
if (photoClusters.length === 0) return;
+ // Get all current photo IDs
+ const currentPhotoIds = new Set(
+ photoClusters.flat().map((photo) => photo.fileId)
+ );
+
+ // Check if we have new photos that haven't been processed
+ const hasNewPhotos = Array.from(currentPhotoIds).some(
+ (id) => !processedPhotoIdsRef.current.has(id)
+ );
+
+ // Check if any photos need location fetching
+ const needsFetching = photoClusters.some((cluster) =>
+ cluster.some((photo) => !locationDataRef.current?.has(photo.fileId))
+ );
+
+ if (!hasNewPhotos && !needsFetching) {
+ setIsLoadingLocations(false);
+ return;
+ }
+
setIsLoadingLocations(true);
try {
@@ -46,6 +68,9 @@ export const useLocationFetching = ({
}),
);
}
+
+ // Update processed photos set
+ processedPhotoIdsRef.current = currentPhotoIds;
} finally {
setIsLoadingLocations(false);
}
@@ -53,7 +78,7 @@ export const useLocationFetching = ({
void fetchNames();
}, [
- photoClusters.length,
+ photoClusters,
locationDataRef,
setJourneyData,
setIsLoadingLocations,
diff --git a/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts b/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts
index dbd997edc5..e34960fd3d 100644
--- a/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts
+++ b/web/apps/photos/src/components/TripTemplate/hooks/useThumbnailGeneration.ts
@@ -1,5 +1,5 @@
import { type EnteFile } from "ente-media/file";
-import { useEffect } from "react";
+import { useEffect, useRef } from "react";
import type { JourneyPoint } from "../types";
import { generateNeededThumbnails } from "../utils/dataProcessing";
@@ -20,11 +20,27 @@ export const useThumbnailGeneration = ({
thumbnailsGeneratedRef,
setJourneyData,
}: UseThumbnailGenerationParams) => {
+ const processedPhotoIdsRef = useRef<Set<number>>(new Set());
+
// Generate thumbnails for needed photos with progressive loading
useEffect(() => {
const generateThumbs = async () => {
- if (photoClusters.length === 0 || thumbnailsGeneratedRef.current)
- return;
+ if (photoClusters.length === 0) return;
+
+ // Get all current photo IDs
+ const currentPhotoIds = new Set(
+ photoClusters.flat().map((photo) => photo.fileId)
+ );
+
+ // Check if we have photos that need thumbnails
+ const photosNeedingThumbnails = photoClusters
+ .flat()
+ .filter((photo) =>
+ !photo.image &&
+ (!processedPhotoIdsRef.current.has(photo.fileId) || !thumbnailsGeneratedRef.current)
+ );
+
+ if (photosNeedingThumbnails.length === 0) return;
const { thumbnailUpdates } = await generateNeededThumbnails({
photoClusters,
@@ -42,9 +58,12 @@ export const useThumbnailGeneration = ({
}),
);
}
+
+ // Update processed photos set and mark as generated
+ processedPhotoIdsRef.current = new Set([...processedPhotoIdsRef.current, ...currentPhotoIds]);
thumbnailsGeneratedRef.current = true;
};
void generateThumbs();
- }, [photoClusters.length, files, thumbnailsGeneratedRef, setJourneyData]);
+ }, [photoClusters, files, thumbnailsGeneratedRef, setJourneyData]);
};