Skip to content

armgit / ente

Public Imported from GitHub
0

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

[photos][web] Add album creation button to sidebar

AswinAsok272e08be550e
diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsx
index bfa4968619..fde9996855 100644
--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx
+++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx
@@ -30,17 +30,13 @@ import {
import { Delete02Icon, StarIcon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import ArchiveIcon from "@mui/icons-material/Archive";
-import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
import CloseIcon from "@mui/icons-material/Close";
import PushPinIcon from "@mui/icons-material/PushPin";
import {
Box,
Button,
Dialog,
- DialogTitle,
IconButton,
- Paper,
- Snackbar,
Stack,
ToggleButton,
ToggleButtonGroup,
@@ -51,15 +47,10 @@ import {
type Theme,
} from "@mui/material";
import { ensureLocalUser } from "ente-accounts/services/user";
-import { FilledIconButton } from "ente-base/components/mui";
-import { SingleInputDialog } from "ente-base/components/SingleInputDialog";
-import { useModalVisibility } from "ente-base/components/utils/modal";
import { useBaseContext } from "ente-base/context";
import { SlideUpTransition } from "ente-new/photos/components/mui/SlideUpTransition";
import { ItemCard } from "ente-new/photos/components/Tiles";
import {
- createAlbum,
- createHiddenAlbum,
deleteCollection,
isArchivedCollection,
isDefaultHiddenCollection,
@@ -94,6 +85,7 @@ interface AllAlbums {
isInHiddenSection: boolean;
isInArchiveSection: boolean;
canCreateAlbum: boolean;
+ onCreateAlbum: () => void;
onRemotePull: (opts?: RemotePullOpts) => Promise<void>;
}
@@ -107,6 +99,7 @@ export const AllAlbums: React.FC<AllAlbums> = ({
isInHiddenSection,
isInArchiveSection,
canCreateAlbum,
+ onCreateAlbum,
onRemotePull,
}) => {
const fullScreen = useMediaQuery(collectionDialogFullScreenQuery);
@@ -115,14 +108,6 @@ export const AllAlbums: React.FC<AllAlbums> = ({
const showAlbumFilters = !isInHiddenSection && !isInArchiveSection;
const { showMiniDialog } = useBaseContext();
const { showNotification } = usePhotosAppContext();
- const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } =
- useModalVisibility();
- const [albumCreatedToast, setAlbumCreatedToast] = useState<{
- open: boolean;
- albumId?: number;
- albumName?: string;
- }>({ open: false });
-
const handleExited = () => {
setSearchTerm("");
setAlbumFilter("ente");
@@ -133,30 +118,6 @@ export const AllAlbums: React.FC<AllAlbums> = ({
onClose();
};
- const handleCreateAlbum = (albumName: string) => {
- onClose();
-
- void (async () => {
- try {
- const newAlbum = isInHiddenSection
- ? await createHiddenAlbum(albumName)
- : await createAlbum(albumName);
- await onRemotePull();
-
- setAlbumCreatedToast({
- open: true,
- albumId: newAlbum.id,
- albumName: albumName,
- });
- } catch {
- showNotification({
- color: "critical",
- title: t("generic_error_retry"),
- });
- }
- })();
- };
-
const emptyAlbumCandidates = useMemo(
() => collectionSummaries.filter(isBulkDeletableEmptyAlbum),
[collectionSummaries],
@@ -370,7 +331,7 @@ export const AllAlbums: React.FC<AllAlbums> = ({
onCollectionClick={onCollectionClick}
hasSearchQuery={!!searchTerm.trim()}
showCreateButton={showCreateButton}
- onCreateAlbum={showAlbumNameInput}
+ onCreateAlbum={onCreateAlbum}
reserveFooterSpace={showDeleteEmptyAlbums}
/>
{showDeleteEmptyAlbums && (
@@ -391,74 +352,6 @@ export const AllAlbums: React.FC<AllAlbums> = ({
</Box>
)}
</Dialog>
- <SingleInputDialog
- {...albumNameInputVisibilityProps}
- variant="v2"
- 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>
</>
);
};
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index 704ccefbe9..ef2db97992 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -1,4 +1,5 @@
// TODO: Audit this file
+import { collectionDialogBodyMutedSx as bodyMutedSx } from "@/components/CollectionDialog/styles";
import { AllAlbums } from "@/components/Collections/AllAlbums";
import { AllPeople } from "@/components/Collections/AllPeople";
import {
@@ -17,6 +18,18 @@ import {
visibleAlbumFilters as getVisibleAlbumFilters,
} from "@/utils/album-filters";
import { sortPeople } from "@/utils/people-sort";
+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 { useModalVisibility } from "ente-base/components/utils/modal";
import {
isSaveCancelled,
@@ -28,6 +41,10 @@ import {
GalleryItemsHeaderAdapter,
GalleryItemsSummary,
} from "ente-new/photos/components/gallery/ListHeader";
+import {
+ createAlbum,
+ createHiddenAlbum,
+} from "ente-new/photos/services/collection";
import {
collectionsSortBy,
PseudoCollectionID,
@@ -37,8 +54,16 @@ import {
type CollectionSummary,
} from "ente-new/photos/services/collection-summary";
import type { Person } from "ente-new/photos/services/ml/people";
+import { usePhotosAppContext } from "ente-new/photos/types/context";
import { includes } from "ente-utils/type-guards";
-import React, { useCallback, useEffect, useMemo, useState } from "react";
+import { t } from "i18next";
+import React, {
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { AlbumCastDialog } from "./AlbumCastDialog";
import {
CollectionHeader,
@@ -52,6 +77,7 @@ export type GalleryBarAndListHeaderProps = Omit<
| "onSelectCollectionID"
| "collectionsSortBy"
| "onChangeCollectionsSortBy"
+ | "onCreateAlbum"
| "onShowAllAlbums"
| "onShowAllPeople"
> & {
@@ -123,6 +149,45 @@ export const GalleryBarAndListHeader: React.FC<
}) => {
const { show: showAllAlbums, props: allAlbumsVisibilityProps } =
useModalVisibility();
+ const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } =
+ useModalVisibility();
+ const [albumCreatedToast, setAlbumCreatedToast] = useState<{
+ open: boolean;
+ albumId?: number;
+ albumName?: string;
+ }>({ open: false });
+
+ const { showNotification } = usePhotosAppContext();
+ const createInHiddenSection = useRef(false);
+ const openAlbumCreation = () => {
+ createInHiddenSection.current = mode == "hidden-albums";
+ showAlbumNameInput();
+ };
+
+ const handleCreateAlbum = (albumName: string) => {
+ allAlbumsVisibilityProps.onClose();
+
+ void (async () => {
+ try {
+ const newAlbum = createInHiddenSection.current
+ ? await createHiddenAlbum(albumName)
+ : await createAlbum(albumName);
+ await onRemotePull();
+
+ setAlbumCreatedToast({
+ open: true,
+ albumId: newAlbum.id,
+ albumName: albumName,
+ });
+ } catch {
+ showNotification({
+ color: "critical",
+ title: t("generic_error_retry"),
+ });
+ }
+ })();
+ };
+
const { show: showAllPeople, props: allPeopleVisibilityProps } =
useModalVisibility();
const { show: showCollectionShare, props: collectionShareVisibilityProps } =
@@ -339,6 +404,8 @@ export const GalleryBarAndListHeader: React.FC<
onSelectPerson={selectPerson}
onChangeCollectionsSortBy={setCollectionsSortBy}
onChangePeopleSortBy={onChangePeopleSortBy}
+ canCreateAlbum={canCreateAlbum}
+ onCreateAlbum={openAlbumCreation}
onShowAllAlbums={showAllAlbums}
onShowAllPeople={showAllPeople}
collectionSummaries={visibleCollectionSummaries}
@@ -356,8 +423,77 @@ export const GalleryBarAndListHeader: React.FC<
isInHiddenSection={mode == "hidden-albums"}
isInArchiveSection={mode == "archive-albums"}
canCreateAlbum={canCreateAlbum}
+ onCreateAlbum={openAlbumCreation}
onRemotePull={onRemotePull}
/>
+ <SingleInputDialog
+ {...albumNameInputVisibilityProps}
+ variant="v2"
+ 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) {
+ selectCollection(
+ albumCreatedToast.albumId,
+ );
+ }
+ setAlbumCreatedToast((prev) => ({
+ ...prev,
+ open: false,
+ }));
+ }}
+ >
+ <ArrowForwardIcon />
+ </FilledIconButton>
+ <FilledIconButton
+ onClick={() =>
+ setAlbumCreatedToast((prev) => ({
+ ...prev,
+ open: false,
+ }))
+ }
+ >
+ <CloseIcon />
+ </FilledIconButton>
+ </Stack>
+ </Stack>
+ </DialogTitle>
+ </Paper>
+ </Snackbar>
<AllPeople
{...allPeopleVisibilityProps}
people={sortedPeople}
diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsx
index c135ff586c..2248b09104 100644
--- a/web/apps/photos/src/components/gallery/BarImpl.tsx
+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx
@@ -12,6 +12,7 @@ import {
ViewOffSlashIcon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
+import AddIcon from "@mui/icons-material/Add";
import ArchiveIcon from "@mui/icons-material/Archive";
import CloseIcon from "@mui/icons-material/Close";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
@@ -82,6 +83,8 @@ export interface GalleryBarImplProps extends GalleryBarPresentationProps {
activeCollectionID: number | undefined;
onSelectCollectionID: (collectionID: number) => void;
onShowAllAlbums: () => void;
+ canCreateAlbum: boolean;
+ onCreateAlbum: () => void;
onShowAllPeople: () => void;
collectionsSortBy: CollectionsSortBy;
onChangeCollectionsSortBy: (by: CollectionsSortBy) => void;
@@ -106,6 +109,8 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
activeCollectionID,
onSelectCollectionID,
onShowAllAlbums,
+ canCreateAlbum,
+ onCreateAlbum,
onShowAllPeople,
collectionsSortBy,
onChangeCollectionsSortBy,
@@ -391,6 +396,21 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
<ExpandMoreIcon sx={{ fontSize: 20 }} />
</IconButton>
</Tooltip>
+ {canCreateAlbum &&
+ (mode == "albums" || mode == "hidden-albums") && (
+ <Tooltip title={t("new_album")}>
+ <IconButton
+ aria-label={t("new_album")}
+ aria-haspopup="dialog"
+ onClick={() => {
+ mobileDrawerProps.onClose();
+ onCreateAlbum();
+ }}
+ >
+ <AddIcon sx={{ fontSize: 20 }} />
+ </IconButton>
+ </Tooltip>
+ )}
{mobile && (
<IconButton
aria-label={t("close")}