π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refine Space profile post layout and reply controls
Anand Baburajan9f48032c9d98
diff --git a/web/apps/space/src/components/PostReplyControls.tsx b/web/apps/space/src/components/PostReplyControls.tsxindex f1fae40adf..252d4c51c8 100644--- a/web/apps/space/src/components/PostReplyControls.tsx+++ b/web/apps/space/src/components/PostReplyControls.tsx@@ -19,10 +19,9 @@ import React from "react";const green = "#08C225";const textBase = "#F4F4F4";const textSecondary = "#A6A6A6";-const controlBackground = "rgba(36, 36, 36, 0.72)";-const controlBackgroundHover = "rgba(48, 48, 48, 0.86)";-const inputBackground = "rgba(58, 58, 58, 0.86)";-const inputBackgroundActive = "rgba(72, 72, 72, 0.9)";+const controlBackground = "#36363A";+const controlBackgroundHover = "#404044";+const controlBackgroundActive = "#48484D";const controlIcon = "#D8D8D8";const replyInputMinHeight = 48;const replyInputPadding = 14;@@ -35,7 +34,6 @@ const viewerActionButtonSx = {bgcolor: controlBackground,border: 0,borderRadius: "50%",- boxShadow: "0 10px 28px rgba(0, 0, 0, 0.36)",color: controlIcon,cursor: "pointer",display: "flex",@@ -43,7 +41,7 @@ const viewerActionButtonSx = {justifyContent: "center",p: 0,width: 48,- "&:active": { bgcolor: "#3A3A3A" },+ "&:active": { bgcolor: controlBackgroundActive },"&:focus-visible": { outline: `2px solid ${green}`, outlineOffset: 2 },"&:hover": { bgcolor: controlBackgroundHover },};@@ -109,7 +107,7 @@ export const SpacePostReplyControls: React.FC<SpacePostReplyControlsProps> = ({rows={1}{...replyInputProps}sx={{- bgcolor: inputBackground,+ bgcolor: controlBackground,border: 0,borderRadius: "24px",boxSizing: "border-box",@@ -131,7 +129,7 @@ export const SpacePostReplyControls: React.FC<SpacePostReplyControlsProps> = ({resize: "none","&::placeholder": { color: textSecondary },"&:disabled": { opacity: 0.74 },- "&:focus": { bgcolor: inputBackgroundActive },+ "&:focus": { bgcolor: controlBackgroundHover },}}/>)}@@ -192,7 +190,9 @@ export const SpacePostReplyControls: React.FC<SpacePostReplyControlsProps> = ({: controlBackgroundHover,},"&:active": {- bgcolor: isSendActive ? "#069B1E" : "#3A3A3A",+ bgcolor: isSendActive+ ? "#069B1E"+ : controlBackgroundActive,},"@media (prefers-reduced-motion: reduce)": {animation: "none",diff --git a/web/apps/space/src/components/ProfileLatestPost.tsx b/web/apps/space/src/components/ProfileLatestPost.tsxindex 3d36127ec5..18e59d3001 100644--- a/web/apps/space/src/components/ProfileLatestPost.tsx+++ b/web/apps/space/src/components/ProfileLatestPost.tsx@@ -4,7 +4,7 @@ import { spacePostLikePopDurationMs } from "components/post-like-animation";import { SpacePostReplyControls } from "components/PostReplyControls";import log from "ente-base/log";import React from "react";-import { spaceTextMuted } from "styles/colors";+import { spaceSurface, spaceTextMuted } from "styles/colors";import { clampSpaceMessageText } from "utils/message-limits";interface ProfileLatestPostProps {@@ -92,7 +92,13 @@ export const ProfileLatestPost: React.FC<ProfileLatestPostProps> = ({<Boxcomponent="article"aria-label="Latest post"- sx={{ minWidth: 0, width: "100%" }}+ sx={{+ bgcolor: spaceSurface,+ borderRadius: "16px",+ minWidth: 0,+ overflow: "hidden",+ width: "100%",+ }}><Boxsx={{@@ -146,7 +152,7 @@ export const ProfileLatestPost: React.FC<ProfileLatestPostProps> = ({)}</Box>{(onReply || onSetLiked) && (- <Box sx={{ mt: "12px" }}>+ <Box sx={{ p: "12px" }}><SpacePostReplyControlscanSendReply={canSendReply}disabled={disabled}diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex 8417a8e8bc..aae0f67e51 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -57,6 +57,7 @@ import {spacePostPreviewImageForFile,type SpaceDraftPostImage,} from "utils/post-image";+import { profilePhotoGap, profilePhotoRows } from "utils/profile-photo-layout";import { thumbHashDataURLFromBase64 } from "utils/thumbhash";const green = "#08C225";@@ -76,7 +77,7 @@ const profileAvatarTopOffset = 54;const profileAvatarSize = 132;const profileCoverHeight =profileHeaderHeight + profileAvatarTopOffset + profileAvatarSize / 2;-const photoMasonryGap = "3px";+const photoMasonryGap = `${profilePhotoGap}px`;const photoMasonryPlaceholderBackground = spaceSurface;const photoMasonryRadius = "16px";const profileCoverRadius = "12px";@@ -126,14 +127,10 @@ interface PostMasonryTile {item: ProfilePostItem;}-interface PostMasonryRow {- aspectRatio: number;- tiles: PostMasonryTile[];-}-const buildPostMasonrySections = (items: ProfilePostItem[],loadedDimensionsByID: Record<string, ProfilePhotoDimensions>,+ width: number,) => {const now = new Date();const dayMs = 24 * 60 * 60 * 1000;@@ -173,7 +170,7 @@ const buildPostMasonrySections = (? latestSection: sections.find(({ sinceMs }) => item.timestampMs >= sinceMs)!;section.tiles.push({- aspectRatio: Math.max(0.1, photoAspectRatio(dimensions)),+ aspectRatio: photoAspectRatio(dimensions),dimensions,index,item,@@ -184,38 +181,10 @@ const buildPostMasonrySections = (.filter(({ tiles }) => tiles.length > 0).map(({ title, tiles }) => ({title,- rows: buildPostMasonryRows(tiles),+ rows: profilePhotoRows(tiles, width),}));};-const buildPostMasonryRows = (tiles: PostMasonryTile[]): PostMasonryRow[] => {- const rows = new Array<PostMasonryRow>();- let nextTileIndex = 0;-- while (nextTileIndex < tiles.length) {- const rowSize = preferredPostMasonryRowSize(- tiles.length - nextTileIndex,- );- const rowTiles = tiles.slice(nextTileIndex, nextTileIndex + rowSize);- rows.push({- aspectRatio: rowTiles.reduce(- (aspectRatio, tile) => aspectRatio + tile.aspectRatio,- 0,- ),- tiles: rowTiles,- });- nextTileIndex += rowSize;- }-- return rows;-};--const preferredPostMasonryRowSize = (remainingTiles: number) => {- if (remainingTiles <= 3) return remainingTiles;- if (remainingTiles == 4 || remainingTiles == 5) return 2;- return remainingTiles % 2 == 0 ? 2 : 3;-};-const profilePostImageCacheKey = (item: ProfilePostItem) =>[item.id, item.imageAsset?.objectKey ?? item.imageUrl ?? ""].join(":");@@ -332,9 +301,9 @@ const ProfilePostLoadingIndicator: React.FC = () => ();interface ProfilePostTileProps {- aspectRatio: number;dimensions: ProfilePhotoDimensions;displayName: string;+ flexGrow: number;imageUrl?: string;index: number;isSingleItemRow: boolean;@@ -348,9 +317,9 @@ interface ProfilePostTileProps {}const ProfilePostTile: React.FC<ProfilePostTileProps> = ({- aspectRatio,dimensions,displayName,+ flexGrow,imageUrl,index,isSingleItemRow,@@ -427,15 +396,12 @@ const ProfilePostTile: React.FC<ProfilePostTileProps> = ({}}sx={{appearance: "none",- aspectRatio: isSingleItemRow- ? `${dimensions.width} / ${dimensions.height}`- : undefined,+ aspectRatio: `${dimensions.width} / ${dimensions.height}`,bgcolor: photoMasonryPlaceholderBackground,border: 0,cursor: imageUrl && !isUnavailable ? "pointer" : "default",display: "block",- flex: isSingleItemRow ? "0 0 100%" : `${aspectRatio} 1 0`,- height: isSingleItemRow ? "auto" : "100%",+ flex: isSingleItemRow ? "0 0 100%" : `${flexGrow} 1 0`,minWidth: 0,opacity: 1,overflow: "hidden",@@ -628,6 +594,8 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({Record<string, true>>({});const [loadedCoverUrl, setLoadedCoverUrl] = useState<string | null>(null);+ const [postGridWidth, setPostGridWidth] = useState(0);+ const postGridRef = React.useRef<HTMLDivElement | null>(null);const postInputRef = React.useRef<HTMLInputElement | null>(null);const postImageLoadsInFlightRef = React.useRef<Map<string, Promise<string | undefined>>@@ -670,6 +638,17 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({const canOpenProfileCover = Boolean(onOpenProfileCover);const canOpenProfilePhoto = Boolean(onOpenProfilePhoto);const hasProfilePosts = postsSharedCount > 0;+ React.useLayoutEffect(() => {+ const grid = postGridRef.current;+ if (!grid) return;++ const observer = new ResizeObserver(([entry]) =>+ setPostGridWidth(entry!.contentRect.width),+ );+ setPostGridWidth(grid.getBoundingClientRect().width);+ observer.observe(grid);+ return () => observer.disconnect();+ }, [hasProfilePosts]);const shouldShowPostLoadingIndicator =isPostsLoading && (showPostLoadingIndicator ?? true);const isCoverImageLoading = Boolean(@@ -687,6 +666,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({const masonrySections = buildPostMasonrySections(visiblePostItems,loadedPhotoDimensionsByID,+ postGridWidth,);const closeFriendActions = () => setFriendActionsAnchor(null);@@ -1103,6 +1083,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({const renderPostTile = ({ aspectRatio, dimensions, index, item }: PostMasonryTile,isSingleItemRow: boolean,+ rowAspectRatio: number,) => {const imageUrl = loadedPostImageURLFor(item);const isLatestPost = index == 0 && !isPublicProfile;@@ -1110,7 +1091,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({const tile = (<ProfilePostTilekey={`${item.id}-${index}`}- aspectRatio={aspectRatio}+ flexGrow={aspectRatio / rowAspectRatio}dimensions={isLatestPost? {@@ -1902,6 +1883,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({>{hasProfilePosts ? (<Box+ ref={postGridRef}sx={{display: "flex",flexDirection: "column",@@ -1948,10 +1930,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({<Boxkey={row.tiles[0]!.item.id}sx={{- aspectRatio:- isSingleItemRow- ? undefined- : `${row.aspectRatio} / 1`,display: "flex",gap: photoMasonryGap,width: "100%",@@ -1961,6 +1939,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({renderPostTile(tile,isSingleItemRow,+ row.aspectRatio,),)}</Box>diff --git a/web/apps/space/src/utils/profile-photo-layout.ts b/web/apps/space/src/utils/profile-photo-layout.tsnew file mode 100644index 0000000000..1949b444f2--- /dev/null+++ b/web/apps/space/src/utils/profile-photo-layout.ts@@ -0,0 +1,41 @@+export const profilePhotoGap = 3;+export const profilePhotoMinRowHeight = 100;++export const profilePhotoRows = <Tile extends { aspectRatio: number }>(+ tiles: Tile[],+ width: number,+) => {+ const rows: { aspectRatio: number; tiles: Tile[] }[] = [];+ let nextTileIndex = 0;++ while (nextTileIndex < tiles.length) {+ const remainingTiles = tiles.length - nextTileIndex;+ let rowSize =+ remainingTiles <= 3+ ? remainingTiles+ : remainingTiles == 4 || remainingTiles == 5+ ? 2+ : remainingTiles % 2 == 0+ ? 2+ : 3;+ const rowTiles = tiles.slice(nextTileIndex, nextTileIndex + rowSize);+ let aspectRatio = rowTiles.reduce(+ (sum, tile) => sum + tile.aspectRatio,+ 0,+ );++ while (+ rowSize > 1 &&+ (width - (rowSize - 1) * profilePhotoGap) / aspectRatio <+ profilePhotoMinRowHeight+ ) {+ aspectRatio -= rowTiles.pop()!.aspectRatio;+ rowSize--;+ }++ rows.push({ aspectRatio, tiles: rowTiles });+ nextTileIndex += rowSize;+ }++ return rows;+};diff --git a/web/apps/space/tests/profile-photo-layout.test.ts b/web/apps/space/tests/profile-photo-layout.test.tsnew file mode 100644index 0000000000..56184ed281--- /dev/null+++ b/web/apps/space/tests/profile-photo-layout.test.ts@@ -0,0 +1,73 @@+import { expect, test } from "vitest";+import {+ profilePhotoGap,+ profilePhotoMinRowHeight,+ profilePhotoRows,+} from "../src/utils/profile-photo-layout";++const photos = (ratios: number[]) =>+ ratios.map((aspectRatio, id) => ({ id, aspectRatio }));++test("short landscape rows split without changing photo dimensions", () => {+ const tiles = photos([4 / 3, 5 / 4, 7 / 4]);+ const rows = profilePhotoRows(tiles, 328);+ expect(rows.map(({ tiles }) => tiles.length)).toEqual([2, 1]);+ expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);+});++test("portrait photos can still share a three-photo row", () => {+ expect(+ profilePhotoRows(photos([2 / 3, 3 / 4, 2 / 3]), 328).map(+ ({ tiles }) => tiles.length,+ ),+ ).toEqual([3]);+});++test("row grouping adapts to the available width and accounts for gaps", () => {+ const tiles = photos([1.5, 1.5, 1.5]);+ expect(+ profilePhotoRows(tiles, 302).map(({ tiles }) => tiles.length),+ ).toEqual([1, 1, 1]);+ expect(+ profilePhotoRows(tiles, 303).map(({ tiles }) => tiles.length),+ ).toEqual([2, 1]);+ expect(+ profilePhotoRows(tiles, 456).map(({ tiles }) => tiles.length),+ ).toEqual([3]);+});++test("a panorama keeps its aspect ratio even when it cannot reach the minimum", () => {+ const tiles = photos([8, 1, 1]);+ const rows = profilePhotoRows(tiles, 328);+ expect(rows.map(({ tiles }) => tiles.length)).toEqual([1, 2]);+ expect(rows[0]!.aspectRatio).toBe(8);+});++test.each([288, 328, 358, 568])(+ "rows preserve order, fill a %ipx grid, and meet the minimum when possible",+ (width) => {+ const tiles = photos([1.5, 1.2, 1.8, 0.75, 0.6, 8, 0.05, 1, 2, 1.5]);+ const rows = profilePhotoRows(tiles, width);+ expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);+ for (const row of rows) {+ const gaps = (row.tiles.length - 1) * profilePhotoGap;+ const height = (width - gaps) / row.aspectRatio;+ expect(+ row.tiles.reduce(+ (sum, tile) => sum + tile.aspectRatio * height,+ gaps,+ ),+ ).toBeCloseTo(width);+ expect(height).toBeGreaterThanOrEqual(+ Math.min(+ profilePhotoMinRowHeight,+ width / row.tiles[0]!.aspectRatio,+ ),+ );+ }+ },+);++test("an empty grid has no rows", () => {+ expect(profilePhotoRows([], 328)).toEqual([]);+});