π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Open newly created albums in Photos web (#14345)
Aswin Asok3cf615175960
diff --git a/web/apps/photos/src/components/CollectionDialog/styles.ts b/web/apps/photos/src/components/CollectionDialog/styles.tsindex 43fb068d27..b56e58fca0 100644--- a/web/apps/photos/src/components/CollectionDialog/styles.ts+++ b/web/apps/photos/src/components/CollectionDialog/styles.ts@@ -52,12 +52,6 @@ export const collectionDialogTitleSx = {textOverflow: "ellipsis",whiteSpace: "nowrap",};-export const collectionDialogBodyMutedSx = {- fontSize: 14,- lineHeight: "20px",- fontWeight: 500,- color: "text.muted",-};export const collectionDialogIconButtonSx = (theme: Theme) => ({width: 38,height: 38,diff --git a/web/apps/photos/src/components/collections/CreateAlbumDialog.tsx b/web/apps/photos/src/components/collections/CreateAlbumDialog.tsxindex 8aadc273e8..15dc545601 100644--- a/web/apps/photos/src/components/collections/CreateAlbumDialog.tsx+++ b/web/apps/photos/src/components/collections/CreateAlbumDialog.tsx@@ -1,139 +1,63 @@-import { collectionDialogBodyMutedSx as bodyMutedSx } from "@/components/CollectionDialog/styles";-import type { RemotePullOpts } from "@/components/gallery";-import ArrowForwardIcon from "@mui/icons-material/ArrowForward";-import CloseIcon from "@mui/icons-material/Close";-import {- Box,- DialogTitle,- Paper,- Snackbar,- Stack,- Typography,-} from "@mui/material";-import { FilledIconButton } from "ente-base/components/mui";import { SingleInputDialog } from "ente-base/components/SingleInputDialog";import type { ModalVisibilityProps } from "ente-base/components/utils/modal";+import type { Collection } from "ente-media/collection";import {createAlbum,createHiddenAlbum,+ renameCollection,} from "ente-new/photos/services/collection";-import { usePhotosAppContext } from "ente-new/photos/types/context";import { t } from "i18next";-import React, { useState } from "react";+import { useLayoutEffect, useRef, type FC } from "react";interface CreateAlbumDialogProps extends ModalVisibilityProps {isHidden: boolean;- onRemotePull: (opts?: RemotePullOpts) => Promise<void>;+ onRemoteFilesPull: () => Promise<void>;onSelectCollectionID: (id: number) => void;}-// Shared album creation flow, including refresh and success notification.-export const CreateAlbumDialog: React.FC<CreateAlbumDialogProps> = ({+export const CreateAlbumDialog: FC<CreateAlbumDialogProps> = ({open,onClose,isHidden,- onRemotePull,+ onRemoteFilesPull,onSelectCollectionID,}) => {- const { showNotification } = usePhotosAppContext();- const [albumCreatedToast, setAlbumCreatedToast] = useState<{- open: boolean;- albumId?: number;- albumName?: string;- }>({ open: false });-- const handleCreateAlbum = (albumName: string) => {- void (async () => {- try {- const newAlbum = isHidden- ? await createHiddenAlbum(albumName)- : await createAlbum(albumName);- await onRemotePull();+ const submission = useRef<{ album?: Collection }>({});+ useLayoutEffect(+ () => () => {+ submission.current = {};+ },+ [],+ );+ const handleClose = () => {+ submission.current = {};+ onClose();+ };- setAlbumCreatedToast({- open: true,- albumId: newAlbum.id,- albumName: albumName,- });- } catch {- showNotification({- color: "critical",- title: t("error"),- caption: t("generic_error_retry"),- });- }- })();+ const handleCreateAlbum = async (albumName: string): Promise<boolean> => {+ const pending = submission.current;+ if (!pending.album) {+ pending.album = isHidden+ ? await createHiddenAlbum(albumName)+ : await createAlbum(albumName);+ } else if (pending.album.name !== albumName) {+ await renameCollection(pending.album, albumName);+ pending.album = { ...pending.album, name: albumName };+ }+ await onRemoteFilesPull();+ if (pending !== submission.current) return false;+ onSelectCollectionID(pending.album.id);+ return true;};return (- <>- <SingleInputDialog- {...{ open, onClose }}- title={t("new_album")}- label={t("album_name")}- submitButtonTitle={t("create")}- onSubmit={handleCreateAlbum}- />- <Snackbar- open={albumCreatedToast.open}- anchorOrigin={{ horizontal: "right", vertical: "bottom" }}- >- <Paper sx={{ width: "min(360px, 100svw)" }}>- <DialogTitle>- <Stack- direction="row"- sx={{- justifyContent: "space-between",- alignItems: "center",- }}- >- <Box>- <Typography variant="h3">- {t("album_created")}- </Typography>- <Typography- sx={[bodyMutedSx, { marginTop: "4px" }]}- >- {albumCreatedToast.albumName &&- albumCreatedToast.albumName.length > 16- ? albumCreatedToast.albumName.substring(- 0,- 16,- ) + "..."- : albumCreatedToast.albumName}- </Typography>- </Box>- <Stack direction="row" sx={{ gap: 1 }}>- <FilledIconButton- onClick={() => {- if (albumCreatedToast.albumId) {- onSelectCollectionID(- albumCreatedToast.albumId,- );- }- setAlbumCreatedToast((prev) => ({- ...prev,- open: false,- }));- }}- >- <ArrowForwardIcon />- </FilledIconButton>- <FilledIconButton- onClick={() =>- setAlbumCreatedToast((prev) => ({- ...prev,- open: false,- }))- }- >- <CloseIcon />- </FilledIconButton>- </Stack>- </Stack>- </DialogTitle>- </Paper>- </Snackbar>- </>+ <SingleInputDialog+ open={open}+ onClose={handleClose}+ title={t("new_album")}+ label={t("album_name")}+ submitButtonTitle={t("create")}+ onSubmit={handleCreateAlbum}+ />);};diff --git a/web/apps/photos/src/components/gallery/hooks/use-gallery-operations.ts b/web/apps/photos/src/components/gallery/hooks/use-gallery-operations.tsindex fc16662f2f..166c35f419 100644--- a/web/apps/photos/src/components/gallery/hooks/use-gallery-operations.ts+++ b/web/apps/photos/src/components/gallery/hooks/use-gallery-operations.ts@@ -67,7 +67,6 @@ export const useGalleryOperations = (const {openCollectionSelector,albumNameInputVisibilityProps,- showCreateAlbum,handleOpenCollectionSelector,handleCloseCollectionSelector,handleAddSingleFileToCollection,@@ -115,7 +114,6 @@ export const useGalleryOperations = (onAddFileToCollection: handleAddSingleFileToCollection,setBlockingLoad,onUpload: openUploader,- onCreateAlbum: () => showCreateAlbum(),saveGroups,setSectionActivity,};diff --git a/web/apps/photos/src/components/gallery/media/use-collection-dialogs.ts b/web/apps/photos/src/components/gallery/media/use-collection-dialogs.tsindex 66a88ea1fc..054f363fab 100644--- a/web/apps/photos/src/components/gallery/media/use-collection-dialogs.ts+++ b/web/apps/photos/src/components/gallery/media/use-collection-dialogs.ts@@ -37,13 +37,13 @@ export const useCollectionDialogs = ({useState<CollectionSelectorAttributes>();const [creation, setCreation] = useState<{getOrCreate: (name: string) => Promise<Collection>;- onCreate?: (collection: Collection) => void | Promise<void>;+ onCreate: (collection: Collection) => void | Promise<void>;}>();const { show, props: albumNameInputVisibilityProps } = useModalVisibility();const showCreateAlbum = useCallback((- hidden = false,- onCreate?: (collection: Collection) => void | Promise<void>,+ hidden: boolean,+ onCreate: (collection: Collection) => void | Promise<void>,) => {let collection: Collection | undefined;setCreation({@@ -79,11 +79,7 @@ export const useCollectionDialogs = ({const request = creation;if (!request) return;const collection = await request.getOrCreate(name);- if (request.onCreate) await request.onCreate(collection);- else {- await remotePull();- showNotification({ color: "primary", title: t("album_created") });- }+ await request.onCreate(collection);setCreation((previous) =>previous === request ? undefined : previous,);diff --git a/web/apps/photos/src/components/gallery/sections/albums/AlbumsOverview.tsx b/web/apps/photos/src/components/gallery/sections/albums/AlbumsOverview.tsxindex 2effba8f90..4ae15dbf03 100644--- a/web/apps/photos/src/components/gallery/sections/albums/AlbumsOverview.tsx+++ b/web/apps/photos/src/components/gallery/sections/albums/AlbumsOverview.tsx@@ -33,7 +33,7 @@ interface AlbumsOverviewProps {filter: AlbumFilter | "links";searchQuery: string;sortBy: CollectionsSortBy;- onCreateAlbum: () => void;+ onCreateAlbum?: () => void;onRemotePull: (opts?: RemotePullOpts) => Promise<void>;}@@ -71,7 +71,8 @@ export const AlbumsOverview = ({filter == "empty-albums" &&hasEnoughEmptyAlbums &&!normalizedSearchQuery;- const showCreate = filter == "ente" && !normalizedSearchQuery;+ const showCreate =+ filter == "ente" && !normalizedSearchQuery && !!onCreateAlbum;const tileWidth = compact ? 104 : 140;const columnGap = compact ? 12 : 22;const rowGap = compact ? 16 : 24;@@ -230,7 +231,7 @@ interface AlbumRowData {tileWidth: number;showCreate: boolean;onSelectAlbum: (id: number) => void;- onCreateAlbum: () => void;+ onCreateAlbum?: () => void;}const AlbumsRow = ({diff --git a/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsx b/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsxindex 802555a512..4367d4e9b7 100644--- a/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsx+++ b/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsx@@ -113,7 +113,9 @@ export const AlbumsSection = ({props: editAlbumDetailsVisibilityProps,} = useModalVisibility();const createAlbum = useModalVisibility();- const { selectCollection, showAlbumOverview } = usePhotosNavigation();+ const [createFromOverview, setCreateFromOverview] = useState(false);+ const { selectCollection, showAlbumOverview, openOverviewAlbum } =+ usePhotosNavigation();const barCollectionSummaries =barMode == "hidden-albums"? library.hiddenCollectionSummaries@@ -295,7 +297,10 @@ export const AlbumsSection = ({library.uncategorizedCollectionSummaryID}activeCollectionID={activeCollectionID}- onCreateAlbum={createAlbum.show}+ onCreateAlbum={() => {+ setCreateFromOverview(false);+ createAlbum.show();+ }}collectionsSortBy={collectionsSortBy}onChangeCollectionsSortBy={onChangeCollectionsSortBy}/>@@ -322,7 +327,10 @@ export const AlbumsSection = ({filter={overviewFilter!}searchQuery={albumSearchQuery}sortBy={collectionsSortBy}- onCreateAlbum={operations.onCreateAlbum}+ onCreateAlbum={() => {+ setCreateFromOverview(true);+ createAlbum.show();+ }}/>) : (<GalleryMedia@@ -373,9 +381,10 @@ export const AlbumsSection = ({<CreateAlbumDialog{...createAlbum.props}isHidden={barMode == "hidden-albums"}- onRemotePull={remotePull}+ onRemoteFilesPull={remoteFilesPull}onSelectCollectionID={(id) => {- selectCollection(id);+ if (createFromOverview) openOverviewAlbum(id);+ else selectCollection(id);presentation.mobileDrawerProps.onClose();}}/>diff --git a/web/apps/photos/src/components/gallery/sections/links/LinksSection.tsx b/web/apps/photos/src/components/gallery/sections/links/LinksSection.tsxindex 3074b92318..c21aefdb7e 100644--- a/web/apps/photos/src/components/gallery/sections/links/LinksSection.tsx+++ b/web/apps/photos/src/components/gallery/sections/links/LinksSection.tsx@@ -27,7 +27,6 @@ export const LinksSection = ({onSearchQueryChange={preferences.setAlbumSearchQuery}sortBy={preferences.collectionsSortBy}onChangeSortBy={preferences.onChangeCollectionsSortBy}- onCreateAlbum={operations.onCreateAlbum}setBlockingLoad={operations.setBlockingLoad}onRemotePull={operations.onRemotePull}/>diff --git a/web/apps/photos/src/components/gallery/sections/links/LinksView.tsx b/web/apps/photos/src/components/gallery/sections/links/LinksView.tsxindex 866703871c..5d12189435 100644--- a/web/apps/photos/src/components/gallery/sections/links/LinksView.tsx+++ b/web/apps/photos/src/components/gallery/sections/links/LinksView.tsx@@ -35,7 +35,6 @@ interface LinksViewProps {selectedLinkID: number | undefined;searchQuery: string;sortBy: CollectionsSortBy;- onCreateAlbum: () => void;setBlockingLoad: (value: boolean) => void;onRemotePull: (opts?: RemotePullOpts) => Promise<void>;}@@ -56,7 +55,6 @@ export const LinksView = ({selectedLinkID,searchQuery,sortBy,- onCreateAlbum,setBlockingLoad,onRemotePull,}: LinksViewProps) => {@@ -131,7 +129,6 @@ export const LinksView = ({filter="links"searchQuery={searchQuery}sortBy={sortBy}- onCreateAlbum={onCreateAlbum}onRemotePull={onRemotePull}/>);diff --git a/web/apps/photos/src/components/gallery/sections/types.ts b/web/apps/photos/src/components/gallery/sections/types.tsindex 4c8560b417..6c4d26f01d 100644--- a/web/apps/photos/src/components/gallery/sections/types.ts+++ b/web/apps/photos/src/components/gallery/sections/types.ts@@ -40,7 +40,6 @@ export type GallerySectionOperations = Pick<onSendLink: (file: EnteFile) => Promise<void>;setBlockingLoad: Dispatch<SetStateAction<boolean>>;onUpload: (intent?: UploadTypeSelectorIntent) => void;- onCreateAlbum: () => void;saveGroups: ReturnType<typeof useSaveGroups>["saveGroups"];setSectionActivity: Dispatch<SetStateAction<{ selection: boolean; drop: boolean }>diff --git a/web/apps/photos/tests/albums-section-summary.test.tsx b/web/apps/photos/tests/albums-section-summary.test.tsxindex f115bcbfea..f3f62d498e 100644--- a/web/apps/photos/tests/albums-section-summary.test.tsx+++ b/web/apps/photos/tests/albums-section-summary.test.tsx@@ -140,7 +140,6 @@ const headerSummary = (state: GalleryState, collectionID = 10) => {onAddFileToCollection: vi.fn(),setBlockingLoad: vi.fn(),onUpload: vi.fn(),- onCreateAlbum: vi.fn(),saveGroups: [],setSectionActivity: vi.fn(),},diff --git a/web/apps/photos/tests/links-view.test.tsx b/web/apps/photos/tests/links-view.test.tsxindex 8f1514c55a..5889832117 100644--- a/web/apps/photos/tests/links-view.test.tsx+++ b/web/apps/photos/tests/links-view.test.tsx@@ -121,7 +121,6 @@ const props = (selectedLinkID: undefined,searchQuery: "",sortBy: "updation-time-desc",- onCreateAlbum: vi.fn(),setBlockingLoad: vi.fn(),onRemotePull: vi.fn().mockResolvedValue(undefined),};@@ -153,7 +152,6 @@ test("derives the overview from library data with shared sorting and search", ()expect(overview.searchQuery).toBe(" SUMMER ");expect(overview.sortBy).toBe("name-asc");expect(overview.onRemotePull).toBe(input.onRemotePull);- expect(overview.onCreateAlbum).toBe(input.onCreateAlbum);expect(PublicLinkDetails).not.toHaveBeenCalled();expect(summaries.get(2)?.sortPriority).toBe(7);expect(input.collections.map(({ id }) => id)).toEqual([1, 2, 3, 4, 5]);diff --git a/web/packages/base/components/SingleInputDialog.tsx b/web/packages/base/components/SingleInputDialog.tsxindex 4e0dc053b3..a372547afe 100644--- a/web/packages/base/components/SingleInputDialog.tsx+++ b/web/packages/base/components/SingleInputDialog.tsx@@ -19,8 +19,12 @@ import {import { SingleInputForm, type SingleInputFormProps } from "./SingleInputForm";type SingleInputDialogProps = ModalVisibilityProps &- Omit<SingleInputFormProps, "onCancel"> & {+ Omit<SingleInputFormProps, "onCancel" | "onSubmit"> & {title: string;+ onSubmit: (+ value: string,+ setFieldError: (message: string) => void,+ ) => ReturnType<SingleInputFormProps["onSubmit"]> | Promise<boolean>;description?: string;sx?: SxProps<Theme>;};@@ -40,11 +44,11 @@ export const SingleInputDialog: React.FC<SingleInputDialogProps> = ({const handleSubmit: SingleInputFormProps["onSubmit"] = useCallback(async (value, setFieldError) => {const submission = { hasError: false };- await onSubmit(value, (message) => {+ const result = await onSubmit(value, (message) => {submission.hasError = true;setFieldError(message);});- if (!submission.hasError) onClose();+ if (result !== false && !submission.hasError) onClose();},[onClose, onSubmit],);diff --git a/web/packages/base/components/mui/index.tsx b/web/packages/base/components/mui/index.tsxindex 1bfe205710..5a57e05367 100644--- a/web/packages/base/components/mui/index.tsx+++ b/web/packages/base/components/mui/index.tsx@@ -1,9 +1,3 @@-import { IconButton, styled } from "@mui/material";-export interface ButtonishProps {onClick: () => void;}--export const FilledIconButton = styled(IconButton)(({ theme }) => ({- backgroundColor: theme.vars.palette.fill.faint,-}));diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex c2d5993c9e..8fedd6deed 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -60,7 +60,6 @@"new_album": "New album","create_albums": "Create albums","album_name": "Album name",- "album_created": "Album created","join_album": "Join album","joined_album": "Joined album","album_join_failed": "Failed to join album",