Skip to content

armgit / ente

Public Imported from GitHub
0

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

fixes

Anand Baburajan17f4bc7520ed
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 99d7b0954c..46798dad27 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -346,6 +346,13 @@ const Page: React.FC = () => {
const activePerson =
state.view?.type == "people" ? state.view.activePerson : undefined;
const activePersonID = activePerson?.id;
+ const selectedFilesInView = useMemo(
+ () => getSelectedFiles(selected, filteredFiles),
+ [selected, filteredFiles],
+ );
+ const isAllSelectedInView =
+ filteredFiles.length > 0 &&
+ selectedFilesInView.length === filteredFiles.length;
// TODO: Move into reducer
const barCollectionSummaries = useMemo(
@@ -966,9 +973,8 @@ const Page: React.FC = () => {
const handleEditLocationConfirm = useCallback(
async (location: Location) => {
- const selectedFiles = getSelectedFiles(selected, filteredFiles);
// Only update files owned by the user
- const userFiles = selectedFiles.filter(
+ const userFiles = selectedFilesInView.filter(
(f) => f.ownerID == user!.id,
);
if (userFiles.length > 0) {
@@ -980,7 +986,7 @@ const Page: React.FC = () => {
}
void remotePull({ silent: true });
},
- [selected, filteredFiles, user, remotePull],
+ [selectedFilesInView, user, remotePull],
);
const handleSelectSearchOption = (
@@ -1343,8 +1349,8 @@ const Page: React.FC = () => {
handleRemoveFilesFromCollection
}
onOpenCollectionSelector={handleOpenCollectionSelector}
- totalFileCount={filteredFiles.length}
onSelectAll={handleSelectAll}
+ isAllSelected={isAllSelectedInView}
{...{
createOnCreateForCollectionOp,
createOnSelectForCollectionOp,
@@ -1546,7 +1552,7 @@ const Page: React.FC = () => {
/>
<EditLocationDialog
{...editLocationVisibilityProps}
- files={getSelectedFiles(selected, filteredFiles)}
+ files={selectedFilesInView}
onConfirm={handleEditLocationConfirm}
/>
</FullScreenDropZone>
diff --git a/web/packages/gallery/components/FileInfo.tsx b/web/packages/gallery/components/FileInfo.tsx
index aa89da02a8..ce330b842d 100644
--- a/web/packages/gallery/components/FileInfo.tsx
+++ b/web/packages/gallery/components/FileInfo.tsx
@@ -238,20 +238,10 @@ export const FileInfo: React.FC<FileInfoProps> = ({
const canAddPerson = isMLEnabled() && assignablePeople.length > 0;
- const fileLocationValue = useMemo(
- // Prefer the location in the EnteFile, then fall back to Exif.
- () => fileLocation(file) ?? exif?.parsed?.location,
- [file, exif],
- );
-
- // Local state to track updated location before file prop refreshes
- const [localLocation, setLocalLocation] = useState<Location | undefined>();
- const location = localLocation ?? fileLocationValue;
+ // Prefer the location in the EnteFile, then fall back to Exif.
+ const fileLocationValue = fileLocation(file) ?? exif?.parsed?.location;
- // Reset local location when file changes
- useEffect(() => {
- setLocalLocation(undefined);
- }, [file.id]);
+ const location = fileLocationValue;
const annotatedExif = useMemo(() => annotateExif(exif), [exif]);
@@ -305,7 +295,6 @@ export const FileInfo: React.FC<FileInfoProps> = ({
newLocation.latitude,
newLocation.longitude,
);
- setLocalLocation(newLocation);
await onFileMetadataUpdate?.();
} catch (e) {
onGenericError(e);
@@ -980,31 +969,51 @@ const MapBox: React.FC<MapBoxProps> = ({ location, mapEnabled }) => {
const zoom = 16;
const mapBoxContainerRef = useRef<HTMLDivElement>(null);
+ const mapRef = useRef<L.Map | null>(null);
+ const markerRef = useRef<L.Marker | null>(null);
useEffect(() => {
- const mapContainer = mapBoxContainerRef.current;
- if (mapEnabled) {
- const position: L.LatLngTuple = [
- location.latitude,
- location.longitude,
- ];
- if (mapContainer && !mapContainer.hasChildNodes()) {
- // @ts-ignore
- const map = leaflet.map(mapContainer).setView(position, zoom);
- // @ts-ignore
- leaflet.tileLayer(urlTemplate, { attribution }).addTo(map);
- // @ts-ignore
- leaflet.marker(position).addTo(map).openPopup();
+ if (!leaflet) return;
+ if (!mapEnabled) {
+ if (mapRef.current) {
+ mapRef.current.remove();
+ mapRef.current = null;
+ markerRef.current = null;
}
+ return;
+ }
+
+ const mapContainer = mapBoxContainerRef.current;
+ if (!mapContainer) return;
+
+ const position: L.LatLngTuple = [location.latitude, location.longitude];
+ if (!mapRef.current) {
+ // @ts-ignore
+ const map = leaflet.map(mapContainer).setView(position, zoom);
+ // @ts-ignore
+ leaflet.tileLayer(urlTemplate, { attribution }).addTo(map);
+ // @ts-ignore
+ markerRef.current = leaflet.marker(position).addTo(map);
+ mapRef.current = map;
} else {
- if (mapContainer?.hasChildNodes()) {
- if (mapContainer.firstChild) {
- mapContainer.removeChild(mapContainer.firstChild);
- }
- }
+ mapRef.current.setView(position, zoom);
+ markerRef.current?.setLatLng(position);
}
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [mapEnabled]);
+ return () => {
+ if (mapRef.current) {
+ mapRef.current.remove();
+ mapRef.current = null;
+ markerRef.current = null;
+ }
+ };
+ }, [
+ mapEnabled,
+ location.latitude,
+ location.longitude,
+ zoom,
+ attribution,
+ urlTemplate,
+ ]);
return mapEnabled ? (
<MapBoxContainer ref={mapBoxContainerRef} />
diff --git a/web/packages/new/photos/components/EditLocationDialog.tsx b/web/packages/new/photos/components/EditLocationDialog.tsx
index 95a7cb4c06..3d5436bfcb 100644
--- a/web/packages/new/photos/components/EditLocationDialog.tsx
+++ b/web/packages/new/photos/components/EditLocationDialog.tsx
@@ -133,6 +133,7 @@ export const EditLocationDialog: React.FC<EditLocationDialogProps> = ({
/>
<Box sx={{ flex: 1, position: "relative" }}>
<EditableMap
+ open={open}
initialLocation={initialLocation}
selectedLocation={selectedLocation}
onLocationSelect={setSelectedLocation}
@@ -221,12 +222,14 @@ const TitleBar: React.FC<TitleBarProps> = ({
);
interface EditableMapProps {
+ open: boolean;
initialLocation: Location | undefined;
selectedLocation: Location | undefined;
onLocationSelect: (location: Location) => void;
}
const EditableMap: React.FC<EditableMapProps> = ({
+ open,
initialLocation,
selectedLocation,
onLocationSelect,
@@ -234,6 +237,7 @@ const EditableMap: React.FC<EditableMapProps> = ({
const mapContainerRef = useRef<HTMLDivElement>(null);
const mapRef = useRef<L.Map | null>(null);
const markerRef = useRef<L.Marker | null>(null);
+ const prevOpenRef = useRef(open);
// Capture initial location at mount time to avoid map reset on file updates
const initialLocationRef = useRef(initialLocation);
@@ -314,26 +318,36 @@ const EditableMap: React.FC<EditableMapProps> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
- // Update marker position when selectedLocation changes externally
+ // Sync marker when selection changes; recenter only when the dialog opens.
useEffect(() => {
- if (
- selectedLocation &&
- markerRef.current &&
- mapRef.current &&
- leaflet
- ) {
- const currentPos = markerRef.current.getLatLng();
- if (
- currentPos.lat !== selectedLocation.latitude ||
- currentPos.lng !== selectedLocation.longitude
- ) {
- markerRef.current.setLatLng([
- selectedLocation.latitude,
- selectedLocation.longitude,
- ]);
- }
+ const wasOpen = prevOpenRef.current;
+ prevOpenRef.current = open;
+ if (!open || !mapRef.current || !leaflet) return;
+ const didOpen = !wasOpen;
+ const nextLocation = selectedLocation ?? initialLocation;
+ if (!nextLocation) return;
+ const position: L.LatLngTuple = [
+ nextLocation.latitude,
+ nextLocation.longitude,
+ ];
+
+ if (markerRef.current) {
+ markerRef.current.setLatLng(position);
+ } else {
+ const marker = leaflet
+ .marker(position, { draggable: true })
+ .addTo(mapRef.current);
+ markerRef.current = marker;
+
+ marker.on("dragend", () => {
+ const pos = marker.getLatLng();
+ onLocationSelect({ latitude: pos.lat, longitude: pos.lng });
+ });
+ }
+ if (didOpen) {
+ mapRef.current.setView(position, mapRef.current.getZoom());
}
- }, [selectedLocation]);
+ }, [open, initialLocation, selectedLocation, onLocationSelect]);
const handleZoomIn = (e: React.MouseEvent) => {
e.stopPropagation();
diff --git a/web/packages/new/photos/components/SelectedFileOptions.tsx b/web/packages/new/photos/components/SelectedFileOptions.tsx
index cd576f6806..fa49e3305c 100644
--- a/web/packages/new/photos/components/SelectedFileOptions.tsx
+++ b/web/packages/new/photos/components/SelectedFileOptions.tsx
@@ -154,14 +154,14 @@ interface SelectedFileOptionsProps {
* Only shown when at least one owned file is selected.
*/
onEditLocation?: () => void;
- /**
- * The total number of files available in the current view.
- */
- totalFileCount: number;
/**
* Called when the user wants to select all files.
*/
onSelectAll: () => void;
+ /**
+ * If true, all files in the current view are selected.
+ */
+ isAllSelected: boolean;
}
/**
@@ -183,8 +183,8 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
createFileOpHandler,
onAddPersonToSelectedFiles,
onEditLocation,
- totalFileCount,
onSelectAll,
+ isAllSelected,
}) => {
const { showMiniDialog } = useBaseContext();
@@ -348,12 +348,8 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
})}
</Typography>
<SelectAllToggleButton
- isAllSelected={selectedFileCount >= totalFileCount}
- onClick={
- selectedFileCount < totalFileCount
- ? onSelectAll
- : onClearSelection
- }
+ isAllSelected={isAllSelected}
+ onClick={isAllSelected ? onClearSelection : onSelectAll}
/>
<Box sx={{ mr: "auto" }} />