Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web] Virtualize hidden album overview

AswinAsok1384e5356a5a
diff --git a/web/apps/photos/src/components/gallery/HiddenAlbumsHeader.tsx b/web/apps/photos/src/components/gallery/HiddenAlbumsHeader.tsx
index 2bbe514ff3..09934301d0 100644
--- a/web/apps/photos/src/components/gallery/HiddenAlbumsHeader.tsx
+++ b/web/apps/photos/src/components/gallery/HiddenAlbumsHeader.tsx
@@ -1,8 +1,10 @@
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
-import { IconButton, Stack, Tooltip, Typography } from "@mui/material";
+import { Box, IconButton, Stack, Tooltip, Typography } from "@mui/material";
import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
import { t } from "i18next";
-import { useEffect, useRef, useState } from "react";
+import { useState } from "react";
+import AutoSizer from "react-virtualized-auto-sizer";
+import { FixedSizeList, type ListChildComponentProps } from "react-window";
import { AlbumTile } from "./AlbumTile";
interface HiddenAlbumsHeaderProps {
@@ -19,26 +21,7 @@ export const HiddenAlbumsHeader = ({
onSelectAlbum,
onBack,
}: HiddenAlbumsHeaderProps) => {
- const rowRef = useRef<HTMLDivElement>(null);
- const [hasMoreAlbums, setHasMoreAlbums] = useState(false);
-
- useEffect(() => {
- const row = rowRef.current;
- if (!row) return;
-
- const updateFade = () =>
- setHasMoreAlbums(
- row.scrollWidth - row.clientWidth - row.scrollLeft > 1,
- );
- updateFade();
- row.addEventListener("scroll", updateFade, { passive: true });
- const observer = new ResizeObserver(updateFade);
- observer.observe(row);
- return () => {
- row.removeEventListener("scroll", updateFade);
- observer.disconnect();
- };
- }, [albums.length]);
+ const [scrollOffset, setScrollOffset] = useState(0);
return (
<Stack
@@ -72,34 +55,72 @@ export const HiddenAlbumsHeader = ({
{t("hidden_albums")}
</Typography>
</Stack>
- <Stack
- ref={rowRef}
- direction="row"
- sx={{
- "--album-name-size": "14px",
- "--album-count-size": "12px",
- "--album-text-gap": "4px",
- gap: "22px",
- overflowX: "auto",
- pb: "12px",
- minHeight: 0,
- maskImage: hasMoreAlbums
- ? "linear-gradient(to right, black calc(100% - 110px), transparent 100%)"
- : undefined,
- }}
- >
- {albums.map((album) => (
- <AlbumTile
- key={album.id}
- album={album}
- onSelectAlbum={onSelectAlbum}
- showBadges={false}
- countLabel={t("photos_count", {
- count: album.fileCount,
- })}
- />
- ))}
- </Stack>
+ {albums.length > 0 && (
+ <Box
+ sx={{
+ "--album-name-size": "14px",
+ "--album-count-size": "12px",
+ "--album-text-gap": "4px",
+ height: 200,
+ flexShrink: 0,
+ }}
+ >
+ <AutoSizer disableHeight>
+ {({ width }) => (
+ <FixedSizeList
+ layout="horizontal"
+ width={width}
+ height={200}
+ itemCount={albums.length}
+ itemSize={162}
+ itemData={{ albums, onSelectAlbum }}
+ itemKey={(index, data) =>
+ data.albums[index]!.id
+ }
+ overscanCount={1}
+ useIsScrolling
+ onScroll={({ scrollOffset }) =>
+ setScrollOffset(scrollOffset)
+ }
+ style={{
+ overflowY: "hidden",
+ maskImage:
+ albums.length * 162 -
+ width -
+ scrollOffset >
+ 1
+ ? "linear-gradient(to right, black calc(100% - 110px), transparent 100%)"
+ : undefined,
+ }}
+ >
+ {HiddenAlbumTile}
+ </FixedSizeList>
+ )}
+ </AutoSizer>
+ </Box>
+ )}
</Stack>
);
};
+
+const HiddenAlbumTile = ({
+ index,
+ style,
+ data: { albums, onSelectAlbum },
+ isScrolling,
+}: ListChildComponentProps<
+ Pick<HiddenAlbumsHeaderProps, "albums" | "onSelectAlbum">
+>) => {
+ const album = albums[index]!;
+ return (
+ <div style={style}>
+ <AlbumTile
+ album={album}
+ onSelectAlbum={onSelectAlbum}
+ isScrolling={isScrolling}
+ showBadges={false}
+ countLabel={t("photos_count", { count: album.fileCount })}
+ />
+ </div>
+ );
+};