Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine Space masonry grids and post viewer

Anand Baburajan150f9f8645db
diff --git a/web/apps/space/src/components/ActionToast.tsx b/web/apps/space/src/components/ActionToast.tsx
index f565cadc38..9c28936d1b 100644
--- a/web/apps/space/src/components/ActionToast.tsx
+++ b/web/apps/space/src/components/ActionToast.tsx
@@ -3,12 +3,12 @@ import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
import { keyframes } from "@mui/material/styles";
import React from "react";
-import { spaceDialogBackground, spaceText } from "styles/colors";
+import { spaceHomeSurface, spaceText } from "styles/colors";
import { spaceTouchTargetSize } from "styles/touch-targets";
const green = "#08C225";
const textBase = spaceText;
-const toastHorizontalPadding = "16px";
+const toastHorizontalPadding = "8px";
export const spaceToastAutoDismissDurationMs = 1800;
const toastEnter = keyframes`
from {
@@ -78,7 +78,7 @@ export const SpaceActionToast: React.FC<SpaceActionToastProps> = ({
aria-live="polite"
sx={{
alignItems: "center",
- bgcolor: spaceDialogBackground,
+ bgcolor: spaceHomeSurface,
borderRadius: "22px",
boxShadow: "0 12px 32px rgba(0, 0, 0, 0.18)",
boxSizing: "border-box",
diff --git a/web/apps/space/src/components/FileViewer.tsx b/web/apps/space/src/components/FileViewer.tsx
index a3377f8304..4fe9ff04d1 100644
--- a/web/apps/space/src/components/FileViewer.tsx
+++ b/web/apps/space/src/components/FileViewer.tsx
@@ -21,7 +21,6 @@ import { SpaceAvatarImage } from "components/AvatarImage";
import { SpaceCaptionText } from "components/CaptionText";
import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";
import { spacePostLikePopDurationMs } from "components/post-like-animation";
-import { SpacePostPhotosCounter } from "components/PostPhotosCounter";
import { SpacePostPhotosDots } from "components/PostPhotosDots";
import { SpacePostReplyControls } from "components/PostReplyControls";
import { createSpaceVideoContent } from "components/PostVideoContent";
@@ -55,7 +54,6 @@ const textTertiary = "rgba(244, 244, 244, 0.52)";
const viewerBackground = "#000000";
const inputBackground = spaceControlBackground;
const inputBackgroundActive = spaceControlBackgroundHover;
-const controlIcon = spaceText;
const dangerColor = "#F63A3A";
const viewerHeaderHeight = 56;
const viewerBottomPadding = 88;
@@ -68,7 +66,7 @@ const viewerActionDoneDurationMs = 1000;
const captionInputMaxHeight = 112;
const defaultPhotoWidth = 900;
const defaultPhotoHeight = 680;
-const viewerHeaderAvatarSize = 28;
+const viewerHeaderAvatarSize = 32;
const draftPostExitDurationMs = 320;
const keyboardInsetThresholdPx = 80;
const keyboardDismissMaxDurationMs = 500;
@@ -1462,7 +1460,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
minHeight: viewerHeaderHeight,
position: "relative",
pl: "16px",
- pr: isDraftPost ? "8px" : "16px",
+ pr: "8px",
width: "100%",
zIndex: 2,
}}
@@ -1471,7 +1469,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
sx={{
alignItems: "center",
display: "flex",
- gap: "8px",
+ gap: "12px",
minWidth: 0,
}}
>
@@ -1597,7 +1595,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
sx={{
alignItems: "center",
display: "flex",
- gap: "8px",
+ gap: canManagePost && !isCaptionEditing ? 0 : "8px",
justifySelf: "flex-end",
}}
>
@@ -1615,30 +1613,23 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
onClick={(event) =>
setActionsAnchor(event.currentTarget)
}
- sx={{
- alignItems: "center",
- bgcolor: "transparent",
- border: 0,
- color: controlIcon,
- cursor: "pointer",
- display: "flex",
- height: spaceTouchTargetSize,
- justifyContent: "center",
- p: 0,
- width: spaceTouchTargetSize,
- "&:focus-visible": {
- borderRadius: "50%",
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": { color: textBase },
- }}
+ sx={draftHeaderButtonSx}
>
- <HugeiconsIcon
- icon={MoreHorizontalIcon}
- size={26}
- strokeWidth={2}
- />
+ <Box
+ component="span"
+ sx={{
+ ...draftHeaderButtonContentSx,
+ width: 32,
+ p: 0,
+ justifyContent: "center",
+ }}
+ >
+ <HugeiconsIcon
+ icon={MoreHorizontalIcon}
+ size={20}
+ strokeWidth={1.8}
+ />
+ </Box>
</Box>
)}
{isDraftPost && onAddDraftPhoto && (
@@ -1696,12 +1687,6 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
</Box>
</Box>
)}
- {!isDraftPost && (
- <SpacePostPhotosCounter
- index={postPhotoIndex}
- count={postPhotoCount}
- />
- )}
<Box
component="button"
type="button"
@@ -1712,35 +1697,23 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
}
disabled={isDraftPostActionRunning}
onClick={closeViewer}
- sx={
- isDraftPost
- ? draftHeaderButtonSx
- : viewerHeaderButtonSx
- }
+ sx={draftHeaderButtonSx}
>
- {isDraftPost ? (
- <Box
- component="span"
- sx={{
- ...draftHeaderButtonContentSx,
- width: 32,
- p: 0,
- justifyContent: "center",
- }}
- >
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={20}
- strokeWidth={1.8}
- />
- </Box>
- ) : (
+ <Box
+ component="span"
+ sx={{
+ ...draftHeaderButtonContentSx,
+ width: 32,
+ p: 0,
+ justifyContent: "center",
+ }}
+ >
<HugeiconsIcon
icon={Cancel01Icon}
size={20}
strokeWidth={1.8}
/>
- )}
+ </Box>
</Box>
</Box>
{canManagePost && (
diff --git a/web/apps/space/src/components/HomeHeader.tsx b/web/apps/space/src/components/HomeHeader.tsx
index a1e70d3509..a75face9d8 100644
--- a/web/apps/space/src/components/HomeHeader.tsx
+++ b/web/apps/space/src/components/HomeHeader.tsx
@@ -7,6 +7,7 @@ import type { SetupProfile } from "screens/SetupProfileScreen";
import { useSpaceAppState } from "state/app-state";
import {
spaceAppBackgroundColor,
+ spaceHomeSurface,
spaceSurface,
spaceText,
} from "styles/colors";
@@ -25,7 +26,7 @@ const avatarFadeSx = {
"@media (prefers-reduced-motion: reduce)": { animation: "none" },
} as const;
-const spaceHomeHeaderHeight = 64;
+const spaceHomeHeaderHeight = 60;
const spaceHomeHeaderBarHeight = 44;
interface SpaceHomeHeaderProps {
@@ -57,22 +58,21 @@ export const SpaceHomeHeader: React.FC<SpaceHomeHeaderProps> = ({
gridTemplateColumns: `${headerSideWidth}px minmax(0, 1fr) ${headerSideWidth}px`,
height: spaceHomeHeaderHeight,
maxWidth: "100%",
- pb: 2,
position: "relative",
- pt: 1.5,
- px: 2,
+ px: "8px",
+ py: "8px",
width: "100%",
zIndex: 4,
"&::after": {
- bgcolor: spaceSurface,
+ bgcolor: spaceHomeSurface,
borderRadius: "16px",
content: '""',
height: spaceHomeHeaderBarHeight,
- left: "16px",
+ left: "8px",
pointerEvents: "none",
position: "absolute",
- right: "16px",
- top: "12px",
+ right: "8px",
+ top: "8px",
zIndex: 0,
},
"&::before": {
@@ -232,7 +232,7 @@ export const SpaceHomeHeader: React.FC<SpaceHomeHeaderProps> = ({
"&::after": { display: "none" },
},
bgcolor: dangerColor,
- border: `2px solid ${spaceSurface}`,
+ border: `2px solid ${spaceHomeSurface}`,
borderRadius: "50%",
boxSizing: "border-box",
height: 12.5,
diff --git a/web/apps/space/src/components/MobileBestToast.tsx b/web/apps/space/src/components/MobileBestToast.tsx
index 1b873a91f0..1ac1c5641f 100644
--- a/web/apps/space/src/components/MobileBestToast.tsx
+++ b/web/apps/space/src/components/MobileBestToast.tsx
@@ -5,7 +5,7 @@ import {
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
import React from "react";
-import { spaceDialogBackground, spaceText } from "styles/colors";
+import { spaceHomeSurface, spaceText } from "styles/colors";
const green = "#08C225";
const dismissedKey = "spaceMobileBestToastDismissed";
@@ -25,7 +25,7 @@ export const SpaceMobileBestToast: React.FC = () => {
aria-live="polite"
sx={{
alignItems: "center",
- bgcolor: spaceDialogBackground,
+ bgcolor: spaceHomeSurface,
borderRadius: "18px",
boxShadow: "0 12px 32px rgba(0, 0, 0, 0.18)",
boxSizing: "border-box",
diff --git a/web/apps/space/src/components/PWAInstallPrompt.tsx b/web/apps/space/src/components/PWAInstallPrompt.tsx
index 68105fd0da..c60e4aacb9 100644
--- a/web/apps/space/src/components/PWAInstallPrompt.tsx
+++ b/web/apps/space/src/components/PWAInstallPrompt.tsx
@@ -18,7 +18,7 @@ import { useSpaceWebPushPrompt } from "hooks/use-web-push-prompt";
import React from "react";
import { spaceToastActionButtonSx } from "styles/buttons";
import {
- spaceDialogBackground,
+ spaceHomeSurface,
spaceOnAccent,
spaceSurface,
spaceText,
@@ -208,7 +208,7 @@ export const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({
: undefined,
boxSizing: "border-box",
left: "50%",
- px: "16px",
+ px: "8px",
pointerEvents: "none",
position: "fixed",
top:
@@ -232,7 +232,7 @@ export const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({
aria-live="polite"
sx={{
alignItems: "center",
- bgcolor: spaceDialogBackground,
+ bgcolor: spaceHomeSurface,
borderRadius: "22px",
boxShadow: "0 12px 32px rgba(0, 0, 0, 0.18)",
color: textBase,
diff --git a/web/apps/space/src/components/PostGrid.tsx b/web/apps/space/src/components/PostGrid.tsx
index 695e8ce535..c06f871c72 100644
--- a/web/apps/space/src/components/PostGrid.tsx
+++ b/web/apps/space/src/components/PostGrid.tsx
@@ -1,13 +1,14 @@
import { Box } from "@mui/material";
import React from "react";
-import { spacePostFrameAspectRatio } from "utils/post-photos";
-import { postPhotoLayout, profilePhotoGap } from "utils/profile-photo-layout";
+import { minimumPostPhotoFrameAspectRatio } from "styles/tiles";
+
+const gap = 8;
interface PostGridItem {
id: string;
+ frameAspectRatio?: number;
width?: number;
height?: number;
- frameAspectRatio?: number;
}
export const SpacePostGrid = <Item extends PostGridItem>({
@@ -17,19 +18,12 @@ export const SpacePostGrid = <Item extends PostGridItem>({
}: {
items: Item[];
postCount?: number;
- renderTile: (
- item: Item,
- index: number,
- flexGrow: number,
- ) => React.ReactNode;
+ renderTile: (item: Item, index: number) => React.ReactNode;
}) => {
const [width, setWidth] = React.useState(0);
- const [previousLayout, setLayout] = React.useState(() => ({
- ...postPhotoLayout([], 0),
- items,
- postCount,
- }));
+ const [fullWidth, setFullWidth] = React.useState<boolean>();
const gridRef = React.useRef<HTMLDivElement | null>(null);
+
React.useLayoutEffect(() => {
const grid = gridRef.current!;
const observer = new ResizeObserver(([entry]) =>
@@ -40,62 +34,63 @@ export const SpacePostGrid = <Item extends PostGridItem>({
return () => observer.disconnect();
}, []);
- const layout =
- previousLayout.items == items &&
- previousLayout.width == width &&
- previousLayout.postCount == postCount
- ? previousLayout
- : {
- ...postPhotoLayout(
- items.map((item) => ({
- id: item.id,
- aspectRatio:
- item.frameAspectRatio ??
- spacePostFrameAspectRatio([item]),
- })),
- width,
- previousLayout,
- postCount,
- ),
- items,
- postCount,
- };
- if (layout != previousLayout) setLayout(layout);
+ if (fullWidth == undefined && width > 0 && items.length > 0)
+ setFullWidth(
+ postCount != undefined && Math.max(postCount, items.length) < 4,
+ );
- const itemsByID = new Map(
- items.map((item, index) => [item.id, { item, index }]),
- );
+ const columnCount = fullWidth ? 1 : 2;
+ const columnWidth = (width - (columnCount - 1) * gap) / columnCount;
+ const columnHeights = new Array<number>(columnCount).fill(0);
+ const tiles =
+ width > gap
+ ? items.map((item, index) => {
+ const column =
+ fullWidth || columnHeights[0]! <= columnHeights[1]!
+ ? 0
+ : 1;
+ const top = columnHeights[column]!;
+ const photoAspectRatio =
+ item.frameAspectRatio ??
+ (item.width && item.height
+ ? item.width / item.height
+ : 1);
+ const aspectRatio = fullWidth
+ ? Math.max(
+ minimumPostPhotoFrameAspectRatio,
+ photoAspectRatio,
+ )
+ : photoAspectRatio;
+ const height = columnWidth / aspectRatio;
+ columnHeights[column] = top + height + gap;
+ return (
+ <Box
+ key={item.id}
+ sx={{
+ height,
+ left: column * (columnWidth + gap),
+ position: "absolute",
+ top,
+ width: columnWidth,
+ }}
+ >
+ {renderTile(item, index)}
+ </Box>
+ );
+ })
+ : [];
return (
<Box
ref={gridRef}
sx={{
- display: "flex",
- flexDirection: "column",
- gap: `${profilePhotoGap}px`,
+ height:
+ Math.max(0, ...columnHeights) - (tiles.length ? gap : 0),
+ position: "relative",
+ width: "100%",
}}
>
- {layout.rows.map((row) => (
- <Box
- key={row.tiles[0]!.id}
- sx={{
- display: "flex",
- flexShrink: 0,
- gap: `${profilePhotoGap}px`,
- height: row.height,
- width: row.width,
- }}
- >
- {row.tiles.map(({ id, aspectRatio }) => {
- const { item, index } = itemsByID.get(id)!;
- return renderTile(
- item,
- index,
- aspectRatio / row.aspectRatio,
- );
- })}
- </Box>
- ))}
+ {tiles}
</Box>
);
};
diff --git a/web/apps/space/src/components/PostTile.tsx b/web/apps/space/src/components/PostTile.tsx
index 2a5233449b..0a64e982e0 100644
--- a/web/apps/space/src/components/PostTile.tsx
+++ b/web/apps/space/src/components/PostTile.tsx
@@ -39,7 +39,6 @@ interface SpacePostTileProps {
showAvatar?: boolean;
subtlePhotosBadge?: boolean;
onLoadAvatar?: () => Promise<string | null>;
- flexGrow: number;
imageUrl?: string;
index: number;
isAvatarPending?: boolean;
@@ -58,7 +57,6 @@ export const SpacePostTile: React.FC<SpacePostTileProps> = ({
showAvatar = false,
subtlePhotosBadge,
onLoadAvatar,
- flexGrow,
imageUrl,
index,
isAvatarPending = false,
@@ -134,7 +132,6 @@ export const SpacePostTile: React.FC<SpacePostTileProps> = ({
sx={{
bgcolor: spaceSurface,
borderRadius: `${spaceProfilePostRadius}px`,
- flex: `${flexGrow} 1 0px`,
height: "100%",
minWidth: 0,
overflow: "hidden",
@@ -160,7 +157,7 @@ export const SpacePostTile: React.FC<SpacePostTileProps> = ({
appearance: "none",
bgcolor: spaceSurface,
border: 0,
- borderRadius: `${spaceProfilePostRadius}px`,
+ borderRadius: "inherit",
cursor: imageUrl && !isUnavailable ? "pointer" : "default",
display: "block",
height: "100%",
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 5e5041af62..9f08c31d34 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -58,7 +58,7 @@ import {
spaceAppBackgroundColor,
spaceControlBackground,
spaceControlBackgroundHover,
- spaceSurface,
+ spaceHomeSurface,
spaceSurfaceHover,
spaceText,
spaceTextMuted,
@@ -78,7 +78,8 @@ const homeBackground = spaceAppBackgroundColor;
const green = "#08C225";
const feedAccentBackground = "#263D2C";
const feedAccentBackgroundHover = "#2C4B32";
-const feedActionBackground = spaceControlBackground;
+const feedActionBackground = spaceControlBackgroundHover;
+const feedActionBackgroundHover = "#3A3A3A";
const feedActionForeground = spaceText;
const feedTimestampForeground = "#D9D9D9";
const feedSkeletonElementBackground = spaceSurfaceHover;
@@ -88,7 +89,7 @@ const dangerColor = "#F63A3A";
const feedAvatarSize = 38;
const feedLikeActionSize = spaceTouchTargetSize;
const feedActionIconSize = 20;
-const feedHorizontalPadding = "16px";
+const feedHorizontalPadding = "8px";
const feedMediaLoadRootMargin = "640px 0px";
const feedLoadMoreRootMargin = "0px 0px 800px 0px";
const feedRowEnterDurationMs = 460;
@@ -382,7 +383,7 @@ class FeedMotionList extends React.Component<FeedMotionListProps> {
sx={{
boxSizing: "border-box",
minWidth: 0,
- pb: "24px",
+ pb: "8px",
position: "relative",
width: "100%",
}}
@@ -560,7 +561,7 @@ const FeedLikeButton: React.FC<FeedLikeButtonProps> = ({
"&:hover": {
bgcolor: isLiked
? feedAccentBackgroundHover
- : spaceControlBackgroundHover,
+ : feedActionBackgroundHover,
},
"@media (prefers-reduced-motion: reduce)": {
animation: "none",
@@ -1170,7 +1171,7 @@ const FeedItem: React.FC<FeedItemProps> = ({
component="article"
sx={{
WebkitTapHighlightColor: "transparent",
- bgcolor: showFooter ? spaceSurface : "transparent",
+ bgcolor: showFooter ? spaceHomeSurface : "transparent",
borderRadius: "16px",
boxSizing: "border-box",
display: "flex",
@@ -1481,6 +1482,7 @@ const FeedItem: React.FC<FeedItemProps> = ({
}}
>
<SpacePostAvatar
+ outerRing
ready={isAvatarReady}
size={feedAvatarSize}
src={displayAvatarUrl}
@@ -1697,7 +1699,7 @@ const FeedItem: React.FC<FeedItemProps> = ({
outlineOffset: 2,
},
"&:not(:disabled):hover": {
- bgcolor: spaceControlBackgroundHover,
+ bgcolor: feedActionBackgroundHover,
color: textBase,
},
}}
@@ -1738,7 +1740,7 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({
aria-live="polite"
sx={{
alignItems: "center",
- bgcolor: spaceSurface,
+ bgcolor: spaceHomeSurface,
borderRadius: "22px",
boxShadow: "0 12px 32px rgba(0, 0, 0, 0.18)",
boxSizing: "border-box",
@@ -2283,11 +2285,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
flexDirection: "column",
gap: 0,
justifyContent: showFeedCards ? "flex-start" : "center",
- minHeight: "calc(100svh - 64px)",
+ minHeight: "calc(100svh - 60px)",
minWidth: 0,
pb: "calc(env(safe-area-inset-bottom) + 112px)",
px: feedHorizontalPadding,
- pt: showFeedCards ? "16px" : "8px",
+ pt: showFeedCards ? 0 : "8px",
width: "100%",
}}
>
@@ -2323,10 +2325,12 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
...item,
id: String(item.postId),
frameAspectRatio:
- spacePostFrameAspectRatio([photo]),
+ photo.width && photo.height
+ ? photo.width / photo.height
+ : 1,
};
})}
- renderTile={(item, index, flexGrow) => {
+ renderTile={(item, index) => {
const photo = {
...spacePostPhotos(item)[0]!,
postId: item.postId,
@@ -2352,7 +2356,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
displayName={item.name}
showAvatar
subtlePhotosBadge
- flexGrow={flexGrow}
index={index}
imageUrl={imageUrl}
isAvatarPending={
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 5b683842d1..bf7773d2b3 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -549,17 +549,12 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
});
};
- const renderPostTile = (
- item: ProfilePostItem,
- index: number,
- flexGrow: number,
- ) => {
+ const renderPostTile = (item: ProfilePostItem, index: number) => {
const imageUrl = loadedPostImageURLFor(item);
const isUnavailable = !viewerPostIndexByID.has(item.id);
return (
<SpacePostTile
key={item.id}
- flexGrow={flexGrow}
displayName={displayName}
imageUrl={imageUrl}
index={index}
@@ -610,7 +605,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
: undefined,
mx: "auto",
position: "relative",
- px: 2,
+ px: "8px",
py: 0,
width: "100%",
zIndex: 3,
@@ -919,7 +914,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
alignItems: "center",
display: "flex",
flexDirection: "column",
- px: "16px",
+ px: "8px",
position: "relative",
pt: `${profileAvatarTopOffset}px`,
textAlign: "center",
@@ -1341,8 +1336,8 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
flexDirection: "column",
gap: "24px",
mt: "6px",
- mx: "16px",
- width: "calc(100% - 32px)",
+ mx: "8px",
+ width: "calc(100% - 16px)",
}}
>
<SpacePostGrid
diff --git a/web/apps/space/src/styles/colors.ts b/web/apps/space/src/styles/colors.ts
index 8fa4fa6fce..74b37b78b9 100644
--- a/web/apps/space/src/styles/colors.ts
+++ b/web/apps/space/src/styles/colors.ts
@@ -4,6 +4,7 @@ export const spaceAppBackground = spaceAppBackgroundColor;
export const spaceDialogBackground = "#242424";
export const spaceSurface = "#1A1A1A";
+export const spaceHomeSurface = "#202020";
export const spaceSurfaceHover = "#262626";
export const spaceControlBackground = "#242424";
export const spaceControlBackgroundHover = "#303030";
diff --git a/web/apps/space/src/styles/tiles.ts b/web/apps/space/src/styles/tiles.ts
index c361f1f603..c4c9d868cd 100644
--- a/web/apps/space/src/styles/tiles.ts
+++ b/web/apps/space/src/styles/tiles.ts
@@ -1,2 +1,2 @@
export const minimumPostPhotoFrameAspectRatio = 3 / 4;
-export const spaceProfilePostRadius = 16;
+export const spaceProfilePostRadius = 24;
diff --git a/web/apps/space/src/utils/profile-photo-layout.ts b/web/apps/space/src/utils/profile-photo-layout.ts
deleted file mode 100644
index 85b647d9c2..0000000000
--- a/web/apps/space/src/utils/profile-photo-layout.ts
+++ /dev/null
@@ -1,119 +0,0 @@
-import { minimumPostPhotoFrameAspectRatio } from "../styles/tiles";
-
-export const profilePhotoGap = 6;
-const profilePhotoMinRowHeight = 100;
-
-interface PhotoRow<Tile> {
- aspectRatio: number;
- height: number;
- width: number;
- tiles: Tile[];
-}
-
-interface PostPhotoTile {
- id: string;
- aspectRatio: number;
-}
-
-interface PostPhotoLayout {
- width: number;
- fullWidth?: boolean;
- rows: PhotoRow<PostPhotoTile>[];
-}
-
-export const postPhotoLayout = (
- tiles: PostPhotoTile[],
- width: number,
- previous?: PostPhotoLayout,
- postCount?: number,
-): PostPhotoLayout => {
- const fullWidth =
- previous?.fullWidth ??
- (width > 0 && tiles.length > 0
- ? postCount != undefined && Math.max(postCount, tiles.length) <= 7
- : undefined);
- const rows: PhotoRow<PostPhotoTile>[] = [];
- let retainedCount = 0;
- if (previous?.width == width) {
- for (const row of previous.rows) {
- if (
- !row.tiles.every(
- (tile, index) =>
- tiles[retainedCount + index]?.id == tile.id,
- )
- )
- break;
- rows.push(row);
- retainedCount += row.tiles.length;
- }
- }
- const remaining = tiles.slice(retainedCount);
- rows.push(
- ...(fullWidth
- ? remaining.flatMap((tile) => profilePhotoRows([tile], width))
- : profilePhotoRows(remaining, width)),
- );
- return { width, fullWidth, rows };
-};
-
-const profilePhotoRows = <Tile extends { aspectRatio: number }>(
- tiles: Tile[],
- width: number,
-) => {
- const rows: PhotoRow<Tile>[] = [];
- if (width <= 0) return rows;
-
- const targetRowHeight = width / 2;
- const costs = new Array<number>(tiles.length + 1).fill(Infinity);
- const rowSizes = new Array<number>(tiles.length);
- costs[tiles.length] = 0;
-
- for (let index = tiles.length - 1; index >= 0; index--) {
- let aspectRatio = 0;
- for (
- let rowSize = 1;
- rowSize <= 3 && index + rowSize <= tiles.length;
- rowSize++
- ) {
- aspectRatio += tiles[index + rowSize - 1]!.aspectRatio;
- const height =
- (width - (rowSize - 1) * profilePhotoGap) / aspectRatio;
- if (rowSize > 1 && height < profilePhotoMinRowHeight) continue;
-
- const cost =
- (height / targetRowHeight - 1) ** 2 + costs[index + rowSize]!;
- if (cost <= costs[index]!) {
- costs[index] = cost;
- rowSizes[index] = rowSize;
- }
- }
- }
-
- for (let index = 0; index < tiles.length; ) {
- const rowSize = rowSizes[index]!;
- const rowTiles = tiles.slice(index, index + rowSize);
- const aspectRatio = rowTiles.reduce(
- (sum, tile) => sum + tile.aspectRatio,
- 0,
- );
- const gaps = (rowSize - 1) * profilePhotoGap;
- let height = (width - gaps) / aspectRatio;
- if (rowSize == 1)
- height = Math.min(
- height,
- tiles.length == 1
- ? width / minimumPostPhotoFrameAspectRatio
- : width * 0.75,
- );
- rows.push({
- aspectRatio,
- height,
- width:
- rowSize > 1 || tiles.length == 1 ? width : height * aspectRatio,
- tiles: rowTiles,
- });
- index += rowSize;
- }
-
- return rows;
-};
diff --git a/web/apps/space/tests/profile-photo-layout.test.ts b/web/apps/space/tests/profile-photo-layout.test.ts
deleted file mode 100644
index 8ef3c89e0e..0000000000
--- a/web/apps/space/tests/profile-photo-layout.test.ts
+++ /dev/null
@@ -1,289 +0,0 @@
-import { expect, test } from "vitest";
-import {
- postPhotoLayout,
- profilePhotoGap,
-} from "../src/utils/profile-photo-layout";
-
-const photos = (ratios: number[]) =>
- ratios.map((aspectRatio, id) => ({ id: String(id), aspectRatio }));
-
-test.each([
- { count: 2, rowSizes: [2] },
- { count: 3, rowSizes: [3] },
- { count: 4, rowSizes: [2, 2] },
-])("the adaptive grid fits $count photos into rows", ({ count, rowSizes }) => {
- const tiles = photos(new Array<number>(count).fill(2 / 3));
- const rows = postPhotoLayout(tiles, 352).rows;
- expect(rows.map(({ tiles }) => tiles.length)).toEqual(rowSizes);
- expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);
-});
-
-test("the adaptive grid arranges five landscape photos", () => {
- const tiles = photos([3 / 2, 3 / 2, 3 / 2, 3 / 2, 3 / 2]);
- const rows = postPhotoLayout(tiles, 352).rows;
- expect(rows.map(({ tiles }) => tiles.map(({ id }) => id))).toEqual([
- ["0", "1"],
- ["2", "3"],
- ["4"],
- ]);
-});
-
-test("three portraits share a compact row", () => {
- expect(
- postPhotoLayout(
- photos([2 / 3, 3 / 4, 2 / 3, 2 / 3, 3 / 4, 2 / 3]),
- 328,
- ).rows.map(({ tiles }) => tiles.length),
- ).toEqual([3, 3]);
-});
-
-test.each([
- { ratios: [3 / 4, 0.45], count: 2 },
- { ratios: [0.3, 0.4, 0.5], count: 3 },
-])(
- "a row of $count tall portraits fills the grid without cropping",
- ({ ratios }) => {
- const width = 328;
- const rows = postPhotoLayout(photos(ratios), width).rows;
- expect(rows).toHaveLength(1);
- const row = rows[0]!;
- expect(row.width).toBe(width);
- expect(row.height).toBeGreaterThan(width * 0.75);
- expect(
- row.tiles.reduce(
- (sum, tile) => sum + tile.aspectRatio * row.height,
- 0,
- ) +
- (row.tiles.length - 1) * profilePhotoGap,
- ).toBeCloseTo(width);
- },
-);
-
-test("a lone portrait within a larger grid keeps its height limit", () => {
- const rows = postPhotoLayout(photos([8, 0.25]), 328).rows;
- expect(rows.map(({ tiles }) => tiles.length)).toEqual([1, 1]);
- expect(rows[1]!.height).toBe(246);
- expect(rows[1]!.width).toBe(61.5);
-});
-
-test("a landscape can share a row with two portraits to avoid a lone portrait", () => {
- const tiles = photos([3 / 4, 3 / 4, 16 / 9, 3 / 4, 9 / 16]);
- expect(
- postPhotoLayout(tiles, 363).rows.map(({ tiles }) =>
- tiles.map(({ id }) => id),
- ),
- ).toEqual([
- ["0", "1"],
- ["2", "3", "4"],
- ]);
-});
-
-test("a single-post grid fills the width with the feed's portrait height cap", () => {
- const tiles = photos([9 / 16]);
- expect(postPhotoLayout(tiles, 324).rows).toEqual([
- { aspectRatio: 9 / 16, height: 432, width: 324, tiles },
- ]);
-});
-
-test("similar landscapes are not forced into full-width rows", () => {
- const tiles = photos(new Array<number>(10).fill(3 / 2));
- const rows = postPhotoLayout(tiles, 358).rows;
- expect(rows.map(({ tiles }) => tiles.length)).toEqual([2, 2, 2, 2, 2]);
- expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);
-});
-
-test("wider photos stand alone when that fits better than a short paired row", () => {
- const tiles = photos([3 / 2, 3 / 2, 5 / 3, 5 / 3, 3 / 2, 3 / 2]);
- const rows = postPhotoLayout(tiles, 358).rows;
- expect(rows.map(({ tiles }) => tiles.length)).toEqual([2, 1, 1, 2]);
- expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);
-});
-
-test("row grouping adapts to the available width and accounts for gaps", () => {
- const tiles = photos([1.5, 1.5, 1.5, 1.5, 1.5, 1.5]);
- expect(
- postPhotoLayout(tiles, 299 + profilePhotoGap).rows.map(
- ({ tiles }) => tiles.length,
- ),
- ).toEqual([1, 1, 1, 1, 1, 1]);
- expect(
- postPhotoLayout(tiles, 300 + profilePhotoGap).rows.map(
- ({ tiles }) => tiles.length,
- ),
- ).toEqual([2, 2, 2]);
- expect(
- postPhotoLayout(tiles, 456).rows.map(({ tiles }) => tiles.length),
- ).toEqual([2, 2, 2]);
-});
-
-test("a panorama keeps its aspect ratio even when it cannot reach the minimum", () => {
- const tiles = photos([8, 1, 1, 1, 1]);
- const rows = postPhotoLayout(tiles, 328).rows;
- expect(rows.map(({ tiles }) => tiles.length)).toEqual([1, 2, 2]);
- expect(rows[0]!.aspectRatio).toBe(8);
-});
-
-test.each([288, 328, 358, 568])(
- "rows preserve order, fit 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 = postPhotoLayout(tiles, width).rows;
- expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);
- for (const row of rows) {
- expect(row.tiles.length).toBeLessThanOrEqual(3);
- const gaps = (row.tiles.length - 1) * profilePhotoGap;
- expect(
- row.tiles.reduce(
- (sum, tile) => sum + tile.aspectRatio * row.height,
- gaps,
- ),
- ).toBeCloseTo(row.width);
- expect(row.width).toBeLessThanOrEqual(width + 0.001);
- if (row.tiles.length > 1) expect(row.width).toBe(width);
- else expect(row.height).toBeLessThanOrEqual(width * 0.75);
- expect(row.height).toBeGreaterThanOrEqual(
- Math.min(100, width / row.tiles[0]!.aspectRatio),
- );
- }
- },
-);
-
-test("an empty grid has no rows", () => {
- expect(postPhotoLayout([], 328).rows).toEqual([]);
-});
-
-test("the grid waits for its width to be measured", () => {
- expect(postPhotoLayout(photos([3 / 4, 3 / 2]), 0).rows).toEqual([]);
-});
-
-test.each([1, 2, 3, 4, 5, 6, 7])(
- "a complete collection of %i posts gives each photo its own full-width row",
- (count) => {
- const tiles = photos([16 / 9, 3 / 4, 1, 9 / 16, 2, 0.3, 1.5]).slice(
- 0,
- count,
- );
- const layout = postPhotoLayout(tiles, 324, undefined, count);
- expect(layout.fullWidth).toBe(true);
- expect(layout.rows).toHaveLength(count);
- expect(layout.rows.flatMap((row) => row.tiles)).toEqual(tiles);
- layout.rows.forEach((row) => {
- expect(row.width).toBe(324);
- expect(row.height).toBeCloseTo(
- Math.min(324 / row.tiles[0]!.aspectRatio, 432),
- );
- });
- },
-);
-
-test("eight posts use the adaptive grid", () => {
- const tiles = photos(new Array<number>(8).fill(1));
- const layout = postPhotoLayout(tiles, 352, undefined, 8);
- expect(layout.fullWidth).toBe(false);
- expect(layout.rows).toEqual(postPhotoLayout(tiles, 352).rows);
-});
-
-test.each([undefined, 8])(
- "two loaded photos do not imply a small collection when the total is %s",
- (postCount) => {
- const tiles = photos([16 / 9, 3 / 4]);
- const layout = postPhotoLayout(tiles, 352, undefined, postCount);
- expect(layout.fullWidth).toBe(false);
- expect(layout.rows).toHaveLength(1);
- },
-);
-
-test("the layout decision waits for photos and a measured width", () => {
- const tiles = photos([16 / 9, 3 / 4]);
- const empty = postPhotoLayout([], 352, undefined, 0);
- expect(empty.fullWidth).toBeUndefined();
- const unmeasured = postPhotoLayout(tiles, 0, empty, 2);
- expect(unmeasured.fullWidth).toBeUndefined();
- expect(postPhotoLayout(tiles, 352, unmeasured, 2).fullWidth).toBe(true);
-});
-
-test("crossing seven posts keeps the chosen layout until the next opening", () => {
- const tiles = photos(new Array<number>(8).fill(1));
- const initial = postPhotoLayout(tiles.slice(0, 7), 352, undefined, 7);
- const appended = postPhotoLayout(tiles, 352, initial, 8);
- expect(appended.fullWidth).toBe(true);
- expect(appended.rows.slice(0, 7)).toEqual(initial.rows);
- expect(appended.rows.every((row) => row.tiles.length == 1)).toBe(true);
-
- const reopened = postPhotoLayout(tiles, 352, undefined, 8);
- expect(reopened.fullWidth).toBe(false);
- const afterDeletion = postPhotoLayout(tiles.slice(0, 7), 352, reopened, 7);
- expect(afterDeletion.fullWidth).toBe(false);
-});
-
-test("resizing retains the full-width layout for a small collection", () => {
- const tiles = photos([16 / 9, 3 / 4]);
- const initial = postPhotoLayout(tiles, 352, undefined, 2);
- const resized = postPhotoLayout(tiles, 600, initial, 2);
- expect(resized.fullWidth).toBe(true);
- expect(resized.rows).toHaveLength(2);
- expect(resized.rows.every((row) => row.width == 600)).toBe(true);
-});
-
-test.each([1, 3, 10])(
- "appending pages preserves every row from the initial %i photos",
- (initialCount) => {
- const tiles = photos(
- Array.from(
- { length: 40 },
- (_, index) => [3 / 4, 3 / 2, 9 / 16, 1, 8][index % 5]!,
- ),
- );
- let layout = postPhotoLayout(tiles.slice(0, initialCount), 352);
- for (let count = initialCount + 10; count < 50; count += 10) {
- const loadedTiles = tiles.slice(0, count);
- const next = postPhotoLayout(loadedTiles, 352, layout);
- expect(next.rows.slice(0, layout.rows.length)).toEqual(layout.rows);
- expect(next.rows.flatMap((row) => row.tiles)).toEqual(loadedTiles);
- layout = next;
- }
- },
-);
-
-test("late dimensions do not resize existing rows or their tiles", () => {
- const tiles = photos([1, 1, 1]);
- const initial = postPhotoLayout(tiles, 352);
- const updated = tiles.map((tile) => ({ ...tile, aspectRatio: 9 / 16 }));
- const next = postPhotoLayout(
- [...updated, { id: "older", aspectRatio: 3 / 2 }],
- 352,
- initial,
- );
- expect(next.rows.slice(0, initial.rows.length)).toEqual(initial.rows);
- expect(next.rows.at(-1)!.tiles).toEqual([
- { id: "older", aspectRatio: 3 / 2 },
- ]);
-});
-
-test("deleting a photo retains preceding rows and removes the deleted tile", () => {
- const tiles = photos([1, 1, 1, 1, 1, 1]);
- const initial = postPhotoLayout(tiles, 352);
- const remaining = tiles.filter((tile) => tile.id != "3");
- const next = postPhotoLayout(remaining, 352, initial);
- expect(next.rows[0]).toEqual(initial.rows[0]);
- expect(next.rows.flatMap((row) => row.tiles)).toEqual(remaining);
-});
-
-test("a replaced or reordered list uses the current photo order", () => {
- const tiles = photos([3 / 4, 3 / 2, 1, 9 / 16]);
- const initial = postPhotoLayout(tiles, 352);
- const reordered = [...tiles].reverse();
- const next = postPhotoLayout(reordered, 352, initial);
- expect(next.rows).toEqual(postPhotoLayout(reordered, 352).rows);
- expect(next.rows.flatMap((row) => row.tiles)).toEqual(reordered);
- expect(postPhotoLayout([], 352, next).rows).toEqual([]);
-});
-
-test("resizing recalculates rows to fit the new width", () => {
- const tiles = photos([3 / 2, 3 / 2, 3 / 2, 3 / 2]);
- const initial = postPhotoLayout(tiles, 352);
- const next = postPhotoLayout(tiles, 600, initial);
- expect(next.width).toBe(600);
- expect(next.rows).toEqual(postPhotoLayout(tiles, 600).rows);
- expect(next.rows).not.toEqual(initial.rows);
-});