Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web][photos] Render album maps in place

AswinAsok2e7380baa638
diff --git a/web/apps/photos/src/components/collections/CollectionMapDialog.tsx b/web/apps/photos/src/components/collections/CollectionMap.tsx
similarity index 93%
rename from web/apps/photos/src/components/collections/CollectionMapDialog.tsx
rename to web/apps/photos/src/components/collections/CollectionMap.tsx
index 1d70762323..0ae2de6545 100644
--- a/web/apps/photos/src/components/collections/CollectionMapDialog.tsx
+++ b/web/apps/photos/src/components/collections/CollectionMap.tsx
@@ -1,13 +1,10 @@
import type { RemotePullOpts } from "@/components/gallery";
import type { SelectedState } from "@/utils/file";
import AddIcon from "@mui/icons-material/Add";
-import CloseIcon from "@mui/icons-material/Close";
import LocationOnIcon from "@mui/icons-material/LocationOn";
import RemoveIcon from "@mui/icons-material/Remove";
import {
Box,
- Dialog,
- DialogContent,
IconButton,
Stack,
styled,
@@ -18,7 +15,6 @@ import {
import { useTheme } from "@mui/material/styles";
import { ensureLocalUser } from "ente-accounts/services/user";
import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";
-import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import { isSxArray } from "ente-base/components/utils/sx";
import { useBaseContext } from "ente-base/context";
import { downloadManager } from "ente-gallery/services/download";
@@ -64,23 +60,19 @@ interface MapFileSource {
tempHiddenFileIDs: Set<number>;
}
-interface CollectionMapDialogProps
- extends
- ModalVisibilityProps,
- Pick<
- FileListWithViewerProps,
- | "onAddSaveGroup"
- | "onMarkTempDeleted"
- | "onAddFileToCollection"
- | "onRemoteFilesPull"
- | "onVisualFeedback"
- | "fileNormalCollectionIDs"
- | "collectionNameByID"
- | "onSelectCollection"
- | "onSelectPerson"
- | "emailByUserID"
- > {
- embedded?: boolean;
+interface CollectionMapProps extends Pick<
+ FileListWithViewerProps,
+ | "onAddSaveGroup"
+ | "onMarkTempDeleted"
+ | "onAddFileToCollection"
+ | "onRemoteFilesPull"
+ | "onVisualFeedback"
+ | "fileNormalCollectionIDs"
+ | "collectionNameByID"
+ | "onSelectCollection"
+ | "onSelectPerson"
+ | "emailByUserID"
+> {
collectionSummary: CollectionSummary;
files: EnteFile[];
mapFileSource: MapFileSource;
@@ -1000,10 +992,7 @@ function createMarkerIcon(
});
}
-export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
- open,
- onClose,
- embedded = false,
+export const CollectionMap: React.FC<CollectionMapProps> = ({
collectionSummary,
files,
onRemotePull,
@@ -1022,7 +1011,6 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
const { onGenericError } = useBaseContext();
const mapComponents = useMapComponents();
const user = useCurrentUser();
- const [isFileViewerOpen, setIsFileViewerOpen] = useState(false);
const {
collectionFiles: mapSourceCollectionFiles,
favoriteFileIDs: syncedFavoriteFileIDs,
@@ -1039,7 +1027,7 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
handleToggleFavorite,
handleFileVisibilityUpdate,
} = useFavorites(
- open,
+ true,
user,
mapSourceCollectionFiles,
syncedFavoriteFileIDs,
@@ -1083,18 +1071,12 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
removeFiles: removeFilesFromMap,
updateFileVisibility,
queueThumbnailFetch,
- } = useMapData(open, collectionSummary, mapFiles, onGenericError);
+ } = useMapData(true, collectionSummary, mapFiles, onGenericError);
const [visibleFileIDs, setVisibleFileIDs] = useState<number[]>([]);
const [isVisiblePhotosUpdating, setIsVisiblePhotosUpdating] =
useState(false);
- useEffect(() => {
- if (!open) {
- setIsVisiblePhotosUpdating(false);
- }
- }, [open]);
-
const visibleFiles = useMemo(() => {
return visibleFileIDs
.map((fileID) => filesByID.get(fileID))
@@ -1102,7 +1084,7 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
}, [visibleFileIDs, filesByID]);
const handleRemotePull = useCallback(
- () => onRemotePull({ silent: true, source: "map-dialog" }),
+ () => onRemotePull({ silent: true, source: "map-view" }),
[onRemotePull],
);
@@ -1151,10 +1133,7 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
);
} else if (!mapPoints.length || !mapCenter || !mapIndex) {
body = (
- <CenteredBox
- onClose={embedded ? undefined : onClose}
- closeLabel={t("close")}
- >
+ <CenteredBox>
<Typography variant="body" sx={{ color: "text.secondary" }}>
{t("no_geotagged_photos")}
</Typography>
@@ -1164,13 +1143,11 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
body = (
<Box sx={{ position: "relative", height: "100%", width: "100%" }}>
<CollectionSidebar
- showCloseButton={!embedded}
collectionSummary={collectionSummary}
visibleFiles={visibleFiles}
isVisiblePhotosUpdating={isVisiblePhotosUpdating}
latestFileId={latestFileId}
thumbByFileID={thumbByFileID}
- onClose={onClose}
user={user}
favoriteFileIDs={favoriteFileIDs}
pendingFavoriteUpdates={pendingFavoriteUpdates}
@@ -1190,7 +1167,6 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
onSelectCollection={onSelectCollection}
onSelectPerson={onSelectPerson}
emailByUserID={emailByUserID}
- onSetOpenFileViewer={setIsFileViewerOpen}
/>
<Box sx={{ width: "100%", height: "100%" }}>
<MapCanvas
@@ -1209,59 +1185,21 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({
);
}
- if (embedded) {
- return (
- <Box
- sx={{
- position: "relative",
- flex: 1,
- minHeight: 0,
- width: "100%",
- }}
- >
- {body}
- </Box>
- );
- }
-
return (
- <Dialog
- fullScreen
- keepMounted
- open={open}
- onClose={onClose}
- sx={{
- // Keep PhotoSwipe above the mounted dialog during transitions.
- ...(isFileViewerOpen && {
- zIndex: (theme) =>
- `calc(${theme.zIndex.drawer} - 2) !important`,
- }),
- }}
+ <Box
+ sx={{ position: "relative", flex: 1, minHeight: 0, width: "100%" }}
>
- <Box
- sx={{
- position: "relative",
- width: "100vw",
- height: "100vh",
- bgcolor: "background.default",
- }}
- >
- <DialogContent sx={{ padding: "0 !important", height: "100%" }}>
- {body}
- </DialogContent>
- </Box>
- </Dialog>
+ {body}
+ </Box>
);
};
interface CollectionSidebarProps {
- showCloseButton: boolean;
collectionSummary: CollectionSummary;
visibleFiles: EnteFile[];
isVisiblePhotosUpdating: boolean;
latestFileId: number | undefined;
thumbByFileID: Map<number, string>;
- onClose: () => void;
user: ReturnType<typeof useCurrentUser>;
favoriteFileIDs: Set<number>;
pendingFavoriteUpdates: Set<number>;
@@ -1282,7 +1220,6 @@ interface CollectionSidebarProps {
onSelectCollection?: FileListWithViewerProps["onSelectCollection"];
onSelectPerson?: FileListWithViewerProps["onSelectPerson"];
emailByUserID: FileListWithViewerProps["emailByUserID"];
- onSetOpenFileViewer?: (open: boolean) => void;
}
const COVER_IMAGE_HEIGHT = 320;
@@ -1290,13 +1227,11 @@ const MOBILE_SIDEBAR_HEIGHT = "50%";
const COVER_HEADER_HEIGHT = COVER_IMAGE_HEIGHT + 34;
function CollectionSidebar({
- showCloseButton,
collectionSummary,
visibleFiles,
isVisiblePhotosUpdating,
latestFileId,
thumbByFileID,
- onClose,
user,
favoriteFileIDs,
pendingFavoriteUpdates,
@@ -1314,7 +1249,6 @@ function CollectionSidebar({
onSelectCollection,
onSelectPerson,
emailByUserID,
- onSetOpenFileViewer,
}: CollectionSidebarProps) {
const [currentDate, setCurrentDate] = useState<string | undefined>(
undefined,
@@ -1349,7 +1283,6 @@ function CollectionSidebar({
name={collectionSummary.name}
coverImageUrl={coverImageUrl}
totalCount={collectionSummary.fileCount}
- onClose={onClose}
/>
),
height: COVER_HEADER_HEIGHT,
@@ -1361,7 +1294,6 @@ function CollectionSidebar({
collectionSummary.name,
collectionSummary.fileCount,
coverImageUrl,
- onClose,
],
);
@@ -1404,19 +1336,6 @@ function CollectionSidebar({
{visibleDate && ` Β· ${visibleDate}`}
</Typography>
</Box>
- {showCloseButton && (
- <IconButton
- onClick={onClose}
- size="small"
- sx={{
- color: "text.secondary",
- bgcolor: "fill.faint",
- "&:hover": { bgcolor: "fill.muted" },
- }}
- >
- <CloseIcon />
- </IconButton>
- )}
</Box>
</StickyDateHeader>
<FileListContainer>
@@ -1445,7 +1364,6 @@ function CollectionSidebar({
activeCollectionID={collectionSummary.id}
selected={emptySelected}
setSelected={noOpSetSelected}
- onSetOpenFileViewer={onSetOpenFileViewer}
listBorderRadius={isMobile ? "0" : "0 0 32px 32px"}
header={coverHeader}
onScroll={setScrollOffset}
@@ -1458,7 +1376,6 @@ function CollectionSidebar({
name={collectionSummary.name}
coverImageUrl={coverImageUrl}
totalCount={collectionSummary.fileCount}
- onClose={onClose}
/>
)}
<EmptyStateMessage>
@@ -1881,40 +1798,20 @@ const FloatingIconButton: React.FC<IconButtonProps> = ({ sx, ...props }) => {
return <IconButton {...props} sx={mergedSx} />;
};
-interface CenteredBoxProps extends React.PropsWithChildren {
- onClose?: () => void;
- closeLabel?: string;
-}
-
-function CenteredBox({ children, onClose, closeLabel }: CenteredBoxProps) {
- return (
- <CenteredBoxContainer>
- {onClose && (
- <IconButton
- aria-label={closeLabel ?? "Close"}
- onClick={onClose}
- sx={{ position: "absolute", top: 16, right: 16 }}
- >
- <CloseIcon />
- </IconButton>
- )}
- {children}
- </CenteredBoxContainer>
- );
+function CenteredBox({ children }: React.PropsWithChildren) {
+ return <CenteredBoxContainer>{children}</CenteredBoxContainer>;
}
interface MapCoverProps {
name: string;
coverImageUrl: string | undefined;
totalCount: number;
- onClose: () => void;
}
const MapCover = React.memo(function MapCover({
name,
coverImageUrl,
totalCount,
- onClose,
}: MapCoverProps) {
return (
<CoverContainer>
@@ -1933,10 +1830,6 @@ const MapCover = React.memo(function MapCover({
/>
<CoverGradientOverlay />
- <CoverCloseButton aria-label="Close" onClick={onClose}>
- <CloseIcon sx={{ fontSize: 20 }} />
- </CoverCloseButton>
-
<CoverContentContainer>
<CoverTitle>{name}</CoverTitle>
<CoverSubtitle>
@@ -1985,15 +1878,6 @@ const CoverGradientOverlay = styled(Box)({
"linear-gradient(to bottom, rgba(0,0,0,0.4), transparent 35%, transparent 60%, rgba(0,0,0,0.75))",
});
-const CoverCloseButton = styled(IconButton)({
- position: "absolute",
- top: "12px",
- right: "12px",
- color: "white",
- backgroundColor: "rgba(0, 0, 0, 0.3)",
- "&:hover": { backgroundColor: "rgba(0, 0, 0, 0.5)" },
-});
-
const CoverContentContainer = styled(Box)({
position: "absolute",
bottom: 0,
diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
index 0441b0ebdb..196104e4a3 100644
--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
@@ -60,6 +60,7 @@ type PhotosNavigationShellProps = SearchBarProps & {
onHome: () => void;
onShowMap: () => void;
isMapView: boolean;
+ isMapSelected: boolean;
mode: GalleryBarMode;
onChangeMode: (mode: GalleryBarMode) => boolean;
};
@@ -241,7 +242,7 @@ export const PhotosNavigationShell: React.FC<
<NormalNavigationRail
{...props}
isHome={
- !props.isMapView &&
+ !props.isMapSelected &&
props.mode == "albums" &&
!props.isInSearchMode &&
galleryNavigation?.activeCollectionID ==
@@ -250,7 +251,7 @@ export const PhotosNavigationShell: React.FC<
onChangeMode={handleChangeMode}
opensDialog={mobile}
navigationOpen={
- !props.isMapView &&
+ !props.isMapSelected &&
!!galleryNavigation &&
(mobile
? mobileDrawerProps.open
@@ -390,7 +391,10 @@ const NormalHeaderContents: React.FC<
};
const NormalNavigationRail: React.FC<
- Omit<PhotosNavigationShellProps, "onUpload" | "onChangeMode"> & {
+ Omit<
+ PhotosNavigationShellProps,
+ "onUpload" | "onChangeMode" | "isMapView"
+ > & {
onChangeMode: (mode: GalleryBarMode) => void;
isHome: boolean;
opensDialog: boolean;
@@ -400,7 +404,7 @@ const NormalNavigationRail: React.FC<
onSidebar,
onHome,
onShowMap,
- isMapView,
+ isMapSelected,
mode,
onChangeMode,
isHome,
@@ -473,7 +477,7 @@ const NormalNavigationRail: React.FC<
<FocusVisibleButton
color="secondary"
aria-label={t("map")}
- aria-pressed={isMapView}
+ aria-pressed={isMapSelected}
onClick={onShowMap}
sx={{
minWidth: 0,
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 20c00a1ab8..8586f9ec54 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -20,7 +20,7 @@ import {
import { Upload } from "@/components/Upload";
import { WhatsNew } from "@/components/WhatsNew";
import { AlbumSlideshow } from "@/components/collections/AlbumSlideshow";
-import { CollectionMapDialog } from "@/components/collections/CollectionMapDialog";
+import { CollectionMap } from "@/components/collections/CollectionMap";
import {
EditAlbumDetailsDialog,
type AlbumDetails,
@@ -323,33 +323,22 @@ const Page: React.FC = () => {
show: showEditAlbumDetails,
props: editAlbumDetailsVisibilityProps,
} = useModalVisibility();
- const { show: showCollectionMap, props: collectionMapVisibilityProps } =
- useModalVisibility();
- const closeCollectionMap = collectionMapVisibilityProps.onClose;
const [isMapView, setIsMapView] = useState(false);
+ const closeCollectionMap = useCallback(() => setIsMapView(false), []);
- const handleShowCollectionMap = useCallback(
- (embedded = false) => {
- void (async () => {
- if (!mapEnabled) {
- try {
- await updateMapEnabled(true);
- } catch (e) {
- onGenericError(e);
- return;
- }
+ const handleShowCollectionMap = useCallback(() => {
+ void (async () => {
+ if (!mapEnabled) {
+ try {
+ await updateMapEnabled(true);
+ } catch (e) {
+ onGenericError(e);
+ return;
}
- if (embedded) setIsMapView(true);
- else showCollectionMap();
- })();
- },
- [mapEnabled, onGenericError, showCollectionMap],
- );
-
- const handleShowAlbumMap = useCallback(
- () => handleShowCollectionMap(),
- [handleShowCollectionMap],
- );
+ }
+ setIsMapView(true);
+ })();
+ }, [mapEnabled, onGenericError]);
const [albumAddedNotification, setAlbumAddedNotification] = useState<{
open: boolean;
@@ -2160,11 +2149,7 @@ const Page: React.FC = () => {
: handleShowCollectionSummaryWithID;
const collectionMap = activeCollectionSummary && (
- <CollectionMapDialog
- {...collectionMapVisibilityProps}
- embedded={isMapView}
- open={isMapView || collectionMapVisibilityProps.open}
- onClose={isMapView ? () => setIsMapView(false) : closeCollectionMap}
+ <CollectionMap
collectionSummary={activeCollectionSummary}
files={activeCollection ? activeCollectionFiles : filteredFiles}
mapFileSource={mapFileSource}
@@ -2228,6 +2213,10 @@ const Page: React.FC = () => {
isSettingsOpen={sidebarVisibilityProps.open}
mode={barMode}
isMapView={isMapView}
+ isMapSelected={
+ isMapView &&
+ activeCollectionID === PseudoCollectionID.all
+ }
onChangeMode={(mode) => {
const changed = handleChangeBarMode(mode);
if (changed) setIsMapView(false);
@@ -2239,7 +2228,7 @@ const Page: React.FC = () => {
handleShowCollectionSummaryWithID(
PseudoCollectionID.all,
);
- handleShowCollectionMap(true);
+ handleShowCollectionMap();
}}
onHome={() => {
setIsMapView(false);
@@ -2251,7 +2240,9 @@ const Page: React.FC = () => {
onSelectPeople={handleShowPeople}
onSelectPerson={handleSelectPerson}
galleryNavigation={
- isCleanupViewOpen || isMapView
+ isCleanupViewOpen ||
+ (isMapView &&
+ activeCollectionID === PseudoCollectionID.all)
? undefined
: {
activeCollectionID:
@@ -2344,7 +2335,7 @@ const Page: React.FC = () => {
setActiveCollectionID={selectGalleryCollection}
onSelectPerson={handleSelectPerson}
onEditAlbumDetails={showEditAlbumDetails}
- onShowMap={handleShowAlbumMap}
+ onShowMap={handleShowCollectionMap}
onCollectionSlideshow={startSlideshow}
emailByUserID={state.emailByUserID}
shareSuggestionEmails={
@@ -2564,7 +2555,6 @@ const Page: React.FC = () => {
onClose={closeSlideshow}
/>
)}
- {!isMapView && collectionMap}
{activeCollection && editAlbumDetailsVisibilityProps.open && (
<EditAlbumDetailsDialog
key={activeCollection.id}