π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Group Space profile photos by time
Anand Baburajan5120befb4b64
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex 4798f46e7f..084038cf78 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -19,7 +19,6 @@ import {} from "components/ActionToast";import { SpaceAvatarImage } from "components/AvatarImage";import { SpaceButtonSpinner } from "components/ButtonSpinner";-import { SpaceCaptionText } from "components/CaptionText";import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";import { SpaceFeedPostButton } from "components/FeedPostButton";import {@@ -53,17 +52,16 @@ import {spaceText,spaceTextMuted,} from "styles/colors";-import {- minimumPostPhotoFrameAspectRatio,- spaceProfilePostRadius,-} from "styles/tiles";+import { spaceProfilePostRadius } from "styles/tiles";import { spaceTouchTargetSize } from "styles/touch-targets";-import { firstNameFrom, formatSpaceDate } from "utils/display";+import { firstNameFrom } from "utils/display";import {spaceDefaultCoverImagePath,type SpaceDraftPostImage,} from "utils/post-image";import { viewerPhotosFromPost } from "utils/post-photos";+import { profilePhotoGap, profilePhotoRows } from "utils/profile-photo-layout";+import { profilePostSections } from "utils/profile-post-sections";import { thumbHashDataURLFromBase64 } from "utils/thumbhash";const green = "#08C225";@@ -117,6 +115,12 @@ interface SelectedProfilePost {photoIndex: number;}+interface ProfilePhotoTile {+ aspectRatio: number;+ index: number;+ item: ProfilePostItem;+}+const profilePostImageCacheKey = (item: ProfilePostItem) =>[item.id, item.imageAsset?.objectKey ?? item.imageUrl ?? ""].join(":");@@ -232,9 +236,9 @@ const ProfilePostLoadingIndicator: React.FC = () => (</Box>);-interface ProfilePostProps {- dimensions: ProfilePhotoDimensions;+interface ProfilePostTileProps {displayName: string;+ flexGrow: number;imageUrl?: string;index: number;isUnavailable: boolean;@@ -246,9 +250,9 @@ interface ProfilePostProps {onRememberDimensions: (itemID: string, image: HTMLImageElement) => void;}-const ProfilePost: React.FC<ProfilePostProps> = ({- dimensions,+const ProfilePostTile: React.FC<ProfilePostTileProps> = ({displayName,+ flexGrow,imageUrl,index,isUnavailable: isPostUnavailable,@@ -262,22 +266,13 @@ const ProfilePost: React.FC<ProfilePostProps> = ({const [shouldLoad, setShouldLoad] = React.useState(Boolean(imageUrl));const [readyImageUrl, setReadyImageUrl] = React.useState<string>();const [imageDecodeFailed, setImageDecodeFailed] = React.useState(false);- const postRef = React.useRef<HTMLElement | null>(null);+ const tileRef = React.useRef<HTMLButtonElement | null>(null);const thumbHashDataURL = React.useMemo(() => thumbHashDataURLFromBase64(item.thumbHash),[item.thumbHash],);const isCurrentImageReady = Boolean(imageUrl && readyImageUrl == imageUrl);const isUnavailable = isPostUnavailable || imageDecodeFailed;- const aspectRatio =- dimensions.width > 0 && dimensions.height > 0- ? dimensions.width / dimensions.height- : 1;- const frameAspectRatio = Math.max(- minimumPostPhotoFrameAspectRatio,- aspectRatio,- );- const caption = item.caption?.trim();const photoCount = item.photos?.length ?? 1;React.useEffect(() => {@@ -287,7 +282,7 @@ const ProfilePost: React.FC<ProfilePostProps> = ({React.useEffect(() => {if (isUnavailable) return;if (shouldLoad || imageUrl) return;- const element = postRef.current;+ const element = tileRef.current;if (!element) return;if (typeof window == "undefined" ||@@ -320,185 +315,113 @@ const ProfilePost: React.FC<ProfilePostProps> = ({return (<Box- ref={postRef}- component="article"+ ref={tileRef}+ component="button"+ type="button"+ aria-label={+ isUnavailable+ ? "Post unavailable"+ : `Open ${displayName} post ${index + 1}${+ photoCount > 1 ? `, ${photoCount} photos` : ""+ }`+ }+ disabled={!imageUrl || isUnavailable}+ onClick={() => {+ if (imageUrl && !isUnavailable) onOpen(imageUrl);+ }}sx={{- aspectRatio: frameAspectRatio,+ appearance: "none",bgcolor: photoPlaceholderBackground,+ border: 0,borderRadius: `${spaceProfilePostRadius}px`,+ cursor: imageUrl && !isUnavailable ? "pointer" : "default",+ display: "block",+ flex: `${flexGrow} 1 0px`,+ height: "100%",minWidth: 0,+ opacity: 1,overflow: "hidden",+ p: 0,position: "relative",- transition: "aspect-ratio 220ms ease",- width: "100%",- "@media (prefers-reduced-motion: reduce)": {- transition: "none",+ "&:focus-visible": {+ outline: `2px solid ${green}`,+ outlineOffset: -2,},}}>- <Box- component="button"- type="button"- aria-label={- isUnavailable- ? "Post unavailable"- : `Open ${displayName} post ${index + 1}${- photoCount > 1 ? `, ${photoCount} photos` : ""- }`- }- disabled={!imageUrl || isUnavailable}- onClick={() => {- if (imageUrl && !isUnavailable) onOpen(imageUrl);- }}- sx={{- appearance: "none",- bgcolor: "transparent",- border: 0,- cursor: imageUrl && !isUnavailable ? "pointer" : "default",- display: "block",- height: "100%",- p: 0,- position: "relative",- width: "100%",- "&:focus-visible": {- outline: `2px solid ${green}`,- outlineOffset: -2,- },- }}- >- {!isUnavailable && thumbHashDataURL ? (- <Box- component="img"- alt=""- aria-hidden- src={thumbHashDataURL}- sx={{- display: "block",- filter: "blur(14px)",- height: "100%",- inset: 0,- objectFit: "cover",- objectPosition: "center",- position: "absolute",- transform: "scale(1.08)",- width: "100%",- }}- />- ) : null}- {!isUnavailable && imageUrl ? (- <Box- component="img"- alt={`${displayName} post ${index + 1}`}- onLoad={(event) => {- setReadyImageUrl(imageUrl);- onRememberDimensions(item.id, event.currentTarget);- }}- onError={() => {- log.warn(- `Post ${item.postId} is unavailable because the browser could not decode its image`,- );- setImageDecodeFailed(true);- onImageDecodeError();- }}- src={imageUrl}- sx={{- display: "block",- height: "100%",- inset: 0,- objectFit: "cover",- objectPosition: "center",- opacity:- isCurrentImageReady || !thumbHashDataURL- ? 1- : 0,- position: "absolute",- transition: thumbHashDataURL- ? "opacity 220ms ease"- : "none",- width: "100%",- "@media (prefers-reduced-motion: reduce)": {- opacity: 1,- transition: "none",- },- }}- />- ) : null}- {isUnavailable && (- <Box- sx={{- alignItems: "center",- color: textSoft,- display: "flex",- fontSize: 12,- fontWeight: 600,- height: "100%",- justifyContent: "center",- width: "100%",- }}- >- Post unavailable- </Box>- )}- </Box>+ {!isUnavailable && thumbHashDataURL ? (+ <Box+ component="img"+ alt=""+ aria-hidden+ src={thumbHashDataURL}+ sx={{+ display: "block",+ filter: "blur(14px)",+ height: "100%",+ inset: 0,+ objectFit: "cover",+ objectPosition: "center",+ position: "absolute",+ transform: "scale(1.08)",+ width: "100%",+ }}+ />+ ) : null}+ {!isUnavailable && imageUrl ? (+ <Box+ component="img"+ alt={`${displayName} post ${index + 1}`}+ onLoad={(event) => {+ setReadyImageUrl(imageUrl);+ onRememberDimensions(item.id, event.currentTarget);+ }}+ onError={() => {+ log.warn(+ `Post ${item.postId} is unavailable because the browser could not decode its image`,+ );+ setImageDecodeFailed(true);+ onImageDecodeError();+ }}+ src={imageUrl}+ sx={{+ display: "block",+ height: "100%",+ inset: 0,+ objectFit: "contain",+ objectPosition: "center",+ opacity:+ isCurrentImageReady || !thumbHashDataURL ? 1 : 0,+ position: "absolute",+ transition: thumbHashDataURL+ ? "opacity 220ms ease"+ : "none",+ width: "100%",+ "@media (prefers-reduced-motion: reduce)": {+ opacity: 1,+ transition: "none",+ },+ }}+ />+ ) : null}{!isUnavailable && (- <>- <Box- aria-hidden- sx={{- background:- "linear-gradient(180deg, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0))",- filter: "blur(12px)",- height: 100,- left: -12,- pointerEvents: "none",- position: "absolute",- right: -12,- top: -12,- }}- />- <Box- component="time"- dateTime={new Date(item.timestampMs).toISOString()}- sx={{- color: "#C8C8C8",- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 12,- fontWeight: 500,- left: 16,- lineHeight: "16px",- pointerEvents: "none",- position: "absolute",- top: 16,- }}- >- {formatSpaceDate(item.timestampMs)}- </Box>- <SpacePostPhotosBadge count={photoCount} inset={12} />- {caption && (- <Box- title={caption}- sx={{- bottom: 20,- color: "#E6E6E6",- fontFamily:- '"Inter Variable", Inter, sans-serif',- fontSize: 13,- fontWeight: 600,- left: "50%",- lineHeight: "21px",- maxWidth: "78%",- pointerEvents: "none",- position: "absolute",- textAlign: "center",- textWrap: "balance",- transform: "translateX(-50%)",- width: "max-content",- }}- >- <SpaceCaptionText caption={caption} lineClamp={2} />- </Box>- )}- </>+ <SpacePostPhotosBadge count={photoCount} inset={8} />+ )}+ {isUnavailable && (+ <Box+ sx={{+ alignItems: "center",+ color: textSoft,+ display: "flex",+ fontSize: 12,+ fontWeight: 600,+ height: "100%",+ justifyContent: "center",+ width: "100%",+ }}+ >+ Post unavailable+ </Box>)}</Box>);@@ -607,6 +530,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>>@@ -630,9 +555,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({? undefined: spaceDefaultCoverImagePath;const firstName = firstNameFrom(displayName);- const visiblePostItems = postItems.filter(- (item) => !deletedPostIDs.has(item.id),- );+ const visiblePostItems = postItems+ .filter((item) => !deletedPostIDs.has(item.id))+ .sort((a, b) => b.timestampMs - a.timestampMs);const viewerPostItems = visiblePostItems.filter((item) =>!item.isUnavailable &&@@ -647,6 +572,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(@@ -797,6 +733,22 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({[loadedPhotoDimensionsByID],);+ const photoSections = profilePostSections(+ visiblePostItems.map((item, index) => {+ const { width, height } = dimensionsForPost(item);+ return {+ aspectRatio: width > 0 && height > 0 ? width / height : 1,+ index,+ item,+ timestampMs: item.timestampMs,+ };+ }),+ ).map(({ id, title, items }) => ({+ id,+ title,+ rows: profilePhotoRows(items, postGridWidth),+ }));+const profileViewerPhotos = viewerPostItems.flatMap((item) =>viewerPhotosFromPost({...item,@@ -847,13 +799,16 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({});};- const renderPost = (item: ProfilePostItem, index: number) => {+ const renderPostTile = (+ { aspectRatio, index, item }: ProfilePhotoTile,+ rowAspectRatio: number,+ ) => {const imageUrl = loadedPostImageURLFor(item);const isUnavailable = !viewerPostIndexByID.has(item.id);return (- <ProfilePost+ <ProfilePostTilekey={item.id}- dimensions={dimensionsForPost(item)}+ flexGrow={aspectRatio / rowAspectRatio}displayName={displayName}imageUrl={imageUrl}index={index}@@ -1630,6 +1585,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({>{hasProfilePosts ? (<Box+ ref={postGridRef}sx={{display: "flex",flexDirection: "column",@@ -1639,7 +1595,56 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({width: "calc(100% - 32px)",}}>- {visiblePostItems.map(renderPost)}+ {photoSections.map(({ id, title, rows }) => (+ <Box+ component="section"+ key={id}+ aria-label={title}+ >+ <Box+ component="h2"+ sx={{+ color: textSoft,+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 13,+ fontWeight: 700,+ lineHeight: "18px",+ m: 0,+ pb: "8px",+ }}+ >+ {title}+ </Box>+ <Box+ sx={{+ display: "flex",+ flexDirection: "column",+ gap: `${profilePhotoGap}px`,+ }}+ >+ {rows.map((row) => (+ <Box+ key={row.tiles[0]!.item.id}+ sx={{+ display: "flex",+ flexShrink: 0,+ gap: `${profilePhotoGap}px`,+ height: row.height,+ width: row.width,+ }}+ >+ {row.tiles.map((tile) =>+ renderPostTile(+ tile,+ row.aspectRatio,+ ),+ )}+ </Box>+ ))}+ </Box>+ </Box>+ ))}</Box>) : shouldShowPostLoadingIndicator ? (<ProfilePostLoadingIndicator />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..c64686a82e--- /dev/null+++ b/web/apps/space/src/utils/profile-photo-layout.ts@@ -0,0 +1,63 @@+export const profilePhotoGap = 6;+const profilePhotoMinRowHeight = 100;++export const profilePhotoRows = <Tile extends { aspectRatio: number }>(+ tiles: Tile[],+ width: number,+) => {+ const rows: {+ aspectRatio: number;+ height: number;+ width: number;+ tiles: 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;+ // Keep sparse sections compact without cropping their photos. Shorter+ // rows keep their natural width and align with the section heading.+ const height = Math.min((width - gaps) / aspectRatio, width * 0.75);+ rows.push({+ aspectRatio,+ height,+ width: height * aspectRatio + gaps,+ tiles: rowTiles,+ });+ index += rowSize;+ }++ return rows;+};diff --git a/web/apps/space/src/utils/profile-post-sections.ts b/web/apps/space/src/utils/profile-post-sections.tsnew file mode 100644index 0000000000..eba4b2c444--- /dev/null+++ b/web/apps/space/src/utils/profile-post-sections.ts@@ -0,0 +1,64 @@+/** Group newest-first posts using calendar boundaries in the viewer's timezone. */+export const profilePostSections = <Item extends { timestampMs: number }>(+ items: Item[],+ now = new Date(),+) => {+ const year = now.getFullYear();+ const month = now.getMonth();+ const day = now.getDate();+ // Weeks start on Monday. Construct local dates rather than subtracting+ // 24-hour periods so yesterday stays correct across daylight saving changes.+ const daysSinceMonday = (now.getDay() + 6) % 7;+ const recentSections = [+ { id: "today", title: "Today", since: new Date(year, month, day) },+ {+ id: "yesterday",+ title: "Yesterday",+ since: new Date(year, month, day - 1),+ },+ {+ id: "week",+ title: "This week",+ since: new Date(year, month, day - daysSinceMonday),+ },+ { id: "month", title: "This month", since: new Date(year, month, 1) },+ ].map((section) => ({ ...section, items: new Array<Item>() }));+ const months = new Map<+ number,+ { id: string; title: string; items: Item[] }+ >();++ for (const item of items) {+ const recentSection = recentSections.find(+ ({ since }) => item.timestampMs >= since.getTime(),+ );+ if (recentSection) {+ recentSection.items.push(item);+ continue;+ }++ const date = new Date(item.timestampMs);+ const monthStart = new Date(date.getFullYear(), date.getMonth(), 1);+ const key = monthStart.getTime();+ let section = months.get(key);+ if (!section) {+ section = {+ id: `${date.getFullYear()}-${date.getMonth() + 1}`,+ title: monthStart.toLocaleDateString("en-US", {+ month: "short",+ year: "numeric",+ }),+ items: [],+ };+ months.set(key, section);+ }+ section.items.push(item);+ }++ return [+ ...recentSections.filter(({ items }) => items.length > 0),+ ...[...months.entries()]+ .sort(([a], [b]) => b - a)+ .map(([, section]) => section),+ ];+};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..11959add02--- /dev/null+++ b/web/apps/space/tests/profile-photo-layout.test.ts@@ -0,0 +1,130 @@+import { expect, test } from "vitest";+import {+ profilePhotoGap,+ profilePhotoRows,+} from "../src/utils/profile-photo-layout";++const photos = (ratios: number[]) =>+ ratios.map((aspectRatio, id) => ({ id, aspectRatio }));++test.each([+ { count: 2, rowSizes: [2] },+ { count: 3, rowSizes: [3] },+ { count: 4, rowSizes: [2, 2] },+])(+ "a profile with $count photos uses the adaptive grid",+ ({ count, rowSizes }) => {+ const tiles = photos(new Array<number>(count).fill(2 / 3));+ const rows = profilePhotoRows(tiles, 352);+ expect(rows.map(({ tiles }) => tiles.length)).toEqual(rowSizes);+ expect(rows.flatMap(({ tiles }) => tiles)).toEqual(tiles);+ },+);++test("a profile with exactly five photos uses the adaptive grid throughout", () => {+ const tiles = photos([3 / 2, 3 / 2, 3 / 2, 3 / 2, 3 / 2]);+ const rows = profilePhotoRows(tiles, 352);+ expect(rows.map(({ tiles }) => tiles.map(({ id }) => id))).toEqual([+ [0, 1],+ [2, 3],+ [4],+ ]);+});++test("three portraits share a compact row", () => {+ expect(+ profilePhotoRows(+ photos([2 / 3, 3 / 4, 2 / 3, 2 / 3, 3 / 4, 2 / 3]),+ 328,+ ).map(({ tiles }) => tiles.length),+ ).toEqual([3, 3]);+});++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(+ profilePhotoRows(tiles, 363).map(({ tiles }) =>+ tiles.map(({ id }) => id),+ ),+ ).toEqual([+ [0, 1],+ [2, 3, 4],+ ]);+});++test("a standalone portrait stays compact and keeps its original proportions", () => {+ const tiles = photos([9 / 16]);+ expect(profilePhotoRows(tiles, 328)).toEqual([+ { aspectRatio: 9 / 16, height: 246, width: 246 * (9 / 16), tiles },+ ]);+});++test("similar landscapes are not forced into full-width rows", () => {+ const tiles = photos(new Array<number>(10).fill(3 / 2));+ const rows = profilePhotoRows(tiles, 358);+ 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 = profilePhotoRows(tiles, 358);+ 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(+ profilePhotoRows(tiles, 299 + profilePhotoGap).map(+ ({ tiles }) => tiles.length,+ ),+ ).toEqual([1, 1, 1, 1, 1, 1]);+ expect(+ profilePhotoRows(tiles, 300 + profilePhotoGap).map(+ ({ tiles }) => tiles.length,+ ),+ ).toEqual([2, 2, 2]);+ expect(+ profilePhotoRows(tiles, 456).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 = profilePhotoRows(tiles, 328);+ 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 = profilePhotoRows(tiles, width);+ 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);+ 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(profilePhotoRows([], 328)).toEqual([]);+});++test("the grid waits for its width to be measured", () => {+ expect(profilePhotoRows(photos([3 / 4, 3 / 2]), 0)).toEqual([]);+});diff --git a/web/apps/space/tests/profile-post-sections.test.ts b/web/apps/space/tests/profile-post-sections.test.tsnew file mode 100644index 0000000000..d537e7f1a1--- /dev/null+++ b/web/apps/space/tests/profile-post-sections.test.ts@@ -0,0 +1,126 @@+import { expect, test } from "vitest";+import { profilePostSections } from "../src/utils/profile-post-sections";++const post = (id: string, timestamp: Date) => ({+ id,+ timestampMs: timestamp.getTime(),+});++test("each post appears once in the first matching calendar section", () => {+ const now = new Date(2026, 8, 24, 12);+ const posts = [+ post("today", new Date(2026, 8, 24)),+ post("yesterday", new Date(2026, 8, 23)),+ post("this-week", new Date(2026, 8, 21)),+ post("this-month", new Date(2026, 8, 20, 23, 59, 59, 999)),+ post("august-1", new Date(2026, 7, 31)),+ post("august-2", new Date(2026, 7, 1)),+ post("july", new Date(2026, 6, 1)),+ post("last-year", new Date(2025, 7, 1)),+ ];+ const sections = profilePostSections(posts, now);++ expect(+ sections.map(({ title, items }) => [title, items.map((p) => p.id)]),+ ).toEqual([+ ["Today", ["today"]],+ ["Yesterday", ["yesterday"]],+ ["This week", ["this-week"]],+ ["This month", ["this-month"]],+ ["Aug 2026", ["august-1", "august-2"]],+ ["Jul 2026", ["july"]],+ ["Aug 2025", ["last-year"]],+ ]);+ expect(sections.flatMap(({ items }) => items)).toEqual(posts);+ expect(new Set(sections.map(({ id }) => id)).size).toBe(sections.length);+});++test("a new month still gives yesterday and this week priority", () => {+ const posts = [+ post("today", new Date(2026, 9, 1)),+ post("yesterday", new Date(2026, 8, 30)),+ post("monday", new Date(2026, 8, 28)),+ post("sunday", new Date(2026, 8, 27)),+ ];+ expect(+ profilePostSections(posts, new Date(2026, 9, 1, 12)).map(+ ({ title, items }) => [title, items.map((p) => p.id)],+ ),+ ).toEqual([+ ["Today", ["today"]],+ ["Yesterday", ["yesterday"]],+ ["This week", ["monday"]],+ ["Sep 2026", ["sunday"]],+ ]);+});++test("Monday starts a new week while Sunday remains yesterday", () => {+ const posts = [+ post("monday", new Date(2026, 8, 28)),+ post("sunday", new Date(2026, 8, 27)),+ post("saturday", new Date(2026, 8, 26)),+ ];+ expect(+ profilePostSections(posts, new Date(2026, 8, 28, 12)).map(+ ({ title }) => title,+ ),+ ).toEqual(["Today", "Yesterday", "This month"]);+});++test("Sunday is the last day of this week", () => {+ const posts = [+ post("friday", new Date(2026, 8, 25)),+ post("monday", new Date(2026, 8, 21)),+ post("last-sunday", new Date(2026, 8, 20)),+ ];+ expect(+ profilePostSections(posts, new Date(2026, 8, 27, 12)).map(+ ({ title, items }) => [title, items.map((p) => p.id)],+ ),+ ).toEqual([+ ["This week", ["friday", "monday"]],+ ["This month", ["last-sunday"]],+ ]);+});++test("month headings include the year and skip empty periods", () => {+ const posts = [+ post("december", new Date(2025, 11, 28)),+ post("october", new Date(2025, 9, 15)),+ post("older-december", new Date(2024, 11, 31)),+ ];+ expect(+ profilePostSections(posts, new Date(2026, 0, 1, 12)).map(+ ({ title }) => title,+ ),+ ).toEqual(["Dec 2025", "Oct 2025", "Dec 2024"]);+ expect(profilePostSections([], new Date(2026, 0, 1))).toEqual([]);+});++test.each([+ { now: new Date(2026, 2, 9, 12), olderTitle: "This month" },+ { now: new Date(2026, 10, 2, 12), olderTitle: "Oct 2026" },+])(+ "uses local midnights across daylight saving changes: $now",+ ({ now, olderTitle }) => {+ const year = now.getFullYear();+ const month = now.getMonth();+ const day = now.getDate();+ const posts = [+ post("today", new Date(year, month, day)),+ post("late-yesterday", new Date(year, month, day - 1, 23, 59)),+ post("early-yesterday", new Date(year, month, day - 1)),+ post("before-yesterday", new Date(year, month, day - 2, 23, 59)),+ ];+ expect(+ profilePostSections(posts, now).map(({ title, items }) => [+ title,+ items.map((p) => p.id),+ ]),+ ).toEqual([+ ["Today", ["today"]],+ ["Yesterday", ["late-yesterday", "early-yesterday"]],+ [olderTitle, ["before-yesterday"]],+ ]);+ },+);