π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Remove All Albums dialog
AswinAsok70b8531db261
diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsxdeleted file mode 100644index 876257fdfe..0000000000--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx+++ /dev/null@@ -1,600 +0,0 @@-// TODO: Audit this file.-import {- CreateAlbumTile,- CollectionDialogSearchField as SearchField,- CollectionTileButton as TileButton,- CollectionTileTextOverlay as TileTextOverlay,-} from "@/components/CollectionDialog/Primitives";-import {- collectionDialogBodyMutedSx as bodyMutedSx,- collectionDialogFullScreenQuery,- collectionDialogDividerSx as dividerSx,- collectionDialogHeaderActionsSx as headerActionsSx,- collectionDialogHeaderRowSx as headerRowSx,- collectionDialogHeaderSx as headerSx,- collectionDialogIconButtonSx as iconButtonSx,- collectionDialogNoResultsSx as noResultsSx,- collectionDialogPaperSx as paperSx,- collectionDialogSurfaceStroke as surfaceStroke,- collectionDialogSurfaceStrokeDark as surfaceStrokeDark,- collectionDialogTitleSx as titleSx,-} from "@/components/CollectionDialog/styles";-import { useDeleteEmptyAlbums } from "@/components/Collections/useDeleteEmptyAlbums";-import { CollectionsSortOptions } from "@/components/CollectionsSortOptions";-import type { RemotePullOpts } from "@/components/gallery";-import {- albumFilters,- visibleAlbumFilters as getVisibleAlbumFilters,- matchesAlbumFilter,- type AlbumFilter,-} from "@/utils/album-filters";-import { Delete02Icon, StarIcon } from "@hugeicons/core-free-icons";-import { HugeiconsIcon } from "@hugeicons/react";-import ArchiveIcon from "@mui/icons-material/Archive";-import CloseIcon from "@mui/icons-material/Close";-import PushPinIcon from "@mui/icons-material/PushPin";-import {- Box,- Button,- Dialog,- IconButton,- Stack,- ToggleButton,- ToggleButtonGroup,- Tooltip,- Typography,- useMediaQuery,- type SxProps,- type Theme,-} from "@mui/material";-import { SlideUpTransition } from "ente-new/photos/components/mui/SlideUpTransition";-import { ItemCard } from "ente-new/photos/components/Tiles";-import type {- CollectionsSortBy,- CollectionSummary,-} from "ente-new/photos/services/collection-summary";-import { t } from "i18next";-import memoize from "memoize-one";-import React, { useEffect, useMemo, useRef, useState } from "react";-import AutoSizer from "react-virtualized-auto-sizer";-import {- areEqual,- FixedSizeList,- type ListChildComponentProps,-} from "react-window";--interface AllAlbums {- open: boolean;- onClose: () => void;- collectionSummaries: CollectionSummary[];- onSelectCollectionID: (id: number) => void;- collectionsSortBy: CollectionsSortBy;- onChangeCollectionsSortBy: (by: CollectionsSortBy) => void;- isInHiddenSection: boolean;- isInArchiveSection: boolean;- canCreateAlbum: boolean;- onCreateAlbum: () => void;- onRemotePull: (opts?: RemotePullOpts) => Promise<void>;-}--export const AllAlbums: React.FC<AllAlbums> = ({- collectionSummaries,- open,- onClose,- onSelectCollectionID,- collectionsSortBy,- onChangeCollectionsSortBy,- isInHiddenSection,- isInArchiveSection,- canCreateAlbum,- onCreateAlbum,- onRemotePull,-}) => {- const fullScreen = useMediaQuery(collectionDialogFullScreenQuery);- const [searchTerm, setSearchTerm] = useState("");- const [albumFilter, setAlbumFilter] = useState<AlbumFilter>("ente");- const showAlbumFilters = !isInHiddenSection && !isInArchiveSection;- const handleExited = () => {- setSearchTerm("");- setAlbumFilter("ente");- };-- const onCollectionClick = (collectionID: number) => {- onSelectCollectionID(collectionID);- onClose();- };-- const { handleDeleteEmptyAlbums, hasEnoughEmptyAlbums } =- useDeleteEmptyAlbums(collectionSummaries, onRemotePull);-- const showDeleteEmptyAlbums =- showAlbumFilters &&- hasEnoughEmptyAlbums &&- albumFilter == "empty-albums" &&- !searchTerm.trim();-- const visibleAlbumFilters = useMemo(- () => getVisibleAlbumFilters(collectionSummaries),- [collectionSummaries],- );-- const activeFilterTitle = (- albumFilters.find(({ value }) => value == albumFilter) ??- albumFilters[0]!- ).title();-- useEffect(() => {- if (!visibleAlbumFilters.some(({ value }) => value == albumFilter)) {- setAlbumFilter("ente");- }- }, [albumFilter, visibleAlbumFilters]);-- const filteredCollectionSummaries = useMemo(() => {- const albumFilteredCollectionSummaries = !showAlbumFilters- ? collectionSummaries- : collectionSummaries.filter((cs) =>- matchesAlbumFilter(cs, albumFilter),- );-- if (!searchTerm.trim()) {- return albumFilteredCollectionSummaries;- }- const searchLower = searchTerm.toLowerCase();- return albumFilteredCollectionSummaries.filter((cs) =>- cs.name.toLowerCase().includes(searchLower),- );- }, [albumFilter, collectionSummaries, showAlbumFilters, searchTerm]);-- const showCreateButton = useMemo(() => {- if (!canCreateAlbum) return false;- if (showAlbumFilters && albumFilter != "ente") return false;- if (!searchTerm.trim()) {- return true;- }- const searchLower = searchTerm.toLowerCase();- const createText = t("new_album").toLowerCase();- return createText.includes(searchLower);- }, [albumFilter, canCreateAlbum, showAlbumFilters, searchTerm]);-- return (- <>- <Dialog- {...{ open, onClose }}- fullScreen={fullScreen}- maxWidth={false}- sx={dialogSx}- slots={{ transition: SlideUpTransition }}- slotProps={{- paper: { sx: paperSx },- transition: { onExited: handleExited },- }}- >- <Stack sx={headerSx}>- <Stack direction="row" sx={headerRowSx}>- <Stack sx={{ minWidth: 0, gap: "2px" }}>- <Typography sx={titleSx}>- {isInHiddenSection- ? t("all_hidden_albums")- : isInArchiveSection- ? t("section_archive")- : activeFilterTitle}- </Typography>- <Typography sx={bodyMutedSx}>- {t("albums_count", {- count: filteredCollectionSummaries.length,- })}- </Typography>- </Stack>- <Stack direction="row" sx={headerActionsSx}>- <CollectionsSortOptions- activeSortBy={collectionsSortBy}- onChangeSortBy={onChangeCollectionsSortBy}- nestedInDialog- variant="v2"- />- <IconButton- aria-label={t("close")}- onClick={onClose}- sx={iconButtonSx}- >- <CloseIcon sx={{ fontSize: 18 }} />- </IconButton>- </Stack>- </Stack>- {showAlbumFilters && visibleAlbumFilters.length > 1 && (- <ToggleButtonGroup- exclusive- value={albumFilter}- aria-label={t("filter_albums")}- onChange={(_, nextValue: AlbumFilter | null) => {- if (nextValue) setAlbumFilter(nextValue);- }}- sx={filterPillsSx}- >- {visibleAlbumFilters.map((filter) => (- <ToggleButton- key={filter.value}- value={filter.value}- >- {filter.label()}- </ToggleButton>- ))}- </ToggleButtonGroup>- )}- <SearchField value={searchTerm} onChange={setSearchTerm} />- </Stack>- <Box sx={dividerSx} />- <AllAlbumsContent- collectionSummaries={filteredCollectionSummaries}- onCollectionClick={onCollectionClick}- hasSearchQuery={!!searchTerm.trim()}- showCreateButton={showCreateButton}- onCreateAlbum={onCreateAlbum}- reserveFooterSpace={showDeleteEmptyAlbums}- />- {showDeleteEmptyAlbums && (- <Box sx={sweepFooterSx}>- <Button- startIcon={- <HugeiconsIcon- icon={Delete02Icon}- size={22}- strokeWidth={1.5}- />- }- onClick={handleDeleteEmptyAlbums}- sx={sweepButtonSx}- >- {t("delete_empty_albums")}- </Button>- </Box>- )}- </Dialog>- </>- );-};--const sweepInset = 12;-const sweepButtonRadius = 20;-const dialogSx: SxProps<Theme> = {- "& .MuiDialog-container": { justifyContent: "flex-end" },- "& .MuiDialog-paper": {- borderRadius: `${sweepButtonRadius + sweepInset}px`,- [`@media ${collectionDialogFullScreenQuery}`]: { borderRadius: 0 },- },-};-const sweepFooterSx = {- position: "absolute",- insetInline: 0,- bottom: `${sweepInset}px`,- px: `${sweepInset}px`,- display: "flex",- pointerEvents: "none",-};-const sweepButtonSx: SxProps<Theme> = (theme) => ({- pointerEvents: "auto",- flex: 1,- height: 52,- borderRadius: `${sweepButtonRadius}px`,- border: `1px solid ${surfaceStroke}`,- backgroundColor: "fixed.white",- color: "fixed.black",- fontSize: 14,- lineHeight: "20px",- fontWeight: 500,- letterSpacing: "inherit",- boxShadow: "0 2px 8px rgba(0 0 0 / 0.08)",- "&:hover": { backgroundColor: "#eaeaea" },- ...theme.applyStyles("dark", { borderColor: surfaceStrokeDark }),-});--const filterPillsSx = (theme: Theme) => ({- display: "flex",- gap: "8px",- "& .MuiToggleButtonGroup-grouped": {- flex: "1 1 0",- minWidth: 0,- marginLeft: "0 !important",- padding: "10px 12px",- border: 0,- borderRadius: "16px !important",- color: "text.muted",- backgroundColor: "background.paper",- fontSize: "14px",- lineHeight: "20px",- fontWeight: 500,- letterSpacing: "-0.011em",- textTransform: "none",- whiteSpace: "nowrap",- overflow: "hidden",- textOverflow: "ellipsis",- transition: theme.transitions.create("background-color", {- duration: 120,- }),- "&:hover": { backgroundColor: "fill.faintHover", color: "text.base" },- "&:focus-visible": {- outline: `1px solid ${theme.vars.palette.stroke.base}`,- outlineOffset: 2,- },- ...theme.applyStyles("dark", {- "&:not(.Mui-selected)": {- backgroundColor: "rgba(255 255 255 / 0.12)",- },- }),- "&.Mui-selected": {- backgroundColor: "accent.main",- color: "accent.contrastText",- },- "&.Mui-selected:hover": { backgroundColor: "accent.dark" },- },-});-const GridColumns = 3;-const GridGap = 8;-const GridPaddingInline = 20;-const GridPaddingBlockStart = 16;-const GridPaddingBlockEnd = 20;-const GridFooterHeight = 88;--interface ItemData {- collectionRowList: (CollectionSummary | "create")[][];- onCollectionClick: (id: number) => void;- onCreateAlbum: () => void;- tileSize: number;-}--const createItemData = memoize(- (- collectionRowList: (CollectionSummary | "create")[][],- onCollectionClick: (id: number) => void,- onCreateAlbum: () => void,- tileSize: number,- ) => ({ collectionRowList, onCollectionClick, onCreateAlbum, tileSize }),-);--const AlbumsRow = React.memo(- ({- data,- index,- style,- isScrolling,- }: ListChildComponentProps<ItemData>) => {- const {- collectionRowList,- onCollectionClick,- onCreateAlbum,- tileSize,- } = data;- const collectionRow = collectionRowList[index]!;- return (- <div style={style}>- <Stack- direction="row"- sx={{- "--tile-size": `${tileSize}px`,- px: `${GridPaddingInline}px`,- gap: `${GridGap}px`,- height: tileSize,- }}- >- {collectionRow.map((item) =>- item === "create" ? (- <CreateAlbumTile- key="create"- onClick={onCreateAlbum}- />- ) : (- <AlbumCard- key={item.id}- isScrolling={isScrolling}- onCollectionClick={onCollectionClick}- collectionSummary={item}- />- ),- )}- </Stack>- </div>- );- },- areEqual,-);--interface AllAlbumsContentProps {- collectionSummaries: CollectionSummary[];- onCollectionClick: (id: number) => void;- hasSearchQuery: boolean;- showCreateButton: boolean;- onCreateAlbum: () => void;- reserveFooterSpace: boolean;-}--const AllAlbumsContent: React.FC<AllAlbumsContentProps> = ({- collectionSummaries,- onCollectionClick,- hasSearchQuery,- showCreateButton,- onCreateAlbum,- reserveFooterSpace,-}) => {- const refreshInProgress = useRef(false);- const shouldRefresh = useRef(false);-- const [collectionRowList, setCollectionRowList] = useState<- (CollectionSummary | "create")[][]- >([]);-- useEffect(() => {- const main = () => {- if (refreshInProgress.current) {- shouldRefresh.current = true;- return;- }- refreshInProgress.current = true;-- const collectionRowList: (CollectionSummary | "create")[][] = [];- let index = 0;-- if (showCreateButton) {- const firstRow: (CollectionSummary | "create")[] = ["create"];- for (- let i = 1;- i < GridColumns && index < collectionSummaries.length;- i++- ) {- firstRow.push(collectionSummaries[index++]!);- }- collectionRowList.push(firstRow);- }-- while (index < collectionSummaries.length) {- const collectionRow: (CollectionSummary | "create")[] = [];- for (- let i = 0;- i < GridColumns && index < collectionSummaries.length;- i++- ) {- collectionRow.push(collectionSummaries[index++]!);- }- collectionRowList.push(collectionRow);- }- setCollectionRowList(collectionRowList);- refreshInProgress.current = false;- if (shouldRefresh.current) {- shouldRefresh.current = false;- setTimeout(main, 0);- }- };- main();- }, [collectionSummaries, showCreateButton]);-- if (- hasSearchQuery &&- collectionSummaries.length === 0 &&- !showCreateButton- ) {- return (- <Box sx={noResultsSx}>- <Typography sx={bodyMutedSx}>{t("no_results")}</Typography>- </Box>- );- }-- return (- <Box- sx={{- flex: 1,- minHeight: 0,- pt: `${GridPaddingBlockStart}px`,- pb: `${reserveFooterSpace ? GridFooterHeight : GridPaddingBlockEnd}px`,- }}- >- <AutoSizer>- {({ width, height }) => {- const tileSize = Math.max(- 0,- Math.floor(- (width -- 2 * GridPaddingInline -- (GridColumns - 1) * GridGap) /- GridColumns,- ),- );- return (- <FixedSizeList- {...{ width, height }}- itemCount={collectionRowList.length}- itemSize={tileSize + GridGap}- itemData={createItemData(- collectionRowList,- onCollectionClick,- onCreateAlbum,- tileSize,- )}- >- {AlbumsRow}- </FixedSizeList>- );- }}- </AutoSizer>- </Box>- );-};--interface AlbumCardProps {- collectionSummary: CollectionSummary;- onCollectionClick: (collectionID: number) => void;- isScrolling?: boolean;-}--const AlbumCard: React.FC<AlbumCardProps> = ({- onCollectionClick,- collectionSummary,- isScrolling,-}) => {- const isFavorite = collectionSummary.type === "userFavorites";- const isPinned = collectionSummary.attributes.has("pinned");- const isArchived = collectionSummary.attributes.has("archived");-- return (- <ItemCard- TileComponent={TileButton}- coverFile={collectionSummary.coverFile}- onClick={() => onCollectionClick(collectionSummary.id)}- isScrolling={isScrolling}- >- <TileTextOverlay>- <Tooltip title={collectionSummary.name} arrow>- <Typography sx={albumNameSx}>- {collectionSummary.name}- </Typography>- </Tooltip>- <Typography sx={albumCountSx}>- {t("photos_count", { count: collectionSummary.fileCount })}- </Typography>- </TileTextOverlay>- {(isFavorite || isPinned || isArchived) && (- <Box- sx={{- position: "absolute",- bottom: 8,- right: 8,- display: "flex",- gap: 0.5,- }}- >- {isFavorite && (- <HugeiconsIcon- icon={StarIcon}- size={20}- color="white"- fill="currentColor"- aria-hidden- />- )}- {isPinned && (- <PushPinIcon sx={{ fontSize: 20, color: "white" }} />- )}- {isArchived && (- <ArchiveIcon sx={{ fontSize: 20, color: "white" }} />- )}- </Box>- )}- </ItemCard>- );-};--const albumNameSx = {- fontSize: 14,- lineHeight: "20px",- fontWeight: 500,- overflow: "hidden",- textOverflow: "ellipsis",- display: "-webkit-box",- WebkitLineClamp: 3,- WebkitBoxOrient: "vertical",-};-const albumCountSx = {- fontSize: 12,- lineHeight: "16px",- fontWeight: 500,- opacity: 0.7,-};diff --git a/web/apps/photos/src/components/Collections/CreateAlbumDialog.tsx b/web/apps/photos/src/components/Collections/CreateAlbumDialog.tsxindex ed6eafdb11..0cdaeff5e2 100644--- a/web/apps/photos/src/components/Collections/CreateAlbumDialog.tsx+++ b/web/apps/photos/src/components/Collections/CreateAlbumDialog.tsx@@ -23,7 +23,6 @@ import React, { useState } from "react";interface CreateAlbumDialogProps extends ModalVisibilityProps {isHidden: boolean;- onSubmit: () => void;onRemotePull: (opts?: RemotePullOpts) => Promise<void>;onSelectCollectionID: (id: number) => void;}@@ -33,7 +32,6 @@ export const CreateAlbumDialog: React.FC<CreateAlbumDialogProps> = ({open,onClose,isHidden,- onSubmit,onRemotePull,onSelectCollectionID,}) => {@@ -45,8 +43,6 @@ export const CreateAlbumDialog: React.FC<CreateAlbumDialogProps> = ({}>({ open: false });const handleCreateAlbum = (albumName: string) => {- onSubmit();-void (async () => {try {const newAlbum = isHiddendiff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsxindex d1e9121fd3..6c5676b2c2 100644--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx@@ -1,5 +1,4 @@// TODO: Audit this file-import { AllAlbums } from "@/components/Collections/AllAlbums";import { AllPeople } from "@/components/Collections/AllPeople";import {CollectionShare,@@ -54,7 +53,6 @@ export type GalleryBarAndListHeaderProps = Omit<| "collectionsSortBy"| "onChangeCollectionsSortBy"| "onCreateAlbum"- | "onShowAllAlbums"| "onShowAllPeople"> & {onAlbumSummariesChange: (@@ -69,7 +67,6 @@ export type GalleryBarAndListHeaderProps = Omit<setFileListHeader: (header: FileListHeaderOrFooter) => void;hasActiveFileSelection: boolean;saveGroups: SaveGroup[];- canCreateAlbum: boolean;} & Pick<CollectionHeaderProps,| "onRemotePull"@@ -109,7 +106,6 @@ export const GalleryBarAndListHeader: React.FC<onSelectPerson,allPeople,saveGroups,- canCreateAlbum,hasActiveFileSelection,activePerson,emailByUserID,@@ -123,8 +119,6 @@ export const GalleryBarAndListHeader: React.FC<collapsed,mobileDrawerProps,}) => {- const { show: showAllAlbums, props: allAlbumsVisibilityProps } =- useModalVisibility();const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } =useModalVisibility();const [createInHiddenSection, setCreateInHiddenSection] = useState(false);@@ -354,30 +348,14 @@ export const GalleryBarAndListHeader: React.FC<onChangeCollectionsSortBy={setCollectionsSortBy}onChangePeopleSortBy={onChangePeopleSortBy}onCreateAlbum={openAlbumCreation}- onShowAllAlbums={showAllAlbums}onShowAllPeople={showAllPeople}collectionSummaries={visibleCollectionSummaries}visibleAlbumFilters={visibleAlbumFilters}/>- <AllAlbums- {...allAlbumsVisibilityProps}- collectionSummaries={sortedCollectionSummaries.filter(- (cs) => !cs.attributes.has("system"),- )}- onSelectCollectionID={selectCollection}- onChangeCollectionsSortBy={setCollectionsSortBy}- collectionsSortBy={collectionsSortBy}- isInHiddenSection={mode == "hidden-albums"}- isInArchiveSection={mode == "archive-albums"}- canCreateAlbum={canCreateAlbum}- onCreateAlbum={openAlbumCreation}- onRemotePull={onRemotePull}- /><CreateAlbumDialog{...albumNameInputVisibilityProps}isHidden={createInHiddenSection}- onSubmit={allAlbumsVisibilityProps.onClose}onRemotePull={onRemotePull}onSelectCollectionID={selectCollection}/>diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsxindex 5440082eeb..5602033851 100644--- a/web/apps/photos/src/components/gallery/BarImpl.tsx+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx@@ -82,7 +82,6 @@ export interface GalleryBarImplProps extends GalleryBarPresentationProps {) => Promise<boolean>;activeCollectionID: number | undefined;onSelectCollectionID: (collectionID: number) => void;- onShowAllAlbums: () => void;onCreateAlbum: () => void;onShowAllPeople: () => void;collectionsSortBy: CollectionsSortBy;@@ -107,7 +106,6 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({onShowCollectionSummary,activeCollectionID,onSelectCollectionID,- onShowAllAlbums,onCreateAlbum,onShowAllPeople,collectionsSortBy,@@ -376,23 +374,20 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({onChangeSortBy={onChangePeopleSortBy}/>)}- <Tooltip- title={mode == "people" ? t("people") : t("all_albums")}- >- <IconButton- aria-label={- mode == "people" ? t("people") : t("all_albums")- }- aria-haspopup="dialog"- onClick={() => {- mobileDrawerProps.onClose();- if (mode == "people") onShowAllPeople();- else onShowAllAlbums();- }}- >- <ExpandMoreIcon sx={{ fontSize: 20 }} />- </IconButton>- </Tooltip>+ {mode == "people" && (+ <Tooltip title={t("people")}>+ <IconButton+ aria-label={t("people")}+ aria-haspopup="dialog"+ onClick={() => {+ mobileDrawerProps.onClose();+ onShowAllPeople();+ }}+ >+ <ExpandMoreIcon sx={{ fontSize: 20 }} />+ </IconButton>+ </Tooltip>+ )}{(mode == "albums" || mode == "hidden-albums") && (<Tooltip title={t("new_album")}><IconButtondiff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 17cb0dba72..cf3d720be1 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -562,8 +562,6 @@ const Page: React.FC = () => {filteredFiles.length > 0 &&selectedFilesInView.length === filteredFiles.length;- const isInArchiveSection = barMode == "archive-albums";-const barCollectionSummaries =barMode == "hidden-albums"? state.hiddenCollectionSummaries@@ -2120,7 +2118,6 @@ const Page: React.FC = () => {onChangePeopleSortBy: setPeopleSortBy,setFileListHeader,saveGroups,- canCreateAlbum: !isInArchiveSection,onAddSaveGroup,onEditAlbumDetails: showEditAlbumDetails,onShowMap: handleShowCollectionMap,