π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Stabilize Space feed batches and refine post transitions
Anand Baburajan60473d1cf441
diff --git a/web/apps/space/src/components/HomeHeader.tsx b/web/apps/space/src/components/HomeHeader.tsxindex 3ee44051a2..3c5f31f7ed 100644--- a/web/apps/space/src/components/HomeHeader.tsx+++ b/web/apps/space/src/components/HomeHeader.tsx@@ -81,7 +81,9 @@ export const SpaceHomeHeader: React.FC<{ profile: SetupProfile | null }> = ({position: "sticky",top: 0,transform: visible ? "translateY(0)" : "translateY(-100%)",- transition: "transform 220ms cubic-bezier(0.2, 0, 0, 1)",+ transition: visible+ ? "transform 220ms cubic-bezier(0.2, 0, 0, 1)"+ : "transform 360ms ease-in-out",width: "100%",zIndex: 10,"@media (prefers-reduced-motion: reduce)": {diff --git a/web/apps/space/src/components/PostGrid.tsx b/web/apps/space/src/components/PostGrid.tsxindex 48aacd6f71..ea3276c83f 100644--- a/web/apps/space/src/components/PostGrid.tsx+++ b/web/apps/space/src/components/PostGrid.tsx@@ -4,6 +4,7 @@ import { layoutPostGrid } from "utils/post-grid";interface PostGridItem {id: string;+ batchIndex?: number;frameAspectRatio?: number;width?: number;height?: number;diff --git a/web/apps/space/src/components/PostPreviewThumbnail.tsx b/web/apps/space/src/components/PostPreviewThumbnail.tsxindex 37f29e7e1a..ef9f723107 100644--- a/web/apps/space/src/components/PostPreviewThumbnail.tsx+++ b/web/apps/space/src/components/PostPreviewThumbnail.tsx@@ -11,13 +11,31 @@ export const SpacePostPreviewThumbnail = ({post?: SpacePostPreview;}) =>post?.imageUrl ? (- <Box sx={{ position: "relative", width: 44, height: 44 }}>+ <Box+ sx={{+ borderRadius: "20%",+ height: 44,+ isolation: "isolate",+ position: "relative",+ width: 44,+ "&::after": {+ borderRadius: "inherit",+ boxShadow: "inset 0 0 0 1px #282828",+ content: '""',+ inset: 0,+ mixBlendMode: "lighten",+ pointerEvents: "none",+ position: "absolute",+ zIndex: 2,+ },+ }}+ ><Boxcomponent="img"alt=""src={post.imageUrl}sx={{- borderRadius: "20%",+ borderRadius: "inherit",display: "block",height: "100%",objectFit: "cover",diff --git a/web/apps/space/src/components/viewer-transition.ts b/web/apps/space/src/components/viewer-transition.tsindex 6e3861e25c..3ba120b452 100644--- a/web/apps/space/src/components/viewer-transition.ts+++ b/web/apps/space/src/components/viewer-transition.ts@@ -10,9 +10,9 @@ import {} from "utils/viewer-geometry";const originAttribute = "data-space-viewer-origin";-const openDuration = 0.6;+const openDuration = 0.48;const openBounce = 0.26;-const closeDuration = 0.46;+const closeDuration = 0.36;const swapFadeMs = 220;const closingFlights = new WeakMap<HTMLElement, () => void>();diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsxindex c89c57aec6..d20b1240d0 100644--- a/web/apps/space/src/pages/app/index.tsx+++ b/web/apps/space/src/pages/app/index.tsx@@ -28,10 +28,10 @@ import {setCurrentPostLiked,updateCurrentPostCaption,type SpaceFriendRequest,- type SpacePost,} from "services/space";import { useSpaceAppState } from "state/app-state";import { spaceAppBackgroundColor as homeBackground } from "styles/colors";+import type { HomeFeedPost } from "utils/home-feed";import { useSpaceRouter } from "utils/route-transitions";import { spaceRoutes } from "utils/routes";@@ -53,7 +53,7 @@ const Page: React.FC = () => {const [friendRequests, setFriendRequests] = useState<SpaceFriendRequest[]>([],);- const [feedItems, setFeedItems] = useState<SpacePost[]>([]);+ const [feedItems, setFeedItems] = useState<HomeFeedPost[]>([]);const [feedSession, setFeedSession] = useState<SpaceFeedSession>();const [hasFeedLoadMoreError, setHasFeedLoadMoreError] = useState(false);const [feedNextCursor, setFeedNextCursor] = useState<string>();@@ -232,11 +232,12 @@ const Page: React.FC = () => {const existingPostIds = new Set(currentItems.map((item) => item.postId),);+ const batchIndex = (currentItems.at(-1)?.batchIndex ?? 0) + 1;return [...currentItems,- ...feed.items.filter(- (item) => !existingPostIds.has(item.postId),- ),+ ...feed.items+ .filter((item) => !existingPostIds.has(item.postId))+ .map((item) => ({ ...item, batchIndex })),];});setFeedNextCursor(feed.nextCursor);diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex be518ab41f..dc793c40ce 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -71,6 +71,7 @@ import {homeFeedEntries,homeFeedSeparatorBefore,type HomeFeedEntry,+ type HomeFeedPost,} from "utils/home-feed";import {spacePostFrameAspectRatio,@@ -111,7 +112,7 @@ const feedPhotoCaptionTextSx = {textWrap: "balance",} as const;interface HomeScreenProps {- feedItems: SpacePost[];+ feedItems: HomeFeedPost[];friendRequestSentToastName?: string;hasFeedLoadMoreError?: boolean;hasMoreFeedItems?: boolean;diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex 2b5ec84c13..c5bafe43b8 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -939,11 +939,22 @@ const PostQuotePreview: React.FC<{display: "flex",flexDirection: "column",font: "inherit",+ isolation: "isolate",overflow: "hidden",p: 0,position: "relative",textAlign: "left",width: "100%",+ "&::after": {+ borderRadius: "inherit",+ boxShadow: "inset 0 0 0 1px #282828",+ content: '""',+ inset: 0,+ mixBlendMode: "lighten",+ pointerEvents: "none",+ position: "absolute",+ zIndex: 2,+ },"&:focus-visible": {outline: `2px solid ${green}`,outlineOffset: 2,diff --git a/web/apps/space/src/utils/home-feed.ts b/web/apps/space/src/utils/home-feed.tsindex 1b5e477c9e..7d38687483 100644--- a/web/apps/space/src/utils/home-feed.ts+++ b/web/apps/space/src/utils/home-feed.ts@@ -1,6 +1,10 @@import type { SpacePost } from "services/space";import type { LocalSpaceFeedPost } from "state/app-state";+export interface HomeFeedPost extends SpacePost {+ batchIndex?: number;+}+export type HomeFeedEntry =| {identity: string;@@ -8,10 +12,15 @@ export type HomeFeedEntry =kind: "local";renderKey: string;}- | { identity: string; item: SpacePost; kind: "remote"; renderKey: string };+ | {+ identity: string;+ item: HomeFeedPost;+ kind: "remote";+ renderKey: string;+ };export const homeFeedEntries = (- feedItems: SpacePost[],+ feedItems: HomeFeedPost[],localFeedPosts: LocalSpaceFeedPost[],newPostsSinceMs: number | undefined,latestPostIDs?: ReadonlySet<number>,@@ -46,9 +55,9 @@ export const homeFeedEntries = (})),];const latest: HomeFeedEntry[] = [];- const history: SpacePost[] = [];+ const history: HomeFeedPost[] = [];for (const entry of entries) {- let post: SpacePost;+ let post: HomeFeedPost;if (entry.kind == "remote") {post = entry.item;} else {diff --git a/web/apps/space/src/utils/post-grid.ts b/web/apps/space/src/utils/post-grid.tsindex 87051a5191..1bb1d55cca 100644--- a/web/apps/space/src/utils/post-grid.ts+++ b/web/apps/space/src/utils/post-grid.ts@@ -3,6 +3,7 @@ import { minimumPostPhotoFrameAspectRatio } from "../styles/tiles";const gap = 8;interface PostGridPhoto {+ batchIndex?: number;frameAspectRatio?: number;width?: number;height?: number;@@ -108,10 +109,15 @@ export const layoutPostGrid = (let previousKind: PhotoGroup["kind"] | undefined;let previousSide: PhotoGroup["side"];while (tiles.length < photos.length) {- const candidates = photoGroups(- ratios.slice(tiles.length, tiles.length + (fullWidth ? 1 : 3)),- width,- );+ const start = tiles.length;+ let end = start + 1;+ while (+ end < photos.length &&+ end < start + (fullWidth ? 1 : 3) &&+ photos[end]!.batchIndex == photos[start]!.batchIndex+ )+ end++;+ const candidates = photoGroups(ratios.slice(start, end), width);const score = (group: PhotoGroup) => {if (group.tiles.length > 1 &&diff --git a/web/apps/space/tests/home-feed.test.ts b/web/apps/space/tests/home-feed.test.tsindex 586e2ef20b..f96d336cfd 100644--- a/web/apps/space/tests/home-feed.test.ts+++ b/web/apps/space/tests/home-feed.test.ts@@ -4,6 +4,7 @@ import type { LocalSpaceFeedPost } from "../src/state/app-state";import {homeFeedEntries,homeFeedSeparatorBefore,+ type HomeFeedPost,} from "../src/utils/home-feed";const post = (postId: number, timestampMs: number): SpacePost => ({@@ -43,6 +44,23 @@ test("new posts stay full size for the visit and join history on the next visit"});});+test("history keeps batch boundaries when new posts are shown as cards", () => {+ const posts: HomeFeedPost[] = [+ post(5, 500),+ post(4, 400),+ post(3, 300),+ { ...post(2, 200), batchIndex: 1 },+ { ...post(1, 100), batchIndex: 1 },+ ];+ const { latest, history } = homeFeedEntries(posts, [], 300);+ expect(latest.map((entry) => entry.identity)).toEqual(["post:5", "post:4"]);+ expect(history.map((item) => [item.postId, item.batchIndex])).toEqual([+ [3, undefined],+ [2, 1],+ [1, 1],+ ]);+});+test("upload completion does not duplicate a post or move it into the grid", () => {const uploaded = post(3, 300);const existing = post(2, 200);diff --git a/web/apps/space/tests/post-grid.test.ts b/web/apps/space/tests/post-grid.test.tsindex ced10daf29..b15f05e4b7 100644--- a/web/apps/space/tests/post-grid.test.ts+++ b/web/apps/space/tests/post-grid.test.ts@@ -138,6 +138,50 @@ describe("post grid mosaic", () => {expect(layoutPostGrid(photos, 374)).toEqual(before);});+ it.each([288, 374, 768])(+ "keeps every displayed tile stable across feed batches at %ipx",+ (width) => {+ const ratios = [0.75, 1.5, 1.8, 1, 0.8, 3, 1.5, 0.75, 2, 1];+ const photos = Array.from({ length: 40 }, (_, index) => ({+ frameAspectRatio: ratios[index % ratios.length]!,+ batchIndex:+ index < 20 ? undefined : Math.floor((index - 20) / 10) + 1,+ }));+ for (const count of [20, 30]) {+ const before = layoutPostGrid(photos.slice(0, count), width);+ const after = layoutPostGrid(+ photos.slice(0, count + 10),+ width,+ );+ expect(after.tiles).toHaveLength(count + 10);+ expect(after.tiles.slice(0, count)).toEqual(before.tiles);+ expect(after.tiles[count]!.top).toBeCloseTo(before.height + 8);+ }+ },+ );++ it.each([1, 2, 3])(+ "finishes a %i-post batch before starting the next row",+ (count) => {+ const photos = photosWithRatios(Array<number>(count).fill(1));+ const { tiles } = layoutPostGrid(+ [...photos, { frameAspectRatio: 1, batchIndex: 1 }],+ 374,+ );+ const firstBatch = tiles.slice(0, count);+ const bottom = Math.max(+ ...firstBatch.map((tile) => tile.top + tile.height),+ );+ expect(Math.min(...firstBatch.map((tile) => tile.left))).toBe(0);+ expect(+ Math.max(...firstBatch.map((tile) => tile.left + tile.width)),+ ).toBeCloseTo(374);+ expect(tiles[count]!.top).toBeCloseTo(bottom + 8);+ if (count > 1)+ expect(firstBatch.every((tile) => tile.width < 374)).toBe(true);+ },+ );+it("has no height before measurement or without photos", () => {expect(layoutPostGrid(photosWithRatios([1, 0.75]), 0)).toEqual({tiles: [],