Skip to content

armgit / ente

Public Imported from GitHub
0

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

update(UploadFlow):update-the-CollectionSelector-and-name-to-v2

Aswin Asok2a6eb04031bf
diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsx
index b6ad039e66..d1d4de0bc8 100644
--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx
+++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx
@@ -31,6 +31,7 @@ import {
LargeTileCreateNewButton,
LargeTileTextOverlay,
} from "ente-new/photos/components/Tiles";
+import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
import {
createAlbum,
createHiddenAlbum,
@@ -79,6 +80,7 @@ export const AllAlbums: React.FC<AllAlbums> = ({
const fullScreen = useMediaQuery("(max-width: 428px)");
const [searchTerm, setSearchTerm] = useState("");
const { showNotification } = usePhotosAppContext();
+ const { isInternalUser } = useSettingsSnapshot();
const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } =
useModalVisibility();
const [albumCreatedToast, setAlbumCreatedToast] = useState<{
@@ -172,6 +174,7 @@ export const AllAlbums: React.FC<AllAlbums> = ({
</AllAlbumsDialog>
<SingleInputDialog
{...albumNameInputVisibilityProps}
+ variant={isInternalUser ? "v2" : "default"}
title={t("new_album")}
label={t("album_name")}
submitButtonTitle={t("create")}
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx
index 15d0ab4f44..c371739a48 100644
--- a/web/apps/photos/src/components/Upload.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -1452,6 +1452,7 @@ export const Upload: React.FC<UploadProps> = ({
)}
<SingleInputDialog
{...newAlbumNameInputVisibilityProps}
+ variant={isInternalUser ? "v2" : "default"}
onClose={handleNewAlbumNameInputClose}
title={t("new_album")}
label={t("album_name")}
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index e6b64a041d..a336a90b06 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -2316,13 +2316,14 @@ const Page: React.FC = () => {
/>
<SingleInputDialog
{...albumNameInputVisibilityProps}
+ variant={isInternalUser ? "v2" : "default"}
title={t("new_album")}
label={t("album_name")}
submitButtonTitle={t("create")}
onClose={() => {
// If the user dismisses the album name dialog without
- // submitting, clear any pending single-file add so that it
- // doesn't leak into a future album creation.
+ // submitting, clear any pending single-file add so that
+ // it doesn't leak into a future album creation.
pendingSingleFileAdd.current = undefined;
albumNameInputVisibilityProps.onClose();
}}
diff --git a/web/packages/base/components/SingleInputDialog.tsx b/web/packages/base/components/SingleInputDialog.tsx
index 9a1cf64b69..ba32e198db 100644
--- a/web/packages/base/components/SingleInputDialog.tsx
+++ b/web/packages/base/components/SingleInputDialog.tsx
@@ -1,9 +1,20 @@
-import { Dialog, DialogContent, DialogTitle } from "@mui/material";
+import CloseIcon from "@mui/icons-material/Close";
+import {
+ Dialog,
+ DialogContent,
+ DialogTitle,
+ IconButton,
+ Stack,
+ Typography,
+ type SxProps,
+ type Theme,
+} from "@mui/material";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
+import { t } from "i18next";
import React, { useCallback } from "react";
import { SingleInputForm, type SingleInputFormProps } from "./SingleInputForm";
-type SingleInputDialogProps = ModalVisibilityProps &
+export type SingleInputDialogProps = ModalVisibilityProps &
Omit<SingleInputFormProps, "onCancel"> & {
/** Title of the dialog. */
title: string;
@@ -23,6 +34,7 @@ export const SingleInputDialog: React.FC<SingleInputDialogProps> = ({
onClose,
onSubmit,
title,
+ variant = "default",
...rest
}) => {
const handleSubmit: SingleInputFormProps["onSubmit"] = useCallback(
@@ -33,6 +45,37 @@ export const SingleInputDialog: React.FC<SingleInputDialogProps> = ({
[onClose, onSubmit],
);
+ if (variant === "v2") {
+ return (
+ <Dialog
+ open={open}
+ onClose={onClose}
+ maxWidth={false}
+ slotProps={{ paper: { sx: v2PaperSx } }}
+ >
+ <Stack sx={{ p: "20px", gap: "20px" }}>
+ <Stack direction="row" sx={v2HeaderRowSx}>
+ <Typography sx={v2TitleSx}>{title}</Typography>
+ <IconButton
+ aria-label={t("close")}
+ onClick={onClose}
+ sx={v2CloseButtonSx}
+ >
+ <CloseIcon sx={{ fontSize: 18 }} />
+ </IconButton>
+ </Stack>
+ <SingleInputForm
+ key={open ? "open" : "closed"}
+ variant="v2"
+ onCancel={onClose}
+ onSubmit={handleSubmit}
+ {...rest}
+ />
+ </Stack>
+ </Dialog>
+ );
+ }
+
return (
<Dialog
open={open}
@@ -52,3 +95,41 @@ export const SingleInputDialog: React.FC<SingleInputDialogProps> = ({
</Dialog>
);
};
+
+const surfaceStroke = "#e0e0e0";
+const surfaceStrokeDark = "rgba(255 255 255 / 0.12)";
+
+const v2PaperSx: SxProps<Theme> = (theme) => ({
+ width: "min(444px, calc(100svw - 32px))",
+ maxWidth: "444px",
+ boxSizing: "content-box",
+ m: 2,
+ borderRadius: "20px",
+ border: `1px solid ${surfaceStroke}`,
+ backgroundColor: "#f4f4f4",
+ backgroundImage: "none",
+ boxShadow: "none",
+ color: "text.base",
+ ...theme.applyStyles("dark", {
+ borderColor: surfaceStrokeDark,
+ backgroundColor: "#1b1b1b",
+ }),
+});
+const v2HeaderRowSx = {
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: "12px",
+};
+const v2TitleSx = { fontSize: 24, lineHeight: "32px", fontWeight: 600 };
+const v2CloseButtonSx = (theme: Theme) => ({
+ width: 38,
+ height: 38,
+ p: 0,
+ flexShrink: 0,
+ color: "text.base",
+ backgroundColor: "background.paper",
+ "&:hover": { backgroundColor: "fill.faintHover" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+});
diff --git a/web/packages/base/components/SingleInputForm.tsx b/web/packages/base/components/SingleInputForm.tsx
index 24c4c24bb8..8bdc04169a 100644
--- a/web/packages/base/components/SingleInputForm.tsx
+++ b/web/packages/base/components/SingleInputForm.tsx
@@ -1,8 +1,14 @@
import {
+ ButtonBase,
+ CircularProgress,
+ InputBase,
Stack,
TextField,
+ Typography,
type ButtonProps,
+ type SxProps,
type TextFieldProps,
+ type Theme,
} from "@mui/material";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
@@ -16,6 +22,8 @@ export type SingleInputFormProps = Pick<
TextFieldProps,
"label" | "placeholder" | "autoComplete" | "autoFocus" | "slotProps"
> & {
+ /** Visual treatment for the form. */
+ variant?: "default" | "v2";
/**
* The type attribute of the HTML input element that will be used.
*
@@ -96,6 +104,7 @@ export type SingleInputFormProps = Pick<
* the {@link autoFocus} to disable this behaviour if needed.
*/
export const SingleInputForm: React.FC<SingleInputFormProps> = ({
+ variant = "default",
inputType,
initialValue,
autoFocus,
@@ -114,6 +123,7 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
const formik = useFormik({
initialValues: { value: initialValue ?? "" },
+ enableReinitialize: variant === "v2",
onSubmit: async (values, { setFieldError }) => {
const value = values.value;
const setValueFieldError = (message: string) =>
@@ -132,6 +142,63 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
},
});
+ if (variant === "v2") {
+ const error = formik.errors.value;
+ return (
+ <Stack
+ component="form"
+ onSubmit={formik.handleSubmit}
+ sx={{ gap: "20px" }}
+ >
+ <Stack sx={{ gap: "8px" }}>
+ {rest.label && (
+ <Typography sx={v2LabelSx}>{rest.label}</Typography>
+ )}
+ <InputBase
+ name="value"
+ value={formik.values.value}
+ onChange={formik.handleChange}
+ type={inputType ?? "text"}
+ placeholder={rest.placeholder}
+ autoComplete={rest.autoComplete}
+ autoFocus={autoFocus ?? true}
+ disabled={formik.isSubmitting}
+ error={!!error}
+ sx={v2InputSx}
+ />
+ <Typography sx={v2HelperSx(!!error)}>
+ {error ?? ""}
+ </Typography>
+ </Stack>
+ <Stack direction="row" sx={{ gap: "12px" }}>
+ {onCancel && (
+ <ButtonBase
+ onClick={onCancel}
+ disabled={formik.isSubmitting}
+ sx={v2CancelButtonSx}
+ >
+ {t("cancel")}
+ </ButtonBase>
+ )}
+ <ButtonBase
+ type="submit"
+ disabled={formik.isSubmitting}
+ sx={v2SubmitButtonSx}
+ >
+ {formik.isSubmitting ? (
+ <CircularProgress
+ size={20}
+ sx={{ color: "#fff" }}
+ />
+ ) : (
+ submitButtonTitle
+ )}
+ </ButtonBase>
+ </Stack>
+ </Stack>
+ );
+ }
+
const submitButton = (
<LoadingButton
fullWidth
@@ -196,3 +263,71 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
</form>
);
};
+
+const greenAccent = "#08c225";
+const greenAccentHover = "#07ad21";
+const errorColor = "#fa1336";
+
+const v2LabelSx = {
+ fontSize: 12,
+ lineHeight: "16px",
+ fontWeight: 500,
+ color: "text.muted",
+};
+const v2InputSx: SxProps<Theme> = (theme) => ({
+ height: 52,
+ boxSizing: "content-box",
+ display: "flex",
+ alignItems: "center",
+ borderRadius: "16px",
+ border: "1px solid transparent",
+ backgroundColor: "background.paper",
+ px: "16px",
+ fontSize: 14,
+ fontWeight: 500,
+ color: "text.base",
+ "&.Mui-focused": { borderColor: greenAccent },
+ "&.Mui-error": { borderColor: errorColor },
+ "& input": { padding: 0, height: "auto" },
+ "& input::placeholder": { color: "text.muted", opacity: 1 },
+ ...theme.applyStyles("dark", { backgroundColor: "#282828" }),
+});
+const v2HelperSx = (isError: boolean) => (theme: Theme) => ({
+ fontSize: 12,
+ lineHeight: "16px",
+ fontWeight: 500,
+ color: isError ? errorColor : "rgba(0 0 0 / 0.45)",
+ ...(isError
+ ? {}
+ : theme.applyStyles("dark", { color: "rgba(255 255 255 / 0.45)" })),
+});
+const v2BaseActionSx = {
+ flex: 1,
+ height: 52,
+ borderRadius: "20px",
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ "&.Mui-disabled": { opacity: 0.7 },
+};
+const v2CancelButtonSx = (theme: Theme) => ({
+ ...v2BaseActionSx,
+ color: "text.base",
+ backgroundColor: "#eaeaea",
+ "&:hover": { backgroundColor: "#dedede" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ "&:hover": { backgroundColor: "rgba(255 255 255 / 0.18)" },
+ }),
+});
+const v2SubmitButtonSx = {
+ ...v2BaseActionSx,
+ color: "#fff",
+ backgroundColor: greenAccent,
+ "&:hover": { backgroundColor: greenAccentHover },
+ "&.Mui-disabled": {
+ color: "#fff",
+ backgroundColor: greenAccent,
+ opacity: 0.7,
+ },
+};
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index da8d193d87..31418b81b4 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -26,24 +26,18 @@ import {
LargeTileCreateNewButton,
LargeTileTextOverlay,
} from "ente-new/photos/components/Tiles";
-import {
- canAddToCollection,
- canMoveToCollection,
- collectionsSortBy,
- sortCollectionSummaries,
- type CollectionsSortBy,
- type CollectionSummaries,
- type CollectionSummary,
+import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
+import type {
+ CollectionSummaries,
+ CollectionSummary,
} from "ente-new/photos/services/collection-summary";
-import { includes } from "ente-utils/type-guards";
import { t } from "i18next";
-import React, {
- useCallback,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from "react";
+import React, { useRef } from "react";
+import { CollectionSelectorV2 } from "./CollectionSelectorV2";
+import {
+ collectionSelectorTitle,
+ useCollectionSelector,
+} from "./useCollectionSelector";
export type CollectionSelectorAction =
| "upload"
@@ -96,7 +90,7 @@ export interface CollectionSelectorAttributes {
onCancel?: () => void;
}
-type CollectionSelectorProps = ModalVisibilityProps & {
+export type CollectionSelectorProps = ModalVisibilityProps & {
/** Callback fired after the selector has finished closing. */
onExited?: () => void;
/**
@@ -138,128 +132,51 @@ type CollectionSelectorProps = ModalVisibilityProps & {
/**
* A dialog allowing the user to select one of their existing collections or
* create a new one.
+ *
+ * For internal users this renders the restyled {@link CollectionSelectorV2}
+ * variant; everyone else continues to get the classic implementation below.
+ * Both share the exact same props and behaviour.
*/
-export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
- open,
- onClose,
- onExited,
- attributes,
- collectionSummaries,
- collectionForCollectionSummaryID,
-}) => {
+export const CollectionSelector: React.FC<CollectionSelectorProps> = (
+ props,
+) => {
+ const { isInternalUser } = useSettingsSnapshot();
+ return isInternalUser ? (
+ <CollectionSelectorV2 {...props} />
+ ) : (
+ <CollectionSelectorClassic {...props} />
+ );
+};
+
+const CollectionSelectorClassic: React.FC<CollectionSelectorProps> = (
+ props,
+) => {
// Make the dialog fullscreen if the screen is <= the dialog's max width.
const isFullScreen = useMediaQuery("(max-width: 490px)");
-
- const [searchTerm, setSearchTerm] = useState("");
- const [sortBy, setSortBy] =
- useCollectionSelectorSortByLocalState("name-asc");
-
- const [filteredCollections, setFilteredCollections] = useState<
- CollectionSummary[]
- >([]);
-
- const handleExited = useCallback(() => {
- setSearchTerm("");
- onExited?.();
- }, [onExited]);
-
- useEffect(() => {
- if (!attributes || !open) {
- return;
- }
-
- const activeCollectionID = attributes.activeCollectionID;
- const filteredCollections = [...collectionSummaries.values()].filter(
- (cs) => {
- if (cs.id === attributes.sourceCollectionSummaryID) {
- return false;
- } else if (
- attributes.action == "add" ||
- attributes.action == "move"
- ) {
- return canAddToCollection(cs) && cs.type != "userFavorites";
- } else if (attributes.action == "upload") {
- return (
- (canAddToCollection(cs) ||
- cs.type == "uncategorized") &&
- cs.type != "userFavorites"
- );
- } else if (attributes.action == "restore") {
- return (
- (canMoveToCollection(cs) ||
- cs.type == "uncategorized") &&
- cs.type != "userFavorites"
- );
- } else {
- // "unhide"
- return (
- canMoveToCollection(cs) && cs.type != "userFavorites"
- );
- }
- },
- );
-
- const collections = sortCollectionSummaries(filteredCollections, sortBy)
- .sort((a, b) => b.sortPriority - a.sortPriority)
- .sort((a, b) => {
- // Prioritize the active collection (if any) to appear first.
- if (a.id === activeCollectionID) return -1;
- if (b.id === activeCollectionID) return 1;
- return 0;
- });
-
- if (collections.length === 0) {
- onClose();
- attributes.onCreateCollection();
- handleExited();
- }
-
- setFilteredCollections(collections);
- }, [collectionSummaries, attributes, open, onClose, sortBy, handleExited]);
-
- const searchFilteredCollections = useMemo(() => {
- if (!searchTerm.trim()) {
- return filteredCollections;
- }
- const searchLower = searchTerm.toLowerCase();
- return filteredCollections.filter((cs) =>
- cs.name.toLowerCase().includes(searchLower),
- );
- }, [filteredCollections, searchTerm]);
-
- const showCreateButton = useMemo(() => {
- if (!searchTerm.trim()) {
- return true;
- }
- const searchLower = searchTerm.toLowerCase();
- const createText = t("create_albums").toLowerCase();
- return createText.includes(searchLower);
- }, [searchTerm]);
-
- if (!filteredCollections.length) {
- return <></>;
- }
-
- if (!attributes) {
- return <></>;
- }
-
- const { action, onSelectCollection, onCancel, onCreateCollection } =
- attributes;
-
- const handleCollectionSummaryClick = async (id: number) => {
- onSelectCollection(await collectionForCollectionSummaryID(id));
- onClose();
- };
-
- const handleClose = () => {
- onCancel?.();
- onClose();
- };
+ const {
+ attributes,
+ searchTerm,
+ setSearchTerm,
+ sortBy,
+ setSortBy,
+ filteredCollections,
+ searchFilteredCollections,
+ showCreateButton,
+ handleExited,
+ handleCollectionSummaryClick,
+ handleClose,
+ } = useCollectionSelector({
+ ...props,
+ createCollectionLabel: t("create_albums"),
+ });
+
+ if (!filteredCollections.length || !attributes) return null;
+
+ const { action, onCreateCollection } = attributes;
return (
<StyledDialog
- open={open}
+ open={props.open}
onClose={handleClose}
fullWidth
fullScreen={isFullScreen}
@@ -279,7 +196,7 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
<Stack sx={{ flex: 1 }}>
<Box>
<Typography variant="h5">
- {titleForAction(action)}
+ {collectionSelectorTitle(action)}
</Typography>
<Typography
variant="small"
@@ -358,21 +275,6 @@ const NoResultsContent = styled(DialogContent)`
min-height: 154px;
`;
-const titleForAction = (action: CollectionSelectorAction) => {
- switch (action) {
- case "upload":
- return t("upload_to_album");
- case "add":
- return t("add_to_album");
- case "move":
- return t("move_to_album");
- case "restore":
- return t("restore_to_album");
- case "unhide":
- return t("unhide_to_album");
- }
-};
-
interface CollectionSummaryButtonProps {
collectionSummary: CollectionSummary;
onClick: (collectionSummaryID: number) => void;
@@ -509,27 +411,3 @@ const SearchField: React.FC<SearchFieldProps> = ({ value, onChange }) => {
/>
);
};
-
-/**
- * A hook that maintains the collection selector sort order both as in-memory
- * and local storage state.
- */
-const useCollectionSelectorSortByLocalState = (
- initialValue: CollectionsSortBy,
-) => {
- const key = "collectionSelectorSortBy";
-
- const [value, setValue] = useState(initialValue);
-
- useEffect(() => {
- const value = localStorage.getItem(key);
- if (value && includes(collectionsSortBy, value)) setValue(value);
- }, []);
-
- const setter = (value: CollectionsSortBy) => {
- localStorage.setItem(key, value);
- setValue(value);
- };
-
- return [value, setter] as const;
-};
diff --git a/web/packages/new/photos/components/CollectionSelectorV2.tsx b/web/packages/new/photos/components/CollectionSelectorV2.tsx
new file mode 100644
index 0000000000..26a9ee5b9e
--- /dev/null
+++ b/web/packages/new/photos/components/CollectionSelectorV2.tsx
@@ -0,0 +1,389 @@
+import AddIcon from "@mui/icons-material/Add";
+import CloseIcon from "@mui/icons-material/Close";
+import FavoriteIcon from "@mui/icons-material/Favorite";
+import PushPinIcon from "@mui/icons-material/PushPin";
+import SearchIcon from "@mui/icons-material/Search";
+import {
+ Box,
+ Dialog,
+ IconButton,
+ InputBase,
+ Stack,
+ styled,
+ Tooltip,
+ Typography,
+ useMediaQuery,
+ type SxProps,
+ type Theme,
+} from "@mui/material";
+import { CollectionsSortOptions } from "ente-new/photos/components/CollectionsSortOptions";
+import { BaseTileButton, ItemCard } from "ente-new/photos/components/Tiles";
+import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
+import { t } from "i18next";
+import React from "react";
+import type { CollectionSelectorProps } from "./CollectionSelector";
+import {
+ collectionSelectorTitle,
+ useCollectionSelector,
+} from "./useCollectionSelector";
+
+/**
+ * The internal-only ("v2") variant of {@link CollectionSelector}, restyled to
+ * match the upload design system (paper surfaces, hairline borders, radius 20
+ * dialog, 16px tiles, paper-filled 38px icon buttons).
+ *
+ * It preserves the exact same behaviour and props as the classic selector; only
+ * the presentation differs. See {@link CollectionSelector} for a description of
+ * the props.
+ */
+export const CollectionSelectorV2: React.FC<CollectionSelectorProps> = (
+ props,
+) => {
+ // Make the dialog fullscreen if the screen is <= the dialog's max width.
+ const isFullScreen = useMediaQuery("(max-width: 490px)");
+ const {
+ attributes,
+ searchTerm,
+ setSearchTerm,
+ sortBy,
+ setSortBy,
+ filteredCollections,
+ searchFilteredCollections,
+ showCreateButton,
+ handleExited,
+ handleCollectionSummaryClick,
+ handleClose,
+ } = useCollectionSelector({
+ ...props,
+ createCollectionLabel: t("new_album"),
+ });
+
+ if (!filteredCollections.length || !attributes) return null;
+
+ const { action, onCreateCollection } = attributes;
+
+ return (
+ <Dialog
+ open={props.open}
+ onClose={handleClose}
+ fullScreen={isFullScreen}
+ maxWidth={false}
+ slotProps={{
+ paper: { sx: paperSx },
+ transition: { onExited: handleExited },
+ }}
+ >
+ <Stack sx={headerSx}>
+ <Stack direction="row" sx={headerRowSx}>
+ <Stack sx={{ minWidth: 0, gap: "2px" }}>
+ <Typography sx={titleSx}>
+ {collectionSelectorTitle(action)}
+ </Typography>
+ <Typography sx={countSx}>
+ {searchTerm
+ ? `${searchFilteredCollections.length} / ${filteredCollections.length} ${t("albums")}`
+ : t("albums_count", {
+ count: filteredCollections.length,
+ })}
+ </Typography>
+ </Stack>
+ <Stack direction="row" sx={headerActionsSx}>
+ <CollectionsSortOptions
+ activeSortBy={sortBy}
+ onChangeSortBy={setSortBy}
+ nestedInDialog
+ variant="v2"
+ />
+ <IconButton
+ aria-label={t("close")}
+ onClick={handleClose}
+ sx={iconButtonSx}
+ >
+ <CloseIcon sx={{ fontSize: 18 }} />
+ </IconButton>
+ </Stack>
+ </Stack>
+ <SearchFieldV2 value={searchTerm} onChange={setSearchTerm} />
+ </Stack>
+ <Box sx={dividerSx} />
+ {searchFilteredCollections.length === 0 && !showCreateButton ? (
+ <Box sx={noResultsSx}>
+ <Typography sx={{ color: "text.muted" }}>
+ {t("no_results")}
+ </Typography>
+ </Box>
+ ) : (
+ <Box sx={gridSx}>
+ {showCreateButton && (
+ <CreateAlbumTile onClick={onCreateCollection} />
+ )}
+ {searchFilteredCollections.map((collectionSummary) => (
+ <CollectionSummaryButtonV2
+ key={collectionSummary.id}
+ collectionSummary={collectionSummary}
+ onClick={handleCollectionSummaryClick}
+ />
+ ))}
+ </Box>
+ )}
+ </Dialog>
+ );
+};
+
+const surfaceStroke = "#e0e0e0";
+const surfaceStrokeDark = "rgba(255 255 255 / 0.12)";
+
+const paperSx: SxProps<Theme> = (theme) => ({
+ width: "min(500px, calc(100svw - 32px))",
+ maxWidth: "500px",
+ boxSizing: "content-box",
+ borderRadius: "20px",
+ border: `1px solid ${surfaceStroke}`,
+ backgroundColor: "#f4f4f4",
+ backgroundImage: "none",
+ boxShadow: "none",
+ color: "text.base",
+ "@media (min-width: 491px)": { height: "100%" },
+ "@media (max-width: 490px)": {
+ width: "100%",
+ maxWidth: "100%",
+ height: "100%",
+ boxSizing: "border-box",
+ borderRadius: 0,
+ border: "none",
+ },
+ ...theme.applyStyles("dark", {
+ borderColor: surfaceStrokeDark,
+ backgroundColor: "#1b1b1b",
+ }),
+});
+
+const headerSx = { p: "20px", gap: "16px" };
+const headerRowSx = {
+ alignItems: "flex-start",
+ justifyContent: "space-between",
+ gap: "12px",
+};
+const headerActionsSx = { alignItems: "center", gap: 1, flexShrink: 0 };
+const titleSx = {
+ fontSize: 24,
+ lineHeight: "32px",
+ fontWeight: 600,
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+};
+const countSx = {
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ color: "text.muted",
+};
+const iconButtonSx = (theme: Theme) => ({
+ width: 38,
+ height: 38,
+ p: 0,
+ color: "text.base",
+ backgroundColor: "background.paper",
+ "&:hover": { backgroundColor: "fill.faintHover" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+});
+const dividerSx = (theme: Theme) => ({
+ height: "1px",
+ backgroundColor: "rgba(0 0 0 / 0.06)",
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.08)",
+ }),
+});
+const gridSx = {
+ flex: 1,
+ minHeight: 0,
+ p: "16px 20px 20px",
+ display: "grid",
+ gridTemplateColumns: "repeat(3, minmax(0, 1fr))",
+ gap: "8px",
+ alignContent: "start",
+ overflowY: "auto",
+};
+const noResultsSx = {
+ flex: 1,
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+ minHeight: 154,
+};
+
+const TileButtonV2 = styled(BaseTileButton)`
+ width: 100%;
+ aspect-ratio: 1;
+ height: auto;
+ border-radius: 16px;
+`;
+
+const TopGradientOverlay = styled("div")`
+ position: absolute;
+ inset: 0;
+ padding: 10px;
+ color: #fff;
+ background: linear-gradient(
+ -10deg,
+ rgba(0, 0, 0, 0.1) 0%,
+ rgba(0, 0, 0, 0.2) 50%,
+ rgba(0, 0, 0, 0.4) 60%,
+ rgba(0, 0, 0, 0.6) 100%
+ );
+`;
+
+interface CollectionSummaryButtonV2Props {
+ collectionSummary: CollectionSummary;
+ onClick: (collectionSummaryID: number) => void;
+}
+
+const CollectionSummaryButtonV2: React.FC<CollectionSummaryButtonV2Props> = ({
+ collectionSummary,
+ onClick,
+}) => {
+ const isFavorite = collectionSummary.type === "userFavorites";
+ const isPinned =
+ collectionSummary.attributes.has("pinned") ||
+ collectionSummary.attributes.has("shareePinned");
+
+ return (
+ <ItemCard
+ TileComponent={TileButtonV2}
+ coverFile={collectionSummary.coverFile}
+ onClick={() => onClick(collectionSummary.id)}
+ >
+ <TopGradientOverlay>
+ <Tooltip title={collectionSummary.name} arrow>
+ <Typography
+ sx={{
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ display: "-webkit-box",
+ WebkitLineClamp: 3,
+ WebkitBoxOrient: "vertical",
+ }}
+ >
+ {collectionSummary.name}
+ </Typography>
+ </Tooltip>
+ </TopGradientOverlay>
+ {(isFavorite || isPinned) && (
+ <Box
+ sx={{
+ position: "absolute",
+ bottom: 8,
+ right: 8,
+ display: "flex",
+ gap: 0.5,
+ }}
+ >
+ {isFavorite && (
+ <FavoriteIcon sx={{ fontSize: 20, color: "white" }} />
+ )}
+ {isPinned && (
+ <PushPinIcon sx={{ fontSize: 20, color: "white" }} />
+ )}
+ </Box>
+ )}
+ </ItemCard>
+ );
+};
+
+const CreateAlbumTile: React.FC<{ onClick: () => void }> = ({ onClick }) => (
+ <TileButtonV2 onClick={onClick} sx={{ borderRadius: "16px" }}>
+ <CreateTileInner>
+ <Typography
+ sx={{ fontSize: 14, lineHeight: "20px", fontWeight: 500 }}
+ >
+ {t("new_album")}
+ </Typography>
+ <Box sx={createTileIconSx}>
+ <AddIcon />
+ </Box>
+ </CreateTileInner>
+ </TileButtonV2>
+);
+
+const CreateTileInner = styled("span")(({ theme }) => ({
+ position: "absolute",
+ inset: 0,
+ padding: 10,
+ display: "flex",
+ flexDirection: "column",
+ border: "1px dashed",
+ borderColor: theme.vars.palette.stroke.muted,
+ borderRadius: 16,
+ color: theme.vars.palette.text.base,
+ "&:hover": { borderColor: "rgba(0 0 0 / 0.45)" },
+ ...theme.applyStyles("dark", {
+ "&:hover": { borderColor: "rgba(255 255 255 / 0.45)" },
+ }),
+}));
+const createTileIconSx = {
+ flex: 1,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ color: "text.muted",
+};
+
+interface SearchFieldV2Props {
+ value: string;
+ onChange: (value: string) => void;
+}
+
+const SearchFieldV2: React.FC<SearchFieldV2Props> = ({ value, onChange }) => (
+ <Stack direction="row" sx={searchFieldSx}>
+ <SearchIcon sx={searchIconSx} />
+ <InputBase
+ fullWidth
+ autoFocus
+ placeholder={t("albums_search_hint")}
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ sx={{
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ color: "text.base",
+ "& input::placeholder": { color: "text.muted", opacity: 1 },
+ }}
+ endAdornment={
+ value ? (
+ <CloseIcon
+ fontSize="small"
+ onClick={() => onChange("")}
+ sx={{
+ color: "stroke.muted",
+ cursor: "pointer",
+ "&:hover": { color: "text.base" },
+ }}
+ />
+ ) : undefined
+ }
+ />
+ </Stack>
+);
+
+const searchFieldSx = (theme: Theme) => ({
+ alignItems: "center",
+ gap: "10px",
+ height: 44,
+ borderRadius: "16px",
+ backgroundColor: "background.paper",
+ px: "14px",
+ ...theme.applyStyles("dark", { backgroundColor: "#282828" }),
+});
+const searchIconSx = (theme: Theme) => ({
+ fontSize: 20,
+ flexShrink: 0,
+ color: "rgba(0 0 0 / 0.4)",
+ ...theme.applyStyles("dark", { color: "rgba(255 255 255 / 0.4)" }),
+});
diff --git a/web/packages/new/photos/components/CollectionsSortOptions.tsx b/web/packages/new/photos/components/CollectionsSortOptions.tsx
index 980463e24c..e5b7e34238 100644
--- a/web/packages/new/photos/components/CollectionsSortOptions.tsx
+++ b/web/packages/new/photos/components/CollectionsSortOptions.tsx
@@ -9,6 +9,7 @@ import {
styled,
type IconButtonProps,
type PaperProps,
+ type Theme,
} from "@mui/material";
import Menu, { type MenuProps } from "@mui/material/Menu";
import type { CollectionsSortBy } from "ente-new/photos/services/collection-summary";
@@ -34,6 +35,10 @@ interface CollectionsSortOptionsProps {
* triggers the menu.
*/
transparentTriggerButtonBackground?: boolean;
+ /**
+ * Visual treatment for the surface in which the control is rendered.
+ */
+ variant?: "default" | "v2";
}
/** The three sort categories. */
@@ -66,6 +71,7 @@ export const CollectionsSortOptions: React.FC<CollectionsSortOptionsProps> = ({
onChangeSortBy,
nestedInDialog,
transparentTriggerButtonBackground,
+ variant = "default",
}) => {
const [anchorEl, setAnchorEl] = useState<MenuProps["anchorEl"]>();
// Apply sort changes after the menu closes to avoid flicker.
@@ -89,15 +95,20 @@ export const CollectionsSortOptions: React.FC<CollectionsSortOptionsProps> = ({
setAnchorEl(undefined);
};
- const triggerButtonSxProps: IconButtonProps["sx"] = [
- transparentTriggerButtonBackground
- ? {}
- : { backgroundColor: "fill.faint" },
- ];
+ const isV2 = variant === "v2";
+
+ const triggerButtonSxProps: IconButtonProps["sx"] = isV2
+ ? v2TriggerButtonSx
+ : [
+ transparentTriggerButtonBackground
+ ? {}
+ : { backgroundColor: "fill.faint" },
+ ];
- const menuPaperSxProps: PaperProps["sx"] | undefined = nestedInDialog
- ? { backgroundColor: "background.paper2" }
- : undefined;
+ const menuPaperSxProps: PaperProps["sx"] | undefined =
+ !isV2 && nestedInDialog
+ ? { backgroundColor: "background.paper2" }
+ : undefined;
return (
<>
@@ -106,12 +117,14 @@ export const CollectionsSortOptions: React.FC<CollectionsSortOptionsProps> = ({
aria-controls={anchorEl ? ariaID : undefined}
aria-haspopup="true"
aria-expanded={anchorEl ? "true" : undefined}
+ aria-label={t("sort_by")}
sx={triggerButtonSxProps}
>
- <SortIcon />
+ <SortIcon sx={isV2 ? { fontSize: 20 } : undefined} />
</IconButton>
<StyledMenu
id={ariaID}
+ sx={isV2 ? v2MenuSx : undefined}
{...(anchorEl && { anchorEl })}
open={!!anchorEl}
onClose={() => setAnchorEl(undefined)}
@@ -247,3 +260,43 @@ const StyledMenuItem = styled(MenuItem)(({ theme }) => ({
"& .MuiListItemText-root": { margin: 0 },
"& .MuiListItemText-primary": { color: "inherit", fontSize: "inherit" },
}));
+
+const v2TriggerButtonSx = (theme: Theme) => ({
+ width: 38,
+ height: 38,
+ p: 0,
+ color: "text.base",
+ backgroundColor: "background.paper",
+ "&:hover": { backgroundColor: "fill.faintHover" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+});
+
+const v2MenuSx = (theme: Theme) => ({
+ "& .MuiPaper-root": {
+ width: 238,
+ minWidth: 238,
+ border: "1px solid #ececec",
+ borderRadius: "16px",
+ backgroundColor: "background.paper",
+ boxShadow: "0 4px 4px rgba(0 0 0 / 0.16)",
+ ...theme.applyStyles("dark", {
+ borderColor: "rgba(255 255 255 / 0.12)",
+ backgroundColor: "#282828",
+ boxShadow: "0 4px 4px rgba(0 0 0 / 0.40)",
+ }),
+ },
+ "& .MuiMenuItem-root": {
+ minHeight: 44,
+ height: 44,
+ boxSizing: "border-box",
+ py: "12px",
+ px: "16px",
+ },
+ "& .MuiTypography-root": {
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ },
+});
diff --git a/web/packages/new/photos/components/useCollectionSelector.ts b/web/packages/new/photos/components/useCollectionSelector.ts
new file mode 100644
index 0000000000..3aa709fbed
--- /dev/null
+++ b/web/packages/new/photos/components/useCollectionSelector.ts
@@ -0,0 +1,180 @@
+import {
+ canAddToCollection,
+ canMoveToCollection,
+ collectionsSortBy,
+ sortCollectionSummaries,
+ type CollectionsSortBy,
+ type CollectionSummary,
+} from "ente-new/photos/services/collection-summary";
+import { includes } from "ente-utils/type-guards";
+import { t } from "i18next";
+import { useCallback, useEffect, useMemo, useState } from "react";
+import type {
+ CollectionSelectorAction,
+ CollectionSelectorProps,
+} from "./CollectionSelector";
+
+type UseCollectionSelectorProps = CollectionSelectorProps & {
+ createCollectionLabel: string;
+};
+
+export const useCollectionSelector = ({
+ open,
+ onClose,
+ onExited,
+ attributes,
+ collectionSummaries,
+ collectionForCollectionSummaryID,
+ createCollectionLabel,
+}: UseCollectionSelectorProps) => {
+ const [searchTerm, setSearchTerm] = useState("");
+ const [sortBy, setSortBy] =
+ useCollectionSelectorSortByLocalState("name-asc");
+ const [filteredCollections, setFilteredCollections] = useState<
+ CollectionSummary[]
+ >([]);
+
+ const handleExited = useCallback(() => {
+ setSearchTerm("");
+ onExited?.();
+ }, [onExited]);
+
+ useEffect(() => {
+ if (!attributes || !open) return;
+
+ const activeCollectionID = attributes.activeCollectionID;
+ const selectableCollections = [...collectionSummaries.values()].filter(
+ (collectionSummary) => {
+ if (
+ collectionSummary.id ===
+ attributes.sourceCollectionSummaryID
+ ) {
+ return false;
+ }
+
+ const isUserFavorites =
+ collectionSummary.type === "userFavorites";
+ if (
+ attributes.action === "add" ||
+ attributes.action === "move"
+ ) {
+ return (
+ canAddToCollection(collectionSummary) &&
+ !isUserFavorites
+ );
+ }
+ if (attributes.action === "upload") {
+ return (
+ (canAddToCollection(collectionSummary) ||
+ collectionSummary.type === "uncategorized") &&
+ !isUserFavorites
+ );
+ }
+ if (attributes.action === "restore") {
+ return (
+ (canMoveToCollection(collectionSummary) ||
+ collectionSummary.type === "uncategorized") &&
+ !isUserFavorites
+ );
+ }
+ return (
+ canMoveToCollection(collectionSummary) && !isUserFavorites
+ );
+ },
+ );
+
+ const collections = sortCollectionSummaries(
+ selectableCollections,
+ sortBy,
+ )
+ .sort((a, b) => b.sortPriority - a.sortPriority)
+ .sort((a, b) => {
+ if (a.id === activeCollectionID) return -1;
+ if (b.id === activeCollectionID) return 1;
+ return 0;
+ });
+
+ if (collections.length === 0) {
+ onClose();
+ attributes.onCreateCollection();
+ handleExited();
+ }
+
+ setFilteredCollections(collections);
+ }, [collectionSummaries, attributes, open, onClose, sortBy, handleExited]);
+
+ const searchFilteredCollections = useMemo(() => {
+ if (!searchTerm.trim()) return filteredCollections;
+ const searchLower = searchTerm.toLowerCase();
+ return filteredCollections.filter((collectionSummary) =>
+ collectionSummary.name.toLowerCase().includes(searchLower),
+ );
+ }, [filteredCollections, searchTerm]);
+
+ const showCreateButton =
+ !searchTerm.trim() ||
+ createCollectionLabel.toLowerCase().includes(searchTerm.toLowerCase());
+
+ const handleCollectionSummaryClick = async (id: number) => {
+ if (!attributes) return;
+ attributes.onSelectCollection(
+ await collectionForCollectionSummaryID(id),
+ );
+ onClose();
+ };
+
+ const handleClose = () => {
+ attributes?.onCancel?.();
+ onClose();
+ };
+
+ return {
+ attributes,
+ searchTerm,
+ setSearchTerm,
+ sortBy,
+ setSortBy,
+ filteredCollections,
+ searchFilteredCollections,
+ showCreateButton,
+ handleExited,
+ handleCollectionSummaryClick,
+ handleClose,
+ };
+};
+
+export const collectionSelectorTitle = (action: CollectionSelectorAction) => {
+ switch (action) {
+ case "upload":
+ return t("upload_to_album");
+ case "add":
+ return t("add_to_album");
+ case "move":
+ return t("move_to_album");
+ case "restore":
+ return t("restore_to_album");
+ case "unhide":
+ return t("unhide_to_album");
+ }
+};
+
+const useCollectionSelectorSortByLocalState = (
+ initialValue: CollectionsSortBy,
+) => {
+ const key = "collectionSelectorSortBy";
+ const [value, setValue] = useState(initialValue);
+
+ useEffect(() => {
+ const storedValue = localStorage.getItem(key);
+ if (storedValue && includes(collectionsSortBy, storedValue)) {
+ setValue(storedValue);
+ }
+ }, []);
+
+ const setter = (newValue: CollectionsSortBy) => {
+ localStorage.setItem(key, newValue);
+ setValue(newValue);
+ };
+
+ return [value, setter] as const;
+};