Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(photos):add-grouped-album-sidebar-filters

Aswin Asok41f0d6a32a0c
diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsx
index 0a9d7abad6..3088657569 100644
--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx
+++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx
@@ -21,6 +21,12 @@ import {
} from "@/components/CollectionDialog/styles";
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";
@@ -78,59 +84,6 @@ import {
type ListChildComponentProps,
} from "react-window";
-type AlbumFilter = "all" | "shared" | "received" | "links" | "empty-albums";
-
-const albumFilters: {
- value: AlbumFilter;
- label: () => string;
- title: () => string;
-}[] = [
- { value: "all", label: () => t("all"), title: () => t("all_albums") },
- {
- value: "shared",
- label: () => t("shared_albums_label"),
- title: () => t("shared_albums_title"),
- },
- {
- value: "received",
- label: () => t("received_albums_label"),
- title: () => t("received_albums_title"),
- },
- {
- value: "links",
- label: () => t("links_albums_label"),
- title: () => t("links_albums_title"),
- },
- {
- value: "empty-albums",
- label: () => t("empty_albums"),
- title: () => t("empty_albums_title"),
- },
-];
-
-const matchesAlbumFilter = (
- cs: CollectionSummary,
- albumFilter: AlbumFilter,
-) => {
- switch (albumFilter) {
- case "all":
- return true;
- case "shared":
- return (
- !cs.attributes.has("sharedIncoming") &&
- !cs.attributes.has("quickLink") &&
- (cs.attributes.has("sharedOutgoing") ||
- cs.attributes.has("sharedViaLink"))
- );
- case "received":
- return cs.attributes.has("sharedIncoming");
- case "links":
- return cs.attributes.has("quickLink");
- case "empty-albums":
- return isBulkDeletableEmptyAlbum(cs);
- }
-};
-
interface AllAlbums {
open: boolean;
onClose: () => void;
@@ -214,16 +167,8 @@ export const AllAlbums: React.FC<AllAlbums> = ({
!searchTerm.trim();
const visibleAlbumFilters = useMemo(
- () =>
- albumFilters.filter(({ value }) => {
- if (value == "all") return true;
- if (value == "empty-albums") return hasEnoughEmptyAlbums;
-
- return collectionSummaries.some((cs) =>
- matchesAlbumFilter(cs, value),
- );
- }),
- [collectionSummaries, hasEnoughEmptyAlbums],
+ () => getVisibleAlbumFilters(collectionSummaries),
+ [collectionSummaries],
);
const activeFilterTitle = (
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index 16a9fd4da9..beea906b0b 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -282,11 +282,11 @@ export const GalleryBarAndListHeader: React.FC<
onChangePeopleSortBy={setPeopleSortBy}
onShowAllAlbums={showAllAlbums}
onShowAllPeople={showAllPeople}
- collectionSummaries={sortedCollectionSummaries.filter(
- (cs) =>
- !cs.attributes.has("hideFromCollectionBar") &&
- !cs.attributes.has("quickLink") &&
- (mode != "albums" || !cs.attributes.has("archived")),
+ collectionSummaries={sortedCollectionSummaries.filter((cs) =>
+ mode == "albums"
+ ? !cs.attributes.has("system")
+ : !cs.attributes.has("hideFromCollectionBar") &&
+ !cs.attributes.has("quickLink"),
)}
/>
diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsx
index 16f5fbf75d..bb4cd589f4 100644
--- a/web/apps/photos/src/components/gallery/BarImpl.tsx
+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx
@@ -1,5 +1,10 @@
import { CollectionsSortOptions } from "@/components/CollectionsSortOptions";
import { PeopleSortOptions } from "@/components/PeopleSortOptions";
+import {
+ visibleAlbumFilters as getVisibleAlbumFilters,
+ matchesAlbumFilter,
+ type AlbumFilter,
+} from "@/utils/album-filters";
import type { PeopleSortBy } from "@/utils/people-sort";
import { Link05Icon, PinIcon, StarIcon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
@@ -86,6 +91,46 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
const titleID = useId();
const listRef = useRef<FixedSizeList | null>(null);
const [viewportHeight, setViewportHeight] = useState(0);
+ const [albumFilter, setAlbumFilter] = useState<AlbumFilter | undefined>(
+ "ente",
+ );
+ const visibleAlbumFilters = useMemo(
+ () =>
+ getVisibleAlbumFilters(
+ collectionSummaries.filter(
+ (cs) => !cs.attributes.has("system"),
+ ),
+ ).map((filter) =>
+ filter.value == "all"
+ ? {
+ value: "ente" as const,
+ label: () => "Ente",
+ title: () => "Ente",
+ }
+ : filter,
+ ),
+ [collectionSummaries],
+ );
+ const activeAlbumFilter =
+ albumFilter === undefined ||
+ visibleAlbumFilters.some(({ value }) => value == albumFilter)
+ ? albumFilter
+ : "ente";
+ const visibleCollectionSummaries = useMemo(
+ () =>
+ mode != "albums"
+ ? collectionSummaries
+ : collectionSummaries.filter(
+ (cs) =>
+ activeAlbumFilter !== undefined &&
+ matchesAlbumFilter(cs, activeAlbumFilter),
+ ),
+ [mode, collectionSummaries, activeAlbumFilter],
+ );
+
+ useEffect(() => {
+ if (albumFilter != activeAlbumFilter) setAlbumFilter(activeAlbumFilter);
+ }, [albumFilter, activeAlbumFilter]);
useEffect(() => {
if (!listRef.current) return;
@@ -94,7 +139,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
case "albums":
case "hidden-albums":
case "archive-albums":
- i = collectionSummaries.findIndex(
+ i = visibleCollectionSummaries.findIndex(
({ id }) => id == activeCollectionID,
);
break;
@@ -105,7 +150,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
if (i != -1) listRef.current.scrollToItem(i, "smart");
}, [
mode,
- collectionSummaries,
+ visibleCollectionSummaries,
activeCollectionID,
people,
activePerson,
@@ -122,7 +167,8 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
mode == "archive-albums"
? {
type: "collections",
- collectionSummaries,
+ collectionSummaries: visibleCollectionSummaries,
+ indented: mode == "albums",
activeCollectionID: activeCollectionID!,
onSelectCollectionID,
}
@@ -134,7 +180,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
},
[
mode,
- collectionSummaries,
+ visibleCollectionSummaries,
activeCollectionID,
onSelectCollectionID,
people,
@@ -152,6 +198,40 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
? t("section_archive")
: t("albums");
+ const albumListID = `${titleID}-albums`;
+ const items = (
+ <Box
+ id={mode == "albums" ? albumListID : undefined}
+ sx={{
+ flex: mode == "albums" ? "0 1 auto" : 1,
+ height:
+ mode == "albums"
+ ? getItemCount(itemData) * (mobile ? 46 : 50)
+ : undefined,
+ minHeight: 0,
+ minWidth: 0,
+ }}
+ >
+ <AutoSizer onResize={({ height }) => setViewportHeight(height)}>
+ {({ width, height }) => (
+ <FixedSizeList
+ ref={listRef}
+ outerElementType={BarScrollContainer}
+ width={width}
+ height={height}
+ itemData={itemData}
+ itemKey={getItemKey}
+ itemCount={getItemCount(itemData)}
+ itemSize={mobile ? 46 : 50}
+ style={{ overflowX: "hidden" }}
+ >
+ {ListItem}
+ </FixedSizeList>
+ )}
+ </AutoSizer>
+ </Box>
+ );
+
const navigation = (
<Stack
component="nav"
@@ -247,25 +327,58 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
</IconButton>
)}
</Stack>
- <Box sx={{ flex: 1, minHeight: 0, minWidth: 0 }}>
- <AutoSizer onResize={({ height }) => setViewportHeight(height)}>
- {({ width, height }) => (
- <FixedSizeList
- ref={listRef}
- outerElementType={BarScrollContainer}
- width={width}
- height={height}
- itemData={itemData}
- itemKey={getItemKey}
- itemCount={getItemCount(itemData)}
- itemSize={mobile ? 46 : 50}
- style={{ overflowX: "hidden" }}
- >
- {ListItem}
- </FixedSizeList>
- )}
- </AutoSizer>
- </Box>
+ {mode == "albums" ? (
+ <Stack
+ role="group"
+ aria-label={t("filter_albums")}
+ sx={{ flex: 1, minHeight: 0, gap: "2px" }}
+ >
+ {visibleAlbumFilters.map((filter) => (
+ <React.Fragment key={filter.value}>
+ <BarCard
+ aria-label={filter.title()}
+ aria-expanded={
+ activeAlbumFilter == filter.value
+ }
+ aria-controls={
+ activeAlbumFilter == filter.value
+ ? albumListID
+ : undefined
+ }
+ onClick={() =>
+ setAlbumFilter((current) =>
+ current == filter.value
+ ? undefined
+ : filter.value,
+ )
+ }
+ sx={{
+ flexShrink: 0,
+ bgcolor:
+ activeAlbumFilter == filter.value
+ ? "var(--gallery-navigation-surface)"
+ : undefined,
+ }}
+ >
+ <CardText>{filter.label()}</CardText>
+ <ExpandMoreIcon
+ sx={{
+ fontSize: 16,
+ color: "text.muted",
+ transform:
+ activeAlbumFilter == filter.value
+ ? undefined
+ : "rotate(-90deg)",
+ }}
+ />
+ </BarCard>
+ {activeAlbumFilter == filter.value && items}
+ </React.Fragment>
+ ))}
+ </Stack>
+ ) : (
+ items
+ )}
</Stack>
);
@@ -327,6 +440,7 @@ type ItemData =
| {
type: "collections";
collectionSummaries: CollectionSummary[];
+ indented: boolean;
activeCollectionID: number;
onSelectCollectionID: (id: number) => void;
}
@@ -382,6 +496,10 @@ const ListItem = memo((props: ListChildComponentProps<ItemData>) => {
activeCollectionID,
onSelectCollectionID,
}}
+ indented={
+ data.indented &&
+ !collectionSummary.attributes.has("system")
+ }
/>
);
break;
@@ -405,12 +523,14 @@ const ListItem = memo((props: ListChildComponentProps<ItemData>) => {
interface CollectionBarCardProps {
collectionSummary: CollectionSummary;
+ indented: boolean;
activeCollectionID: number;
onSelectCollectionID: (collectionID: number) => void;
}
const CollectionBarCard: React.FC<CollectionBarCardProps> = ({
collectionSummary,
+ indented,
activeCollectionID,
onSelectCollectionID,
}: CollectionBarCardProps) => (
@@ -421,6 +541,11 @@ const CollectionBarCard: React.FC<CollectionBarCardProps> = ({
}
title={collectionSummary.name}
onClick={() => onSelectCollectionID(collectionSummary.id)}
+ sx={
+ indented
+ ? { marginInlineStart: "20px", width: "calc(100% - 20px)" }
+ : undefined
+ }
>
<Box aria-hidden sx={{ flexShrink: 0 }}>
<ItemCard
diff --git a/web/apps/photos/src/utils/album-filters.ts b/web/apps/photos/src/utils/album-filters.ts
new file mode 100644
index 0000000000..9b4935a9cb
--- /dev/null
+++ b/web/apps/photos/src/utils/album-filters.ts
@@ -0,0 +1,80 @@
+import {
+ isBulkDeletableEmptyAlbum,
+ type CollectionSummary,
+} from "ente-new/photos/services/collection-summary";
+import { t } from "i18next";
+
+export type AlbumFilter =
+ "all" | "ente" | "shared" | "received" | "links" | "empty-albums";
+
+export const albumFilters: {
+ value: AlbumFilter;
+ label: () => string;
+ title: () => string;
+}[] = [
+ { value: "all", label: () => t("all"), title: () => t("all_albums") },
+ {
+ value: "shared",
+ label: () => t("shared_albums_label"),
+ title: () => t("shared_albums_title"),
+ },
+ {
+ value: "received",
+ label: () => t("received_albums_label"),
+ title: () => t("received_albums_title"),
+ },
+ {
+ value: "links",
+ label: () => t("links_albums_label"),
+ title: () => t("links_albums_title"),
+ },
+ {
+ value: "empty-albums",
+ label: () => t("empty_albums"),
+ title: () => t("empty_albums_title"),
+ },
+];
+
+export const matchesAlbumFilter = (
+ cs: CollectionSummary,
+ albumFilter: AlbumFilter,
+): boolean => {
+ switch (albumFilter) {
+ case "all":
+ return true;
+ case "ente":
+ return (
+ cs.fileCount > 0 &&
+ !cs.attributes.has("system") &&
+ !cs.attributes.has("shared") &&
+ !matchesAlbumFilter(cs, "shared") &&
+ !matchesAlbumFilter(cs, "received") &&
+ !matchesAlbumFilter(cs, "links")
+ );
+ case "shared":
+ return (
+ !cs.attributes.has("sharedIncoming") &&
+ !cs.attributes.has("quickLink") &&
+ (cs.attributes.has("sharedOutgoing") ||
+ cs.attributes.has("sharedViaLink"))
+ );
+ case "received":
+ return cs.attributes.has("sharedIncoming");
+ case "links":
+ return cs.attributes.has("quickLink");
+ case "empty-albums":
+ return isBulkDeletableEmptyAlbum(cs);
+ }
+};
+
+export const visibleAlbumFilters = (collectionSummaries: CollectionSummary[]) =>
+ albumFilters.filter(({ value }) => {
+ if (value == "all") return true;
+ if (value == "empty-albums") {
+ return (
+ collectionSummaries.filter(isBulkDeletableEmptyAlbum).length >=
+ 3
+ );
+ }
+ return collectionSummaries.some((cs) => matchesAlbumFilter(cs, value));
+ });
diff --git a/web/apps/photos/tests/album-filters.test.ts b/web/apps/photos/tests/album-filters.test.ts
new file mode 100644
index 0000000000..ee3d9d3d74
--- /dev/null
+++ b/web/apps/photos/tests/album-filters.test.ts
@@ -0,0 +1,119 @@
+import type {
+ CollectionSummary,
+ CollectionSummaryAttribute,
+} from "ente-new/photos/services/collection-summary";
+import { describe, expect, test } from "vitest";
+import {
+ matchesAlbumFilter,
+ visibleAlbumFilters,
+ type AlbumFilter,
+} from "../src/utils/album-filters";
+
+const album = (
+ id: number,
+ attributes: CollectionSummaryAttribute[] = [],
+ fileCount = 1,
+): CollectionSummary => ({
+ id,
+ type: "album",
+ attributes: new Set(attributes),
+ name: `Album ${id}`,
+ fileCount,
+ latestFile: undefined,
+ coverFile: undefined,
+ updationTime: undefined,
+ sortPriority: 0,
+});
+
+describe("album filters shared by the dialog and sidebar", () => {
+ test("Ente contains non-empty local albums outside the other categories", () => {
+ const albums = [
+ album(1),
+ { ...album(2, ["userFavorites"]), type: "userFavorites" as const },
+ album(3, ["sharedOutgoing", "shared"]),
+ album(4, ["sharedIncoming"]),
+ album(5, ["sharedViaLink"]),
+ album(6, ["quickLink"]),
+ album(7, [], 0),
+ album(8, ["archived"], 0),
+ album(9, ["system"]),
+ album(10, ["shared"]),
+ ];
+ expect(
+ albums
+ .filter((cs) => matchesAlbumFilter(cs, "ente"))
+ .map(({ id }) => id),
+ ).toEqual([1, 2]);
+ expect(
+ albums.filter((cs) => matchesAlbumFilter(cs, "all")),
+ ).toHaveLength(10);
+ });
+
+ test("separates outgoing sharing, incoming sharing, and quick links", () => {
+ const albums = [
+ album(1),
+ album(2, ["sharedOutgoing", "shared"]),
+ album(3, ["sharedIncoming", "sharedViaLink", "shared"]),
+ album(4, ["sharedViaLink", "shared"]),
+ album(5, ["quickLink", "sharedViaLink", "shared"]),
+ ];
+ const ids = (filter: AlbumFilter) =>
+ albums
+ .filter((cs) => matchesAlbumFilter(cs, filter))
+ .map(({ id }) => id);
+ expect(ids("all")).toEqual([1, 2, 3, 4, 5]);
+ expect(ids("shared")).toEqual([2, 4]);
+ expect(ids("received")).toEqual([3]);
+ expect(ids("links")).toEqual([5]);
+ expect(albums.map(({ id }) => id)).toEqual([1, 2, 3, 4, 5]);
+ });
+
+ test("empty albums exclude shared, archived, system, and favorites collections", () => {
+ expect(matchesAlbumFilter(album(1, [], 0), "empty-albums")).toBe(true);
+ expect(
+ matchesAlbumFilter(
+ { ...album(2, [], 0), type: "folder" },
+ "empty-albums",
+ ),
+ ).toBe(true);
+ for (const attribute of ["shared", "archived", "system"] as const) {
+ expect(
+ matchesAlbumFilter(album(3, [attribute], 0), "empty-albums"),
+ ).toBe(false);
+ }
+ expect(
+ matchesAlbumFilter(
+ { ...album(4, [], 0), type: "userFavorites" },
+ "empty-albums",
+ ),
+ ).toBe(false);
+ expect(matchesAlbumFilter(album(5), "empty-albums")).toBe(false);
+ });
+
+ test("shows available categories in pill order and requires three eligible empty albums", () => {
+ const albums = [
+ album(1, [], 0),
+ album(2, [], 0),
+ album(3, ["shared"], 0),
+ ];
+ expect(visibleAlbumFilters(albums).map(({ value }) => value)).toEqual([
+ "all",
+ ]);
+ albums.push(
+ album(4, [], 0),
+ album(5, ["sharedOutgoing"]),
+ album(6, ["sharedIncoming"]),
+ album(7, ["quickLink"]),
+ );
+ expect(visibleAlbumFilters(albums).map(({ value }) => value)).toEqual([
+ "all",
+ "shared",
+ "received",
+ "links",
+ "empty-albums",
+ ]);
+ expect(visibleAlbumFilters([]).map(({ value }) => value)).toEqual([
+ "all",
+ ]);
+ });
+});
diff --git a/web/packages/gallery/components/FullScreenDropZone.tsx b/web/packages/gallery/components/FullScreenDropZone.tsx
index 4f96932557..4080e86424 100644
--- a/web/packages/gallery/components/FullScreenDropZone.tsx
+++ b/web/packages/gallery/components/FullScreenDropZone.tsx
@@ -83,7 +83,7 @@ export const FullScreenDropZone: React.FC<
<>
<input {...getInputProps()} />
<Stack
- sx={{ flex: 1 }}
+ sx={{ flex: 1, minHeight: 0 }}
{...getRootProps({ onDragEnter: handleDragEnter })}
>
{!disabled && (isDragActive || isDropPending) && (