Skip to content

armgit / ente

Public Imported from GitHub
0

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

[photos][web] Make places clickable on the map

AswinAsok0b9336f6b032
diff --git a/web/apps/photos/src/components/collections/CollectionMap.tsx b/web/apps/photos/src/components/collections/CollectionMap.tsx
index 08f4da0bcb..343664eb2e 100644
--- a/web/apps/photos/src/components/collections/CollectionMap.tsx
+++ b/web/apps/photos/src/components/collections/CollectionMap.tsx
@@ -1,4 +1,5 @@
import type { RemotePullOpts } from "@/components/gallery";
+import type { PlaceSelection } from "@/components/gallery/PlacesList";
import type { SelectedState } from "@/utils/file";
import AddIcon from "@mui/icons-material/Add";
import LocationOnIcon from "@mui/icons-material/LocationOn";
@@ -71,6 +72,7 @@ interface CollectionMapProps extends Pick<
| "onSelectPerson"
| "emailByUserID"
> {
+ selectedPlace?: PlaceSelection;
collectionSummary: CollectionSummary;
files: EnteFile[];
mapFileSource: MapFileSource;
@@ -991,6 +993,7 @@ function createMarkerIcon(
}
export const CollectionMap: React.FC<CollectionMapProps> = ({
+ selectedPlace,
collectionSummary,
files,
onRemotePull,
@@ -1166,6 +1169,7 @@ export const CollectionMap: React.FC<CollectionMapProps> = ({
<Box sx={{ width: "100%", height: "100%" }}>
<MapCanvas
mapComponents={mapComponents}
+ selectedPlace={selectedPlace}
mapCenter={mapCenter}
mapIndex={mapIndex}
thumbByFileID={thumbByFileID}
@@ -1346,6 +1350,7 @@ function CollectionSidebar({
}
interface MapCanvasProps {
+ selectedPlace?: PlaceSelection;
mapComponents: MapComponents;
mapCenter: [number, number];
mapIndex: MapIndex;
@@ -1362,6 +1367,7 @@ const leafletAttributionPrefix =
'<a href="https://leafletjs.com" target="_blank" rel="noopener noreferrer">Leaflet</a>';
const MapCanvas = React.memo(function MapCanvas({
+ selectedPlace,
mapComponents,
mapCenter,
mapIndex,
@@ -1388,6 +1394,11 @@ const MapCanvas = React.memo(function MapCanvas({
updateWhenZooming
referrerPolicy="strict-origin-when-cross-origin"
/>
+ <PlaceFocus
+ useMap={useMap}
+ selectedPlace={selectedPlace}
+ mapCenter={mapCenter}
+ />
<MapControls useMap={useMap} />
<MapClusters
useMap={useMap}
@@ -1403,6 +1414,27 @@ const MapCanvas = React.memo(function MapCanvas({
);
});
+const PlaceFocus = ({
+ useMap,
+ selectedPlace,
+ mapCenter,
+}: {
+ useMap: MapComponents["useMap"];
+ selectedPlace?: PlaceSelection;
+ mapCenter: [number, number];
+}) => {
+ const map = useMap();
+ useEffect(() => {
+ map.setView(
+ selectedPlace
+ ? [selectedPlace.latitude, selectedPlace.longitude]
+ : mapCenter,
+ DEFAULT_MAP_ZOOM,
+ );
+ }, [map, selectedPlace, mapCenter]);
+ return null;
+};
+
interface MapControlsProps {
useMap: typeof import("react-leaflet").useMap;
}
diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsx
index 39cc776cf9..efee665f6f 100644
--- a/web/apps/photos/src/components/gallery/BarImpl.tsx
+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx
@@ -59,7 +59,7 @@ import {
areEqual,
type ListChildComponentProps,
} from "react-window";
-import { PlacesList } from "./PlacesList";
+import { PlacesList, type PlaceSelection } from "./PlacesList";
import type { GalleryBarMode } from "./reducer";
export interface GalleryBarPresentationProps {
@@ -70,6 +70,8 @@ export interface GalleryBarPresentationProps {
export interface GalleryBarImplProps extends GalleryBarPresentationProps {
mode: GalleryBarMode;
placesFiles?: EnteFile[];
+ selectedPlace?: PlaceSelection;
+ onSelectPlace: (place: PlaceSelection | undefined) => void;
albumFilter: AlbumFilter;
albumSearchQuery: string;
onAlbumSearchQueryChange: (query: string) => void;
@@ -98,6 +100,8 @@ export interface GalleryBarImplProps extends GalleryBarPresentationProps {
export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
mode,
placesFiles,
+ selectedPlace,
+ onSelectPlace,
albumFilter,
albumSearchQuery,
onAlbumSearchQueryChange,
@@ -675,7 +679,11 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
)}
</Stack>
{placesFiles ? (
- <PlacesList files={placesFiles} />
+ <PlacesList
+ files={placesFiles}
+ selectedPlace={selectedPlace}
+ onSelectPlace={onSelectPlace}
+ />
) : isSearching &&
(mode == "albums"
? !visibleAlbumFilters.length && !albumShortcuts.length
diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
index a9c9afaca2..162387d1a3 100644
--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
@@ -167,6 +167,10 @@ export const PhotosNavigationShell: React.FC<
mobileDrawerProps={mobileDrawerProps}
onCreateAlbum={openAlbumCreation}
onSelectCollectionID={selectCollection}
+ onSelectPlace={(place) => {
+ galleryNavigation.onSelectPlace(place);
+ closeMobileNavigation();
+ }}
onSelectPerson={selectPerson}
/>
);
diff --git a/web/apps/photos/src/components/gallery/PlacesList.tsx b/web/apps/photos/src/components/gallery/PlacesList.tsx
index dd143a759d..f48243f050 100644
--- a/web/apps/photos/src/components/gallery/PlacesList.tsx
+++ b/web/apps/photos/src/components/gallery/PlacesList.tsx
@@ -1,4 +1,12 @@
-import { Box, List, ListItem, Stack, Typography, styled } from "@mui/material";
+import {
+ Box,
+ List,
+ ListItem,
+ ListItemButton,
+ Stack,
+ Typography,
+ styled,
+} from "@mui/material";
import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";
import log from "ente-base/log";
import type { EnteFile } from "ente-media/file";
@@ -7,7 +15,20 @@ import { t } from "i18next";
import { useEffect, useState } from "react";
import { listPlaces } from "../../services/places";
-export const PlacesList = ({ files }: { files: EnteFile[] }) => {
+export interface PlaceSelection {
+ latitude: number;
+ longitude: number;
+}
+
+export const PlacesList = ({
+ files,
+ selectedPlace,
+ onSelectPlace,
+}: {
+ files: EnteFile[];
+ selectedPlace?: PlaceSelection;
+ onSelectPlace: (place: PlaceSelection | undefined) => void;
+}) => {
const [result, setResult] = useState<{
files: EnteFile[];
groups?: Awaited<ReturnType<typeof listPlaces>>;
@@ -32,13 +53,16 @@ export const PlacesList = ({ files }: { files: EnteFile[] }) => {
return (
<Stack sx={{ flex: 1, minHeight: 0, gap: "8px" }}>
- <Stack
- direction="row"
- aria-current="page"
+ <ListItemButton
+ selected={!selectedPlace}
+ onClick={() => onSelectPlace(undefined)}
sx={{
...placeRowSx,
flexShrink: 0,
- bgcolor: "var(--gallery-navigation-surface)",
+ flexGrow: 0,
+ "&.Mui-selected": {
+ bgcolor: "var(--gallery-navigation-surface)",
+ },
}}
>
<Box
@@ -53,7 +77,7 @@ export const PlacesList = ({ files }: { files: EnteFile[] }) => {
}}
/>
<Typography sx={placeNameSx}>{t("your_map")}</Typography>
- </Stack>
+ </ListItemButton>
{!currentResult ? (
<Stack role="status" aria-label={t("loading")} sx={{ p: 2 }}>
<ActivityIndicator />
@@ -80,17 +104,31 @@ export const PlacesList = ({ files }: { files: EnteFile[] }) => {
key={`${city.name}-${city.country}-${city.latitude}-${city.longitude}`}
disableGutters
title={`${city.name}, ${city.country}`}
- sx={placeRowSx}
+ disablePadding
>
- <Box aria-hidden sx={{ flexShrink: 0 }}>
- <ItemCard
- coverFile={coverFile}
- TileComponent={PlaceCover}
- />
- </Box>
- <Typography noWrap sx={placeNameSx}>
- {city.name}
- </Typography>
+ <ListItemButton
+ selected={
+ selectedPlace?.latitude === city.latitude &&
+ selectedPlace.longitude === city.longitude
+ }
+ onClick={() =>
+ onSelectPlace({
+ latitude: city.latitude,
+ longitude: city.longitude,
+ })
+ }
+ sx={placeRowSx}
+ >
+ <Box aria-hidden sx={{ flexShrink: 0 }}>
+ <ItemCard
+ coverFile={coverFile}
+ TileComponent={PlaceCover}
+ />
+ </Box>
+ <Typography noWrap sx={placeNameSx}>
+ {city.name}
+ </Typography>
+ </ListItemButton>
</ListItem>
))}
</List>
@@ -122,5 +160,5 @@ const PlaceCover = styled(PreviewItemTile)({
width: 36,
height: 36,
borderRadius: "12px",
- cursor: "default",
+ cursor: "inherit",
});
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 8d7db91967..4e7bbaee35 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -38,6 +38,7 @@ import { DuplicatesView } from "@/components/gallery/DuplicatesView";
import { LargeFilesView } from "@/components/gallery/LargeFilesView";
import { PeopleOverview } from "@/components/gallery/PeopleOverview";
import { PhotosNavigationShell } from "@/components/gallery/PhotosNavigationShell";
+import type { PlaceSelection } from "@/components/gallery/PlacesList";
import { PublicLinkDetails } from "@/components/gallery/PublicLinkDetails";
import {
albumShortcutCollectionID,
@@ -323,6 +324,7 @@ const Page: React.FC = () => {
show: showEditAlbumDetails,
props: editAlbumDetailsVisibilityProps,
} = useModalVisibility();
+ const [selectedPlace, setSelectedPlace] = useState<PlaceSelection>();
const [isMapView, setIsMapView] = useState(false);
const closeCollectionMap = useCallback(() => setIsMapView(false), []);
@@ -2163,6 +2165,11 @@ const Page: React.FC = () => {
<CollectionMap
collectionSummary={activeCollectionSummary}
files={activeCollection ? activeCollectionFiles : filteredFiles}
+ selectedPlace={
+ activeCollectionID === PseudoCollectionID.all
+ ? selectedPlace
+ : undefined
+ }
mapFileSource={mapFileSource}
onRemotePull={remotePull}
onAddSaveGroup={onAddSaveGroup}
@@ -2236,6 +2243,7 @@ const Page: React.FC = () => {
onSidebar={showSidebar}
onUpload={openUploader}
onShowMap={() => {
+ setSelectedPlace(undefined);
handleShowCollectionSummaryWithID(
PseudoCollectionID.all,
);
@@ -2254,6 +2262,8 @@ const Page: React.FC = () => {
isCleanupViewOpen
? undefined
: {
+ selectedPlace,
+ onSelectPlace: setSelectedPlace,
placesFiles:
isMapView &&
activeCollectionID ===
diff --git a/web/apps/photos/tests/sidebar-album-search.test.tsx b/web/apps/photos/tests/sidebar-album-search.test.tsx
index 7486c480c7..29b3c6b169 100644
--- a/web/apps/photos/tests/sidebar-album-search.test.tsx
+++ b/web/apps/photos/tests/sidebar-album-search.test.tsx
@@ -125,6 +125,7 @@ const renderSearch = (
onChangeCollectionsSortBy: vi.fn(),
onChangePeopleSortBy: vi.fn(),
onSelectPerson: vi.fn(),
+ onSelectPlace: vi.fn(),
};
const Sidebar = () => {
const data = useAlbumNavigationData({