Skip to content

armgit / ente

Public Imported from GitHub
0

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

remove(ListHeader):unwanted-transition

Aswin Asok057bca478c86
diff --git a/web/apps/albums/src/public-album/components/FileList.tsx b/web/apps/albums/src/public-album/components/FileList.tsx
index c767c6bc07..a7eb1cbfd8 100644
--- a/web/apps/albums/src/public-album/components/FileList.tsx
+++ b/web/apps/albums/src/public-album/components/FileList.tsx
@@ -30,7 +30,6 @@ import React, {
useCallback,
useDeferredValue,
useEffect,
- useLayoutEffect,
useMemo,
useRef,
useState,
@@ -272,9 +271,9 @@ export const FileList: React.FC<FileListProps> = ({
emptyStateAction,
]);
- useLayoutEffect(() => {
+ useEffect(() => {
listRef.current?.resetAfterIndex(0);
- }, [items, header?.height]);
+ }, [items]);
useEffect(() => {
const notSelectedFiles = annotatedFiles.filter(
@@ -484,11 +483,8 @@ export const FileList: React.FC<FileListProps> = ({
);
const itemSize = useCallback(
- (index: number) =>
- index == 0 && header && itemData.items[0]?.type == "span"
- ? header.height
- : itemData.items[index]!.height,
- [header, itemData],
+ (index: number) => itemData.items[index]!.height,
+ [itemData],
);
const itemKey = useCallback((index: number, itemData: FileListItemData) => {
diff --git a/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx b/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx
index 3107b52b85..c07860d686 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx
@@ -73,9 +73,7 @@ export const MobileCover = memo<MobileCoverProps>(
locations
</TripSubtitle>
<AlbumDescription
- key={albumDescription}
description={albumDescription}
- expandable
sx={{
mt: "4px",
pb: "20px",
diff --git a/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx b/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx
index f045200d6e..3ff6bcef3a 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx
@@ -77,9 +77,7 @@ export const TripCover = memo<TripCoverProps>(
{locationCount} locations
</TripSubtitle>
<AlbumDescription
- key={albumDescription}
description={albumDescription}
- expandable
sx={{
maxWidth: "420px",
mt: "4px",
diff --git a/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx b/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx
index d3586d3a8c..5914a6d0a7 100644
--- a/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx
+++ b/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx
@@ -75,7 +75,6 @@ import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import {
AlbumDescription,
- galleryItemsDescriptionHeight,
GalleryItemsHeaderAdapter,
GalleryItemsSummary,
} from "ente-new/photos/components/gallery/ListHeader";
@@ -605,18 +604,13 @@ export default function PublicAlbumPage() {
const hasSummaryDescription = !!albumDescription && !showMobileMasonryCover;
const [descriptionHeight, setDescriptionHeight] = useState(0);
- useEffect(() => {
- setDescriptionHeight(
- hasSummaryDescription ? galleryItemsDescriptionHeight : 0,
- );
- }, [hasSummaryDescription, albumDescription]);
-
const fileListHeaderHeightForViewport =
(isMobileHeaderLayout
? showMobileMasonryCover
? mobileMasonryFileListHeaderHeight(viewportWidth)
: fileListHeaderHeightMobile
- : fileListHeaderHeight) + descriptionHeight;
+ : fileListHeaderHeight) +
+ (hasSummaryDescription ? descriptionHeight : 0);
const fileListHeader = useMemo<FileListHeaderOrFooter | undefined>(
() =>
@@ -1544,9 +1538,7 @@ const PublicAlbumCoverHero: React.FC<PublicAlbumCoverHeroProps> = ({
<MobileMasonryCoverContent>
<MobileMasonryCoverTitle>{title}</MobileMasonryCoverTitle>
<AlbumDescription
- key={description}
description={description}
- expandable
sx={{ maxWidth: "100%", mt: "-6px", opacity: 0.8 }}
/>
<Typography
diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
index f4e4660c95..bec3b301f9 100644
--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
@@ -118,7 +118,6 @@ export const CollectionHeader: React.FC<CollectionHeaderProps> = (props) => {
name={name}
description={description}
descriptionMaxWidth={480}
- descriptionOpacity={0.9}
fileCount={fileCount}
endIcon={<EndIcon />}
onDescriptionHeightChange={onDescriptionHeightChange}
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index 9d8a9368dc..2aad239233 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -21,7 +21,6 @@ import {
} from "ente-gallery/components/utils/save-groups";
import type { Collection } from "ente-media/collection";
import {
- galleryItemsDescriptionHeight,
GalleryItemsHeaderAdapter,
GalleryItemsSummary,
} from "ente-new/photos/components/gallery/ListHeader";
@@ -35,13 +34,7 @@ import {
} from "ente-new/photos/services/collection-summary";
import type { Person } from "ente-new/photos/services/ml/people";
import { includes } from "ente-utils/type-guards";
-import React, {
- useCallback,
- useEffect,
- useLayoutEffect,
- useMemo,
- useState,
-} from "react";
+import React, { useCallback, useEffect, useMemo, useState } from "react";
import { AlbumCastDialog } from "./AlbumCastDialog";
import {
CollectionHeader,
@@ -169,12 +162,6 @@ export const GalleryBarAndListHeader: React.FC<
const [descriptionHeight, setDescriptionHeight] = useState(0);
useEffect(() => {
- setDescriptionHeight(
- albumDescription ? galleryItemsDescriptionHeight : 0,
- );
- }, [albumDescription]);
-
- useLayoutEffect(() => {
if (shouldHide) return;
const collectionSummary = toShowCollectionSummaries.get(
@@ -221,7 +208,7 @@ export const GalleryBarAndListHeader: React.FC<
) : (
<></>
),
- height: 68 + descriptionHeight,
+ height: 68 + (albumDescription ? descriptionHeight : 0),
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
@@ -241,6 +228,7 @@ export const GalleryBarAndListHeader: React.FC<
onAddSaveGroup,
onShowMap,
onEditAlbumDetails,
+ albumDescription,
descriptionHeight,
// TODO: Cluster
// This causes a loop since it is an array dep
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index 460b7e7d86..fdcb9eddf4 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -52,7 +52,6 @@ import React, {
useCallback,
useDeferredValue,
useEffect,
- useLayoutEffect,
useMemo,
useRef,
useState,
@@ -328,9 +327,9 @@ export const FileList: React.FC<FileListProps> = ({
layoutParams,
]);
- useLayoutEffect(() => {
+ useEffect(() => {
listRef.current?.resetAfterIndex(0);
- }, [items, header?.height]);
+ }, [items]);
useEffect(() => {
const notSelectedFiles = annotatedFiles.filter(
@@ -732,11 +731,8 @@ export const FileList: React.FC<FileListProps> = ({
);
const itemSize = useCallback(
- (index: number) =>
- index == 0 && header && itemData.items[0]?.type == "span"
- ? header.height
- : itemData.items[index]!.height,
- [header, itemData],
+ (index: number) => itemData.items[index]!.height,
+ [itemData],
);
const itemKey = useCallback((index: number, itemData: FileListItemData) => {
diff --git a/web/packages/new/photos/components/gallery/ListHeader.tsx b/web/packages/new/photos/components/gallery/ListHeader.tsx
index 9ef5696ab0..e7fb1acdb9 100644
--- a/web/packages/new/photos/components/gallery/ListHeader.tsx
+++ b/web/packages/new/photos/components/gallery/ListHeader.tsx
@@ -13,7 +13,6 @@ interface GalleryItemsSummaryProps {
name: string;
description?: string;
descriptionMaxWidth?: number;
- descriptionOpacity?: number;
nameProps?: TypographyProps;
fileCount: number;
endIcon?: React.ReactNode;
@@ -26,7 +25,6 @@ export const GalleryItemsSummary: React.FC<GalleryItemsSummaryProps> = ({
name,
description,
descriptionMaxWidth,
- descriptionOpacity,
nameProps,
fileCount,
endIcon,
@@ -57,120 +55,76 @@ export const GalleryItemsSummary: React.FC<GalleryItemsSummaryProps> = ({
</Stack>
<AlbumDescription
- key={description}
description={description}
- expandable={Boolean(onDescriptionHeightChange)}
sx={{
pt: "4px",
maxWidth: descriptionMaxWidth ?? 420,
- color: "text.muted",
- opacity: descriptionOpacity,
+ color: "text.faint",
}}
onHeightChange={onDescriptionHeightChange}
/>
</Box>
);
-export const galleryItemsDescriptionHeight = 24;
-
interface AlbumDescriptionProps {
description?: string;
- expandable?: boolean;
sx?: TypographyProps["sx"];
onHeightChange?: (height: number) => void;
}
export const AlbumDescription: React.FC<AlbumDescriptionProps> = ({
description,
- expandable,
sx,
onHeightChange,
}) => {
- const [expansionState, setExpansionState] = useState<
- "collapsed" | "expanded" | "collapsing"
- >("collapsed");
- const [expandedHeight, setExpandedHeight] = useState(
- galleryItemsDescriptionHeight,
- );
- const textRef = useRef<HTMLElement>(null);
+ const [expandedDescription, setExpandedDescription] = useState<string>();
+ const expanded = expandedDescription === description;
+ const textRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
+ if (!onHeightChange) return;
+
const text = textRef.current;
- if (!text || (!expandable && !onHeightChange)) return;
+ if (!text) {
+ onHeightChange(0);
+ return;
+ }
- const report = () => {
- setExpandedHeight(text.scrollHeight);
- onHeightChange?.(text.offsetHeight);
- };
+ const report = () => onHeightChange(text.offsetHeight);
report();
const observer = new ResizeObserver(report);
observer.observe(text);
return () => observer.disconnect();
- }, [description, expandable, onHeightChange]);
+ }, [description, onHeightChange]);
- if (!description) return <></>;
+ if (!description) return null;
- const handleToggle = () => {
- if (expansionState == "collapsed") {
- setExpansionState("expanded");
- } else if (expansionState == "expanded") {
- setExpansionState(
- matchMedia("(prefers-reduced-motion: reduce)").matches
- ? "collapsed"
- : "collapsing",
- );
- }
- };
-
- const handleTransitionEnd: React.TransitionEventHandler<HTMLElement> = (
- event,
- ) => {
- if (
- event.propertyName == "max-height" &&
- expansionState == "collapsing"
- )
- setExpansionState("collapsed");
- };
+ const handleClick = () =>
+ setExpandedDescription(expanded ? undefined : description);
return (
<Typography
- component={expandable ? "button" : "p"}
- ref={(element: HTMLElement | null) => {
- textRef.current = element;
- }}
- type={expandable ? "button" : undefined}
- aria-expanded={
- expandable ? expansionState == "expanded" : undefined
- }
- onClick={expandable ? handleToggle : undefined}
- onTransitionEnd={expandable ? handleTransitionEnd : undefined}
+ component="button"
+ type="button"
+ variant="small"
+ ref={textRef}
+ aria-expanded={expanded}
+ onClick={handleClick}
sx={[
{
display: "-webkit-box",
overflow: "hidden",
WebkitBoxOrient: "vertical",
- WebkitLineClamp:
- expansionState == "collapsed" ? 1 : "unset",
+ WebkitLineClamp: expanded ? "unset" : 1,
overflowWrap: "anywhere",
textWrap: "pretty",
- fontSize: "14px",
- lineHeight: "20px",
- ...(expandable && {
- border: 0,
- p: 0,
- background: "none",
- color: "inherit",
- textAlign: "left",
- cursor: "pointer",
- maxHeight:
- expansionState == "expanded"
- ? `${expandedHeight}px`
- : `${galleryItemsDescriptionHeight}px`,
- transition: "max-height 140ms ease-out",
- "@media (prefers-reduced-motion: reduce)": {
- transition: "none",
- },
- }),
+ width: "100%",
+ border: 0,
+ p: 0,
+ background: "none",
+ color: "inherit",
+ textAlign: "left",
+ cursor: "pointer",
},
...(sx ? (isSxArray(sx) ? sx : [sx]) : []),
]}