π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refine Space home tiles and empty states
Anand Baburajan27e86b058889
diff --git a/web/apps/space/src/components/AddFriendTile.tsx b/web/apps/space/src/components/AddFriendTile.tsxnew file mode 100644index 0000000000..833cd3f9bc--- /dev/null+++ b/web/apps/space/src/components/AddFriendTile.tsx@@ -0,0 +1,149 @@+import { UserAdd02Icon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { Box } from "@mui/material";+import { SpaceShareIcon } from "components/ShareInviteButton";+import React from "react";+import { spaceEmptyStateButtonSx } from "styles/buttons";+import {+ spaceSurface,+ spaceSurfaceHover,+ spaceText,+ spaceTextMuted,+} from "styles/colors";+import { spacePostTileRadius, spaceTileCornerStyles } from "styles/tiles";+import type {+ AddFriendTileVariant,+ HomeTilePlacement,+} from "utils/home-tile-layout";++interface SpaceAddFriendTileProps {+ onClick: () => void;+ placement: HomeTilePlacement;+ variant: AddFriendTileVariant;+}++export const SpaceAddFriendTile: React.FC<SpaceAddFriendTileProps> = ({+ onClick,+ placement,+ variant,+}) => (+ <Box+ component="li"+ sx={{+ ...spaceTileCornerStyles(+ Math.min(+ spacePostTileRadius,+ Math.min(placement.width, placement.height) * 0.2,+ ),+ ),+ height: placement.height,+ left: placement.x,+ listStyle: "none",+ position: "absolute",+ top: placement.y,+ width: placement.width,+ }}+ >+ {variant == "empty" ? (+ <Box+ sx={{+ alignItems: "center",+ bgcolor: spaceSurface,+ borderRadius: "inherit",+ boxSizing: "border-box",+ color: spaceText,+ display: "flex",+ flexDirection: "column",+ height: "100%",+ justifyContent: "center",+ px: "24px",+ py: "32px",+ textAlign: "center",+ }}+ >+ <HugeiconsIcon+ icon={UserAdd02Icon}+ size={32}+ strokeWidth={1.7}+ color={spaceTextMuted}+ style={{ flexShrink: 0, marginBottom: 16 }}+ />+ <Box+ component="h2"+ sx={{+ fontFamily: '"Nunito", sans-serif',+ fontSize: 22,+ fontWeight: 800,+ lineHeight: "28px",+ m: 0,+ mb: "8px",+ textWrap: "balance",+ }}+ >+ Invite your close friends and family+ </Box>+ <Box+ component="p"+ sx={{+ color: spaceTextMuted,+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 13,+ lineHeight: "20px",+ m: 0,+ maxWidth: 240,+ }}+ >+ Each person gets a little spot of their own in your Space.+ </Box>+ <Box+ className="green-bg"+ component="button"+ type="button"+ onClick={onClick}+ sx={{ ...spaceEmptyStateButtonSx, mt: "24px" }}+ >+ <SpaceShareIcon />+ Share invite link+ </Box>+ </Box>+ ) : (+ <Box+ component="button"+ type="button"+ aria-label="Add friend"+ onClick={onClick}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: spaceSurface,+ border: 0,+ borderRadius: "inherit",+ color: spaceText,+ cursor: "pointer",+ display: "flex",+ height: "100%",+ justifyContent: "center",+ p: "var(--space-tile-padding)",+ width: "100%",+ transition:+ "background-color 160ms ease, box-shadow 160ms ease",+ "&:hover": {+ bgcolor: spaceSurfaceHover,+ boxShadow: "inset 0 0 0 1px rgba(255, 255, 255, 0.08)",+ },+ "&:active": { bgcolor: spaceSurface },+ "&:focus-visible": {+ outline: "2px solid #08C225",+ outlineOffset: -4,+ },+ }}+ >+ <HugeiconsIcon+ icon={UserAdd02Icon}+ size={28}+ strokeWidth={1.7}+ />+ </Box>+ )}+ </Box>+);diff --git a/web/apps/space/src/components/OwnPostTile.tsx b/web/apps/space/src/components/OwnPostTile.tsxindex cf7e8d4701..31bc2b5bae 100644--- a/web/apps/space/src/components/OwnPostTile.tsx+++ b/web/apps/space/src/components/OwnPostTile.tsx@@ -6,9 +6,17 @@ import log from "ente-base/log";import React from "react";import type { SetupProfile } from "screens/SetupProfileScreen";import type { SpacePost, SpacePostAssetURLLoader } from "services/space";-import { spaceSurface, spaceText, spaceTextMuted } from "styles/colors";+import { useSpaceAppState } from "state/app-state";+import { spaceSurface, spaceTextMuted } from "styles/colors";+import {+ spacePostTileRadius,+ spaceTileCircleInset,+ spaceTileCornerStyles,+} from "styles/tiles";+import { spaceDefaultCoverImagePath } from "utils/post-image";const green = "#08C225";+const actionSize = 44;interface SpaceOwnPostTileProps {profile: SetupProfile | null;@@ -33,6 +41,10 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({onOpenProfile,onNewPost,}) => {+ const { cachedProfileAvatarUrl } = useSpaceAppState();+ const avatarUrl = profile ? profile.avatarUrl : cachedProfileAvatarUrl;+ const isAvatarLoading =+ !avatarUrl && (!profile || Boolean(profile.avatarObjectID));const [loadedImage, setLoadedImage] = React.useState<{post: SpacePost;url?: string;@@ -44,6 +56,8 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({isUnavailable || post?.isUnavailable || postImage?.failed;const loading =isLoading || Boolean(post?.imageAsset && !imageUrl && !unavailable);+ const isEmpty = !post && !loading && !unavailable;+ const coverUrl = isEmpty ? spaceDefaultCoverImagePath : imageUrl;React.useEffect(() => {if (!post?.imageAsset || post.imageUrl || !onLoadPostImage) return;@@ -67,9 +81,9 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({component="section"aria-label="Your latest post"sx={{+ ...spaceTileCornerStyles(spacePostTileRadius),aspectRatio: "1.7",bgcolor: spaceSurface,- borderRadius: "24px",flexShrink: 0,fontFamily: '"Inter Variable", Inter, sans-serif',overflow: "hidden",@@ -101,11 +115,11 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({width: "100%",}}>- {imageUrl && !unavailable ? (+ {coverUrl && !unavailable ? (<Boxcomponent="img"- alt={post?.caption || "Your latest post"}- src={imageUrl}+ alt={isEmpty ? "" : post?.caption || "Your latest post"}+ src={coverUrl}onError={() =>post && setLoadedImage({ post, failed: true })}@@ -122,26 +136,74 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({sx={{ height: "100%", transform: "none" }}/>) : (- <Box sx={{ fontSize: 15, pb: "56px", px: "24px" }}>- {unavailable- ? "Couldn't load your latest post"- : "Share your first photo"}+ <Box+ sx={{+ fontSize: 15,+ pb: "56px",+ px: "var(--space-tile-padding)",+ }}+ >+ Couldn't load your latest post+ </Box>+ )}+ {isEmpty && (+ <Box+ sx={{+ alignItems: "center",+ bgcolor: "rgba(0, 0, 0, 0.18)",+ display: "flex",+ flexDirection: "column",+ gap: "6px",+ inset: 0,+ justifyContent: "center",+ position: "absolute",+ px: "var(--space-tile-padding)",+ textAlign: "center",+ }}+ >+ <Box+ component="span"+ sx={{+ bgcolor: "rgba(249, 252, 239, 0.94)",+ borderRadius: "999px",+ color: "#24351B",+ fontSize: 12,+ fontWeight: 600,+ lineHeight: "18px",+ px: "12px",+ py: "3px",+ }}+ >+ Your posts will show up here+ </Box>+ <Box+ component="span"+ sx={{+ backdropFilter: "blur(12px)",+ bgcolor: "rgba(28, 28, 30, 0.48)",+ borderRadius: "999px",+ color: "#E3E7DA",+ fontSize: 12,+ fontWeight: 500,+ lineHeight: "18px",+ px: "10px",+ py: "3px",+ }}+ >+ Share a little moment from your day!+ </Box></Box>)}</Box><Boxsx={{- alignItems: "center",background:imageUrl && !unavailable? "linear-gradient(transparent, rgba(0, 0, 0, 0.72))": undefined,bottom: 0,- display: "flex",- gap: "12px",- justifyContent: "space-between",+ height: "50%",left: 0,- p: "32px 16px 16px",pointerEvents: "none",position: "absolute",right: 0,@@ -157,37 +219,43 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({appearance: "none",bgcolor: "transparent",border: 0,- borderRadius: "12px",- color: spaceText,+ borderRadius: "50%",+ bottom: spaceTileCircleInset(actionSize),cursor: onOpenProfile ? "pointer" : "default",display: "flex",- font: "inherit",- gap: "10px",- minWidth: 0,+ height: actionSize,+ justifyContent: "center",+ left: spaceTileCircleInset(actionSize),p: 0,pointerEvents: "auto",- textAlign: "left",+ position: "absolute",+ width: actionSize,}}><Boxsx={{- border: "2px solid rgba(255, 255, 255, 0.8)",+ border: avatarUrl+ ? "2px solid rgba(255, 255, 255, 0.36)"+ : "2px solid rgba(255, 255, 255, 0.28)",borderRadius: "50%",boxSizing: "border-box",flexShrink: 0,- height: 44,+ height: actionSize,overflow: "hidden",- width: 44,+ width: actionSize,}}>- <SpaceAvatarImage src={profile?.avatarUrl} />- </Box>- <Box>- <Box sx={{ fontSize: 16, fontWeight: 650 }}>You</Box>- {post && (- <Box sx={{ fontSize: 11, mt: "3px", opacity: 0.8 }}>- Latest post- </Box>+ {isAvatarLoading ? (+ <Skeleton+ variant="circular"+ sx={{+ bgcolor: spaceSurface,+ height: "100%",+ width: "100%",+ }}+ />+ ) : (+ <SpaceAvatarImage src={avatarUrl} />)}</Box></Box>@@ -195,6 +263,7 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({className="green-bg"component="button"type="button"+ aria-label="New post"disabled={isNewPostDisabled}onClick={onNewPost}sx={{@@ -202,25 +271,24 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({appearance: "none",bgcolor: green,border: 0,- borderRadius: "999px",+ borderRadius: "50%",+ bottom: spaceTileCircleInset(actionSize),color: "#FFFFFF",cursor: isNewPostDisabled ? "default" : "pointer",display: "flex",- flexShrink: 0,- font: "inherit",- fontSize: 13,- fontWeight: 650,- gap: "6px",- minHeight: 44,+ height: actionSize,+ justifyContent: "center",opacity: isNewPostDisabled ? 0.6 : 1,- px: "14px",+ p: 0,pointerEvents: "auto",+ position: "absolute",+ right: spaceTileCircleInset(actionSize),+ width: actionSize,"&:hover": { bgcolor: "#07B422" },"&:focus-visible": { outlineColor: "#FFFFFF" },}}>- <HugeiconsIcon icon={Add01Icon} size={20} strokeWidth={2} />- New post+ <HugeiconsIcon icon={Add01Icon} size={24} strokeWidth={2} /></Box></Box></Box>diff --git a/web/apps/space/src/components/PostUnreadBadge.tsx b/web/apps/space/src/components/PostUnreadBadge.tsxindex f24589dbfb..3cbe863b2e 100644--- a/web/apps/space/src/components/PostUnreadBadge.tsx+++ b/web/apps/space/src/components/PostUnreadBadge.tsx@@ -1,5 +1,6 @@import { Box } from "@mui/material";import React from "react";+import { spaceTileCircleInset } from "styles/tiles";interface SpacePostBadgeProps extends React.PropsWithChildren {backgroundColor: string;@@ -14,48 +15,61 @@ export const SpacePostBadge: React.FC<SpacePostBadgeProps> = ({color,placement = "top-right",variant = "default",-}) => (- <Box- component="span"- aria-hidden- sx={{- alignItems: "center",- bgcolor: backgroundColor,- borderRadius: "999px",- color,- display: "inline-flex",- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: placement == "center" ? 11 : 10,- fontVariantNumeric: "tabular-nums",- fontWeight: placement == "center" ? 600 : 700,- height: placement == "center" ? 24 : 20,- justifyContent: "center",- lineHeight: 1,- minWidth: 20,- pointerEvents: "none",- position: "absolute",- px: placement == "center" ? "10px" : "7px",- whiteSpace: "nowrap",- zIndex: 1,- ...(placement == "center"- ? {- left: "50%",- top: "50%",- transform: "translate(-50%, -50%)",- }- : { right: "10%", top: "10%" }),- ...(variant == "unread" && {- boxShadow: "0 1px 3px rgba(0, 0, 0, 0.15)",- fontSize: 12,- height: 24,- minWidth: 24,- px: "6px",- }),- }}- >- {children}- </Box>-);+}) => {+ const height = variant == "unread" || placement == "center" ? 24 : 20;+ const inset = spaceTileCircleInset(height);+ return (+ <Box+ component="span"+ aria-hidden+ sx={{+ alignItems: "center",+ bgcolor: backgroundColor,+ borderRadius: "999px",+ boxSizing: "border-box",+ color,+ display: "inline-flex",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: placement == "center" ? 11 : 10,+ fontVariantNumeric: "tabular-nums",+ fontWeight: placement == "center" ? 600 : 700,+ height,+ justifyContent: "center",+ lineHeight: 1,+ maxWidth: "calc(100% - 2 * var(--space-tile-padding))",+ minWidth: height,+ pointerEvents: "none",+ position: "absolute",+ px: placement == "center" ? "10px" : "7px",+ whiteSpace: "nowrap",+ zIndex: 1,+ ...(placement == "center"+ ? {+ left: "50%",+ top: "50%",+ transform: "translate(-50%, -50%)",+ }+ : {+ right: inset,+ top: inset,+ maxWidth: `calc(100% - 2 * (${inset}))`,+ }),+ ...(variant == "unread" && {+ boxShadow: "0 1px 3px rgba(0, 0, 0, 0.15)",+ fontSize: 12,+ px: "6px",+ }),+ }}+ >+ <Box+ component="span"+ sx={{ overflow: "hidden", textOverflow: "ellipsis" }}+ >+ {children}+ </Box>+ </Box>+ );+};export const SpacePostUnreadBadge: React.FC<{ count: number }> = ({count,diff --git a/web/apps/space/src/hooks/use-own-latest-post.ts b/web/apps/space/src/hooks/use-own-latest-post.tsnew file mode 100644index 0000000000..571db0e3f1--- /dev/null+++ b/web/apps/space/src/hooks/use-own-latest-post.ts@@ -0,0 +1,87 @@+import log from "ente-base/log";+import { useCallback, useEffect, useState } from "react";+import {+ deleteCurrentPost,+ loadCurrentSpaceProfilePostsPage,+ updateCurrentPostCaption,+ type SpacePost,+} from "services/space";+import { useSpaceAppState } from "state/app-state";++export const useOwnLatestPost = () => {+ const { profile, profileLoadStatus } = useSpaceAppState();+ const spaceId = profile?.spaceId;+ const [ownLatestPost, setOwnLatestPost] = useState<SpacePost>();+ const [ownPostsVersion, setOwnPostsVersion] = useState(0);+ const [isOwnLatestPostLoading, setIsOwnLatestPostLoading] = useState(true);+ const [isOwnLatestPostUnavailable, setIsOwnLatestPostUnavailable] =+ useState(false);++ useEffect(() => {+ if (profileLoadStatus != "ready") return;++ setOwnLatestPost(undefined);+ setIsOwnLatestPostLoading(Boolean(spaceId));+ setIsOwnLatestPostUnavailable(false);+ if (!spaceId) return;++ let cancelled = false;+ void loadCurrentSpaceProfilePostsPage(spaceId, spaceId)+ .then((page) => {+ if (!cancelled) setOwnLatestPost(page.items[0]);+ })+ .catch((error: unknown) => {+ log.error("Failed to load own latest Space post", error);+ if (!cancelled) setIsOwnLatestPostUnavailable(true);+ })+ .finally(() => {+ if (!cancelled) setIsOwnLatestPostLoading(false);+ });+ return () => {+ cancelled = true;+ };+ }, [spaceId, profileLoadStatus, ownPostsVersion]);++ const setCreatedPost = useCallback((post: SpacePost) => {+ setOwnLatestPost(post);+ setIsOwnLatestPostLoading(false);+ setIsOwnLatestPostUnavailable(false);+ }, []);++ const deleteOwnPost = useCallback(+ async (postId: number) => {+ if (!spaceId) throw new Error("Missing space.");++ await deleteCurrentPost(spaceId, postId);+ if (ownLatestPost?.postId == postId) {+ setOwnLatestPost(undefined);+ setIsOwnLatestPostLoading(true);+ setOwnPostsVersion((version) => version + 1);+ }+ },+ [spaceId, ownLatestPost?.postId],+ );++ const updateOwnPostCaption = useCallback(+ async (postId: number, caption: string) => {+ if (!spaceId) throw new Error("Missing space.");++ await updateCurrentPostCaption(spaceId, postId, caption);+ setOwnLatestPost((post) =>+ post?.postId == postId+ ? { ...post, caption: caption.trim() || undefined }+ : post,+ );+ },+ [spaceId],+ );++ return {+ ownLatestPost,+ isOwnLatestPostLoading,+ isOwnLatestPostUnavailable,+ setCreatedPost,+ deleteOwnPost,+ updateOwnPostCaption,+ };+};diff --git a/web/apps/space/src/pages/_app.tsx b/web/apps/space/src/pages/_app.tsxindex 0980a5189a..2a23395de1 100644--- a/web/apps/space/src/pages/_app.tsx+++ b/web/apps/space/src/pages/_app.tsx@@ -29,6 +29,11 @@ import {} from "styles/colors";import "styles/globals.css";+const interFontURL = new URL(+ "@fontsource-variable/inter/files/inter-latin-wght-normal.woff2",+ import.meta.url,+).href;+const darkPalette = shareTheme.colorSchemes.dark!.palette;const spaceTheme = createTheme(@@ -116,6 +121,13 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {title="Ente Space"viewportContent="width=device-width, initial-scale=1, maximum-scale=1">+ <link+ rel="preload"+ href={interFontURL}+ as="font"+ type="font/woff2"+ crossOrigin="anonymous"+ /><meta name="color-scheme" content="dark" /><meta name="theme-color" content={spaceAppBackgroundColor} /><meta name="application-name" content="Ente Space" />diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsxindex 99368ae124..887372494c 100644--- a/web/apps/space/src/pages/app/index.tsx+++ b/web/apps/space/src/pages/app/index.tsx@@ -3,6 +3,7 @@ import { SpaceFriendRequestCanceledToast } from "components/FriendRequestCanceleimport { SpacePageMeta } from "components/PageMeta";import { SpaceRouteFallback } from "components/RouteFallback";import log from "ente-base/log";+import { useOwnLatestPost } from "hooks/use-own-latest-post";import React, { useEffect, useState } from "react";import { HomeScreen } from "screens/HomeScreen";import {@@ -58,10 +59,14 @@ const Page: React.FC = () => {[],);const [latestPosts, setLatestPosts] = useState<SpacePost[]>([]);- const [ownLatestPost, setOwnLatestPost] = useState<SpacePost>();- const [isOwnLatestPostLoading, setIsOwnLatestPostLoading] = useState(true);- const [isOwnLatestPostUnavailable, setIsOwnLatestPostUnavailable] =- useState(false);+ const {+ ownLatestPost,+ isOwnLatestPostLoading,+ isOwnLatestPostUnavailable,+ setCreatedPost,+ deleteOwnPost,+ updateOwnPostCaption,+ } = useOwnLatestPost();const [unreadPosts, setUnreadPosts] = useState<SpacePost[]>([]);const [hasUnreadMessages, setHasUnreadMessages] = useState<boolean>();const [isLatestPostsLoading, setIsLatestPostsLoading] = useState(true);@@ -102,29 +107,6 @@ const Page: React.FC = () => {setFriendRequestSentToastName(sentFriend.username.trim());}, [router.isReady]);- useEffect(() => {- if (profileLoadStatus != "ready" || !profile?.spaceId) return;-- let cancelled = false;- setOwnLatestPost(undefined);- setIsOwnLatestPostLoading(true);- setIsOwnLatestPostUnavailable(false);- void loadCurrentSpaceProfilePostsPage(profile.spaceId, profile.spaceId)- .then((page) => {- if (!cancelled) setOwnLatestPost(page.items[0]);- })- .catch((error: unknown) => {- log.error("Failed to load own latest Space post", error);- if (!cancelled) setIsOwnLatestPostUnavailable(true);- })- .finally(() => {- if (!cancelled) setIsOwnLatestPostLoading(false);- });- return () => {- cancelled = true;- };- }, [profile?.spaceId, profileLoadStatus]);-useEffect(() => {const request = { cancelled: false };const isCancelled = () => request.cancelled;@@ -363,12 +345,12 @@ const Page: React.FC = () => {profile? async (image, caption) => {const post = await publishPost(image, caption);- setOwnLatestPost(post);- setIsOwnLatestPostLoading(false);- setIsOwnLatestPostUnavailable(false);+ setCreatedPost(post);}: undefined}+ onDeletePost={deleteOwnPost}+ onUpdatePostCaption={updateOwnPostCaption}onOpenFriend={(friendID, username) => {const friend = friends.find((candidate) =>diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsxindex 46254301c5..d68ab2f478 100644--- a/web/apps/space/src/pages/layout-demo.tsx+++ b/web/apps/space/src/pages/layout-demo.tsx@@ -1,35 +1,44 @@import { ArrowLeft02Icon, ArrowRight02Icon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box } from "@mui/material";+import { SpaceAddFriendTile } from "components/AddFriendTile";import { SpaceFileViewer } from "components/FileViewer";import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";import { SpaceOwnPostTile } from "components/OwnPostTile";import { useBrowserBackClose } from "hooks/use-browser-back-close";import React from "react";import { FriendPostTile } from "screens/HomeScreen";+import type { SetupProfile } from "screens/SetupProfileScreen";import type { SpacePost } from "services/space";-import { useSpaceAppState } from "state/app-state";import { spaceAppBackground, spaceSurface, spaceText } from "styles/colors";import {- homeTileGridLayout,- homeTilePlacements,+ spacePostTileRadius,+ spaceTileCircleInset,+ spaceTileCornerStyles,+} from "styles/tiles";+import {+ homeTileGap,+ homeTileLayout,maximumHomeTileCount,- usesHomeTileGrid,+ minimumHomeTileCanvasHeight,type HomeTilePlacement,} from "utils/home-tile-layout";-import { useSpaceRouter } from "utils/route-transitions";-import { spaceRoutes } from "utils/routes";+import { spaceDefaultCoverImagePath } from "utils/post-image";const controlButtonColor = spaceSurface;-+const demoProfile: SetupProfile = {+ avatarUrl: null,+ fullName: "Alex Morgan",+ spaceId: "demo-self",+ username: "you",+};const demoOwnPosts: SpacePost[] = [- "/images/default-cover-image.jpg",+ spaceDefaultCoverImagePath,"/images/invite-bg.jpg",- "/images/default-profile-pic.png",].map((imageUrl, index) => ({friendID: "demo-self",imageUrl,- name: "You",+ name: demoProfile.fullName,postId: 100 - index,spaceId: "demo-self",timestampMs: 1_700_000_000_000 - index * 86_400_000,@@ -44,7 +53,7 @@ interface CanvasSize {interface LayoutDemoPostProps {count: number;index: number;- placement?: HomeTilePlacement;+ placement: HomeTilePlacement;}const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({@@ -103,7 +112,7 @@ const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({hasPlaceholderMedia? "/images/invite-bg.jpg": isUnread- ? "/images/default-cover-image.jpg"+ ? spaceDefaultCoverImagePath: undefined}isAvatarPending={false}@@ -133,21 +142,36 @@ const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({};const LayoutDemoPage: React.FC = () => {- const router = useSpaceRouter();- const { profile } = useSpaceAppState();+ const [{ friendCount, ownPosts }, setDemo] = React.useState({+ friendCount: 0,+ ownPosts: [] as SpacePost[],+ });+ const changeFriendCount = React.useCallback((delta: number) => {+ setDemo(({ friendCount }) => {+ const count = Math.max(+ 0,+ Math.min(maximumHomeTileCount, friendCount + delta),+ );+ return {+ friendCount: count,+ ownPosts: count % 2 == 0 ? [] : demoOwnPosts,+ };+ });+ }, []);+ const [ownViewerPosts, setOwnViewerPosts] = React.useState<SpacePost[]>([]);const [ownPostIndex, setOwnPostIndex] = React.useState<number>();+ const ownViewerOpen = ownPostIndex !== undefined;useBrowserBackClose({- open: ownPostIndex !== undefined,+ open: ownViewerOpen,onClose: () => setOwnPostIndex(undefined),stateKey: "space-layout-demo-viewer",});- const ownPostPhotos = demoOwnPosts.map((post) => ({+ const ownPostPhotos = ownViewerPosts.map((post) => ({...post,alt: "Your post",- avatarUrl: profile?.avatarUrl,- imageUrl: post.imageUrl!,+ avatarUrl: demoProfile.avatarUrl,+ imageUrl: post.imageUrl ?? "",}));- const [friendCount, setFriendCount] = React.useState(1);const [canvasSize, setCanvasSize] = React.useState<CanvasSize>({height: 0,width: 0,@@ -169,26 +193,20 @@ const LayoutDemoPage: React.FC = () => {}, []);React.useEffect(() => {+ if (ownViewerOpen) return;+const handleKeyDown = (event: KeyboardEvent) => {if (event.key == "ArrowLeft") {- setFriendCount((count) => Math.max(1, count - 1));+ changeFriendCount(-1);} else if (event.key == "ArrowRight") {- setFriendCount((count) =>- Math.min(maximumHomeTileCount, count + 1),- );+ changeFriendCount(1);}};window.addEventListener("keydown", handleKeyDown);return () => window.removeEventListener("keydown", handleKeyDown);- }, []);+ }, [changeFriendCount, ownViewerOpen]);- const usesGrid = usesHomeTileGrid(friendCount);- const placements = homeTilePlacements(- friendCount,- canvasSize.width,- canvasSize.height,- );- const gridLayout = homeTileGridLayout(+ const layout = homeTileLayout(friendCount,canvasSize.width,canvasSize.height,@@ -220,154 +238,151 @@ const LayoutDemoPage: React.FC = () => {"@media (min-width: 600px)": { maxWidth: 390 },}}>- <SpaceHomeHeader- profile={profile}- onOpenMessages={() =>- void router.push(spaceRoutes.messages)- }- onOpenProfile={- profile- ? () => void router.push(spaceRoutes.profile)- : undefined- }- />+ <SpaceHomeHeader profile={demoProfile} /><Boxsx={{boxSizing: "border-box",display: "flex",flexDirection: "column",- gap: "16px",+ gap: `${homeTileGap}px`,minHeight: `calc(100svh - ${spaceHomeHeaderHeight}px)`,minWidth: 0,- pb: "calc(env(safe-area-inset-bottom) + 72px)",+ pb: "calc(env(safe-area-inset-bottom) + 16px)",px: "16px",- pt: "12px",+ pt: "4px",width: "100%",}}>- <SpaceOwnPostTile- profile={profile}- post={demoOwnPosts[0]}- onNewPost={() => void router.push("/app/post")}- onOpenPost={() => setOwnPostIndex(0)}- onOpenProfile={() =>- void router.push(spaceRoutes.profile)- }- /><Boxref={canvasRef}+ component="ul"+ aria-label="Friends and friend requests"sx={{- display: usesGrid ? "grid" : "block",flex: "1 1 auto",- gap: gridLayout ? `${gridLayout.gap}px` : undefined,- gridTemplateColumns: gridLayout- ? `repeat(3, ${gridLayout.size}px)`- : undefined,- gridTemplateRows: gridLayout- ? `repeat(${gridLayout.rows}, ${gridLayout.size}px)`- : undefined,- minHeight: 320,- placeContent: usesGrid ? "center" : undefined,+ m: 0,+ minHeight: minimumHomeTileCanvasHeight(friendCount),+ p: 0,position: "relative",width: "100%",}}>- {usesGrid && gridLayout- ? Array.from(- { length: friendCount },- (_, index) => (- <LayoutDemoPost- key={index}- count={friendCount}- index={index}- />- ),- )- : placements.map((placement, index) => (- <LayoutDemoPost- key={index}- count={friendCount}- index={index}- placement={placement}- />- ))}+ {layout && (+ <>+ {layout.friends.map((placement, index) => (+ <LayoutDemoPost+ key={index}+ count={friendCount}+ index={index}+ placement={placement}+ />+ ))}+ {layout.addFriend && (+ <SpaceAddFriendTile+ placement={layout.addFriend}+ variant={layout.addFriendVariant}+ onClick={() => changeFriendCount(1)}+ />+ )}+ </>+ )}</Box>- </Box>- <Box- sx={{- bottom: "calc(env(safe-area-inset-bottom) + 20px)",- display: "flex",- gap: "8px",- left: "max(20px, calc((100vw - 390px) / 2 + 20px))",- position: "fixed",- zIndex: 5,- }}- ><Box- component="button"- type="button"- aria-label="Show one fewer friend"- disabled={friendCount == 1}- onClick={() =>- setFriendCount((count) => Math.max(1, count - 1))- }sx={{- alignItems: "center",- appearance: "none",- bgcolor: controlButtonColor,- border: 0,- borderRadius: "50%",- color: spaceText,- cursor: friendCount == 1 ? "default" : "pointer",- display: "flex",- height: 36,- justifyContent: "center",- opacity: friendCount == 1 ? 0.3 : 1,- p: 0,- width: 36,- }}- >- <HugeiconsIcon- icon={ArrowLeft02Icon}- size={22}- strokeWidth={2.2}- />- </Box>- <Box- component="button"- type="button"- aria-label="Show one more friend"- disabled={friendCount == maximumHomeTileCount}- onClick={() =>- setFriendCount((count) =>- Math.min(maximumHomeTileCount, count + 1),- )- }- sx={{- alignItems: "center",- appearance: "none",- bgcolor: controlButtonColor,- border: 0,- borderRadius: "50%",- color: spaceText,- cursor:- friendCount == maximumHomeTileCount- ? "default"- : "pointer",- display: "flex",- height: 36,- justifyContent: "center",- opacity:- friendCount == maximumHomeTileCount ? 0.3 : 1,- p: 0,- width: 36,+ ...spaceTileCornerStyles(spacePostTileRadius),+ flexShrink: 0,+ position: "relative",}}>- <HugeiconsIcon- icon={ArrowRight02Icon}- size={22}- strokeWidth={2.2}+ <SpaceOwnPostTile+ profile={demoProfile}+ post={ownPosts[0]}+ onNewPost={() =>+ setDemo((current) => ({+ ...current,+ ownPosts: demoOwnPosts,+ }))+ }+ onOpenPost={() => {+ setOwnViewerPosts(ownPosts);+ setOwnPostIndex(0);+ }}/>+ <Box+ sx={{+ display: "flex",+ gap: "8px",+ position: "absolute",+ right: spaceTileCircleInset(36),+ top: spaceTileCircleInset(36),+ zIndex: 5,+ }}+ >+ <Box+ component="button"+ type="button"+ aria-label="Show one fewer friend"+ disabled={friendCount == 0}+ onClick={() => changeFriendCount(-1)}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: controlButtonColor,+ border: 0,+ borderRadius: "50%",+ color: spaceText,+ cursor:+ friendCount == 0+ ? "default"+ : "pointer",+ display: "flex",+ height: 36,+ justifyContent: "center",+ opacity: friendCount == 0 ? 0.3 : 1,+ p: 0,+ width: 36,+ }}+ >+ <HugeiconsIcon+ icon={ArrowLeft02Icon}+ size={22}+ strokeWidth={2.2}+ />+ </Box>+ <Box+ component="button"+ type="button"+ aria-label="Show one more friend"+ disabled={friendCount == maximumHomeTileCount}+ onClick={() => changeFriendCount(1)}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: controlButtonColor,+ border: 0,+ borderRadius: "50%",+ color: spaceText,+ cursor:+ friendCount == maximumHomeTileCount+ ? "default"+ : "pointer",+ display: "flex",+ height: 36,+ justifyContent: "center",+ opacity:+ friendCount == maximumHomeTileCount+ ? 0.3+ : 1,+ p: 0,+ width: 36,+ }}+ >+ <HugeiconsIcon+ icon={ArrowRight02Icon}+ size={22}+ strokeWidth={2.2}+ />+ </Box>+ </Box></Box></Box>{ownPostIndex !== undefined && (@@ -378,6 +393,33 @@ const LayoutDemoPage: React.FC = () => {onPhotoIndexChange={setOwnPostIndex}postActionMode="hidden"onClose={() => setOwnPostIndex(undefined)}+ onDeletePost={() => {+ const postId = ownViewerPosts[ownPostIndex]!.postId;+ setDemo((current) => ({+ ...current,+ ownPosts: current.ownPosts.filter(+ (post) => post.postId != postId,+ ),+ }));+ }}+ onUpdatePostCaption={(postId, caption) => {+ const updatePosts = (posts: SpacePost[]) =>+ posts.map((post) =>+ post.postId == postId+ ? {+ ...post,+ caption:+ caption.trim() || undefined,+ }+ : post,+ );+ setDemo((current) => ({+ ...current,+ ownPosts: updatePosts(current.ownPosts),+ }));+ setOwnViewerPosts(updatePosts);+ return Promise.resolve();+ }}/>)}</Box>diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex b23d4c2287..70bc853e96 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -6,6 +6,7 @@ import {SpaceActionToast,spaceToastAutoDismissDurationMs,} from "components/ActionToast";+import { SpaceAddFriendTile } from "components/AddFriendTile";import { SpaceAvatarImage } from "components/AvatarImage";import {SpaceFileViewer,@@ -22,13 +23,13 @@ import {} from "components/PostUnreadBadge";import { SpacePWAInstallPrompt } from "components/PWAInstallPrompt";import { SpaceLoadingSpinner } from "components/RouteFallback";-import { SpaceShareInviteButton } from "components/ShareInviteButton";import type { FriendProfile } from "data/friends";import log from "ente-base/log";import { useBrowserBackClose } from "hooks/use-browser-back-close";import React, { useState } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";import { markSpaceHomePostRead } from "services/home-posts";+import { openSpaceShareLinkDialog } from "services/share-link";import {isSpaceContentError,type SpaceFriendRequest,@@ -44,12 +45,18 @@ import {spaceText,spaceTextMuted,} from "styles/colors";+import {+ spacePostTileRadius,+ spaceTileCircleInset,+ spaceTileCornerStyles,+ spaceTileInnerRadius,+} from "styles/tiles";import { firstNameFrom } from "utils/display";import {- homeTileGridLayout,- homeTilePlacements,+ homeTileGap,+ homeTileLayout,maximumHomeTileCount,- usesHomeTileGrid,+ minimumHomeTileCanvasHeight,type HomeTilePlacement,} from "utils/home-tile-layout";import { createLoadedLocalPostPhoto } from "utils/local-post-photo";@@ -90,6 +97,8 @@ interface HomeScreenProps {image: SpaceDraftPostImage,caption: string,) => Promise<void>;+ onDeletePost?: (postId: number) => Promise<void>;+ onUpdatePostCaption?: (postId: number, caption: string) => Promise<void>;onLoadFriendAvatar?: (friend: FriendProfile) => Promise<string | null>;onLoadFriendPosts?: (friendSpaceId: string,@@ -276,7 +285,7 @@ interface FriendPostTileProps {photo: SpaceViewerPhoto,) => void;isTwoTileLayout?: boolean;- placement?: HomeTilePlacement;+ placement: HomeTilePlacement;posts: SpacePost[];showFriendRequestDetails?: boolean;}@@ -343,53 +352,25 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({isFriendRequestActionBusy ||(isRequestPending && !canOpenFriendRequest) ||Boolean(post && !postUnavailable && !isPhotoReady);- const avatarSize = placement ? Math.min(36, placement.size * 0.22) : "22%";- const requestActionSize = placement- ? showFriendRequestDetails- ? Math.min(44, Math.max(40, placement.size * 0.13))- : Math.min(40, Math.max(26, placement.size * 0.14))- : 26;+ const tileSize = Math.min(placement.width, placement.height);+ const tileRadius = Math.min(spacePostTileRadius, tileSize * 0.2);+ const avatarSize = Math.min(36, tileSize * 0.22);+ const requestActionSize = showFriendRequestDetails+ ? Math.min(44, Math.max(40, tileSize * 0.13))+ : Math.min(40, Math.max(26, tileSize * 0.14));const requestUsernameTextSize = isTwoTileLayout? 14: showFriendRequestDetails- ? placement- ? Math.min(18, Math.max(15, placement.size * 0.05))- : 15+ ? Math.min(18, Math.max(15, tileSize * 0.05)): 11;const requestActionTextSize = isTwoTileLayout? 12: showFriendRequestDetails? 13- : placement- ? Math.min(13, Math.max(10, placement.size * 0.04))- : 10;- const requestActionInset = placement- ? placement.size * 0.2 - requestActionSize / 2- : `calc(20% - ${requestActionSize / 2}px)`;+ : Math.min(13, Math.max(10, tileSize * 0.04));const requestCloseIconSize = 14;- const requestCloseInset = placement- ? Math.max(- 0,- placement.size * 0.2 -- requestActionSize / 2 -- (requestActionSize - requestCloseIconSize) / 2,- )- : 3;const requestButtonGap = 6;- const twoTileRequestActionTop =- isTwoTileLayout && placement- ? placement.size -- (placement.size * 0.2 - requestActionSize / 2) -- requestActionSize * 2 -- requestButtonGap- : undefined;- const twoTileRequestUsernameGap = placement- ? Math.min(60, Math.max(45, placement.size * 0.23))- : 45;- const twoTileRequestUsernameTop =- twoTileRequestActionTop === undefined- ? undefined- : Math.max(28, twoTileRequestActionTop - twoTileRequestUsernameGap);+ const stackRequestActions = placement.height >= 176;const hasMediaToLoad =isAvatarPending || Boolean(post && !postUnavailable && !imageUrl);@@ -489,15 +470,16 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({ref={rootRef}component="li"sx={{- aspectRatio: "1",+ ...spaceTileCornerStyles(tileRadius),listStyle: "none",minWidth: 0,- position: placement ? "absolute" : "relative",- transition: placement- ? "left 420ms cubic-bezier(0.2, 0.8, 0.2, 1), top 420ms cubic-bezier(0.2, 0.8, 0.2, 1), width 420ms cubic-bezier(0.2, 0.8, 0.2, 1)"- : "none",- width: placement?.size ?? "100%",- ...(placement && { left: placement.x, top: placement.y }),+ position: "absolute",+ transition:+ "left 420ms ease, top 420ms ease, width 420ms ease, height 420ms ease",+ width: placement.width,+ height: placement.height,+ left: placement.x,+ top: placement.y,"@media (prefers-reduced-motion: reduce)": {transition: "none",},@@ -526,10 +508,9 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({sx={{alignItems: "center",appearance: "none",- aspectRatio: "1",bgcolor: mediaPlaceholderColor,border: 0,- borderRadius: "20%",+ borderRadius: "inherit",color: textBase,cursor: isTileDisabled ? "default" : "pointer",display: "flex",@@ -654,9 +635,10 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({fontWeight: 600,left: "50%",lineHeight: "17px",- maxWidth: "calc(100% - 16px)",- px: isTwoTileLayout ? "9px" : "14px",- py: isTwoTileLayout ? "8px" : "7px",+ maxWidth:+ "calc(100% - 2 * var(--space-tile-padding))",+ px: "12px",+ py: "7px",position: "absolute",textAlign: "center",top: "50%",@@ -711,13 +693,11 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({? "2px solid rgba(255, 255, 255, 0.36)": "2px solid rgba(255, 255, 255, 0.28)",borderRadius: "50%",- bottom: "10%",+ bottom: spaceTileCircleInset(avatarSize),boxSizing: "border-box",cursor: canOpenAvatar ? "pointer" : "default",height: avatarSize,- left: "10%",- maxHeight: 36,- maxWidth: 36,+ left: spaceTileCircleInset(avatarSize),overflow: "hidden",p: 0,position: "absolute",@@ -753,8 +733,16 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({{friendRequestDirection == "received" && (<Boxsx={{+ boxSizing: "border-box",+ display: "flex",+ flexDirection: "column",+ gap: `${requestButtonGap}px`,height: "100%",inset: 0,+ p: "var(--space-tile-padding)",+ pt: showFriendRequestDetails+ ? "var(--space-tile-padding)"+ : `calc(${spaceTileCircleInset(requestActionSize)} + ${requestActionSize}px)`,pointerEvents: "none",position: "absolute",width: "100%",@@ -762,70 +750,73 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({}}><Box- component="span"- aria-hidden- title={`@${friend.username}`}sx={{- bgcolor: tileBadgeBackground,- borderRadius: "999px",- boxSizing: "border-box",- color: textBase,- display: "block",- fontFamily: '"Nunito", sans-serif',- fontSize: requestUsernameTextSize,- fontWeight: 800,- height: showFriendRequestDetails ? undefined : 24,- left: "50%",- lineHeight: showFriendRequestDetails- ? "20px"- : "24px",- maxWidth: "88%",- overflow: "hidden",- position: "absolute",- px: showFriendRequestDetails ? "11px" : "6px",- py: showFriendRequestDetails ? "6px" : 0,- textOverflow: "ellipsis",- textAlign: "center",- top: isTwoTileLayout- ? twoTileRequestUsernameTop- : showFriendRequestDetails- ? "30%"- : "50%",- transform: "translate(-50%, -50%)",- whiteSpace: "nowrap",+ alignItems: "center",+ display: "flex",+ flex: 1,+ flexDirection: "column",+ gap: "8px",+ justifyContent: "center",+ minHeight: 0,}}>- @{friend.username}- </Box>- {showFriendRequestDetails && !isTwoTileLayout && (<Boxcomponent="span"aria-hidden+ title={`@${friend.username}`}sx={{- color: textSecondary,- fontSize: 13,- fontWeight: 500,- left: "50%",- lineHeight: 1,- position: "absolute",- top: "40%",- transform: "translate(-50%, -50%)",+ bgcolor: tileBadgeBackground,+ borderRadius: "999px",+ boxSizing: "border-box",+ color: textBase,+ display: "block",+ fontFamily: '"Nunito", sans-serif',+ fontSize: requestUsernameTextSize,+ fontWeight: 800,+ height: showFriendRequestDetails+ ? undefined+ : 24,+ lineHeight: showFriendRequestDetails+ ? "20px"+ : "24px",+ flexShrink: 0,+ maxWidth: "100%",+ overflow: "hidden",+ px: showFriendRequestDetails ? "12px" : "8px",+ py: showFriendRequestDetails ? "6px" : 0,+ textOverflow: "ellipsis",+ textAlign: "center",whiteSpace: "nowrap",}}>- sent you a friend request+ @{friend.username}</Box>- )}+ {showFriendRequestDetails && !isTwoTileLayout && (+ <Box+ component="span"+ aria-hidden+ sx={{+ color: textSecondary,+ fontSize: 13,+ fontWeight: 500,+ lineHeight: 1.4,+ textAlign: "center",+ }}+ >+ sent you a friend request+ </Box>+ )}+ </Box><Boxsx={{- bottom: requestActionInset,display: "flex",- flexDirection: "column",+ flexDirection:+ showFriendRequestDetails && !stackRequestActions+ ? "row"+ : "column",+ flexShrink: 0,gap: `${requestButtonGap}px`,- left: requestActionInset,pointerEvents: "auto",- position: "absolute",- right: requestActionInset,}}><Box@@ -847,7 +838,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({alignItems: "center",bgcolor: green,border: 0,- borderRadius: `${requestActionSize / 2}px`,+ borderRadius: spaceTileInnerRadius,boxSizing: "border-box",color: spaceOnAccent,cursor: isFriendRequestActionBusy@@ -900,7 +891,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({alignItems: "center",bgcolor: spaceSurfaceHover,border: 0,- borderRadius: `${requestActionSize / 2}px`,+ borderRadius: spaceTileInnerRadius,boxSizing: "border-box",color: textBase,cursor: isFriendRequestActionBusy@@ -966,8 +957,8 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({p: 0,pointerEvents: "auto",position: "absolute",- right: requestCloseInset,- top: requestCloseInset,+ right: spaceTileCircleInset(requestActionSize),+ top: spaceTileCircleInset(requestActionSize),width: requestActionSize,"&:disabled": { opacity: 0.55 },"&:focus-visible": {@@ -1030,6 +1021,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({isHomeCacheLoading = false,showInstallPrompt = false,onCreatePost,+ onDeletePost,+ onUpdatePostCaption,onAcceptFriendRequest,onDiscardFriendRequest,onLoadFriendAvatar,@@ -1083,6 +1076,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({const isPostPhotoButtonDisabled =isPostPhotoOpening || !viewerSpaceId || !onCreatePost;const selectedPhotoFriendID = selectedViewer?.photo.friendID;+ const selectedPhotoPostId = selectedViewer?.photo.postId;const selectedPhotoIsOwn =Boolean(viewerSpaceId) && selectedPhotoFriendID == viewerSpaceId;const latestPostByFriendID = React.useMemo(() => {@@ -1151,21 +1145,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({updateSize();return () => observer.disconnect();}, []);- const postTilePlacements = homeTilePlacements(- orderedHomeItems.length,- postTileCanvasSize.width,- postTileCanvasSize.height,- );- const usesPostGrid = usesHomeTileGrid(orderedHomeItems.length);- const postGridLayout = homeTileGridLayout(+ const postLayout = homeTileLayout(orderedHomeItems.length,postTileCanvasSize.width,postTileCanvasSize.height,);- const emptyFriendTileSize = Math.min(- postTileCanvasSize.width,- Math.max(0, postTileCanvasSize.height - 64),- );const isInstallPromptEnabled =showInstallPrompt && !friendRequestSentToastName && !selectedViewer;const isHomeItemsLoading = isFriendsLoading || isFriendRequestsLoading;@@ -1476,6 +1460,29 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({},[onSetPostLiked],);+ const updateSelectedViewerPostCaption = async (+ postId: number,+ caption: string,+ ) => {+ await onUpdatePostCaption?.(postId, caption);+ const normalizedCaption = caption.trim() || undefined;+ setSelectedViewer((viewer) =>+ viewer+ ? {+ ...viewer,+ photo:+ viewer.photo.postId == postId+ ? { ...viewer.photo, caption: normalizedCaption }+ : viewer.photo,+ posts: viewer.posts?.map((post) =>+ post.postId == postId+ ? { ...post, caption: normalizedCaption }+ : post,+ ),+ }+ : viewer,+ );+ };React.useEffect(() => {if (!selectedViewerPosts || selectedViewerPostIndex == undefined)@@ -1494,7 +1501,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({selectedViewerPosts,]);const friendPostTileFor = (friend: FriendProfile, index: number) => {- const placement = usesPostGrid ? undefined : postTilePlacements[index];+ const placement = postLayout!.friends[index]!;const friendID = friend.spaceId ?? friend.id;const unreadFriendPosts = (unreadPostsByFriendID.get(friendID) ?? []@@ -1595,7 +1602,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({}onOpenPosts={openPostPhotos}isTwoTileLayout={orderedHomeItems.length == 2}- placement={usesPostGrid ? undefined : postTilePlacements[index]}+ placement={postLayout!.friends[index]!}posts={[]}showFriendRequestDetails={orderedHomeItems.length <= 2}/>@@ -1764,50 +1771,22 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({boxSizing: "border-box",display: "flex",flexDirection: "column",- gap: "16px",+ gap: `${homeTileGap}px`,minHeight: `calc(100svh - ${spaceHomeHeaderHeight}px)`,minWidth: 0,- pb: "calc(env(safe-area-inset-bottom) + 72px)",+ pb: "calc(env(safe-area-inset-bottom) + 16px)",px: homeHorizontalPadding,- pt: "12px",+ pt: "4px",width: "100%",}}>- <SpaceOwnPostTile- profile={profile}- post={ownLatestPost}- isLoading={isOwnLatestPostLoading}- isUnavailable={isOwnLatestPostUnavailable}- isNewPostDisabled={isPostPhotoButtonDisabled}- onLoadPostImage={onLoadPostImage}- onNewPost={openPostPhotoPicker}- onOpenProfile={onOpenProfile}- onOpenPost={(imageUrl) => {- if (!ownLatestPost || !profile) return;-- const self = {- ...profile,- id: ownLatestPost.spaceId,- friendsCount: friends.length,- };- openPostPhotos(- self,- [ownLatestPost],- viewerPhotoForPost(- ownLatestPost,- self,- profile.avatarUrl,- imageUrl,- ),- true,- );- }}- /><Boxref={postTileCanvasRef}sx={{flex: "1 1 auto",- minHeight: 320,+ minHeight: minimumHomeTileCanvasHeight(+ orderedHomeItems.length,+ ),position: "relative",width: "100%",}}@@ -1826,37 +1805,19 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({<SpaceLoadingSpinner ariaLabel="Loading friends and requests" />)}</Box>- ) : orderedHomeItems.length > 0 ? (- <Box- component="ul"- aria-label="Friends and friend requests"- sx={{- display: usesPostGrid ? "grid" : "block",- gap: postGridLayout- ? `${postGridLayout.gap}px`- : undefined,- gridTemplateColumns: postGridLayout- ? `repeat(3, ${postGridLayout.size}px)`- : undefined,- gridTemplateRows: postGridLayout- ? `repeat(${postGridLayout.rows}, ${postGridLayout.size}px)`- : undefined,- height: "100%",- m: 0,- minHeight: 0,- p: 0,- placeContent: usesPostGrid- ? "center"- : undefined,- position: "relative",- width: "100%",- }}- >- {((usesPostGrid && postGridLayout) ||- (!usesPostGrid &&- postTilePlacements.length ==- orderedHomeItems.length)) &&- orderedHomeItems.map((item, index) =>+ ) : (+ postLayout && (+ <Box+ component="ul"+ aria-label="Friends and friend requests"+ sx={{+ inset: 0,+ m: 0,+ p: 0,+ position: "absolute",+ }}+ >+ {orderedHomeItems.map((item, index) =>item.type == "friend"? friendPostTileFor(item.friend,@@ -1867,122 +1828,54 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({index,),)}- </Box>- ) : (- <Box- sx={{- alignItems: "center",- display: "flex",- fontFamily:- '"Inter Variable", Inter, sans-serif',- height: "100%",- inset: 0,- justifyContent: "center",- position: "absolute",- width: "100%",- }}- >- {emptyFriendTileSize > 0 && (- <Box- sx={{- alignItems: "flex-start",- bgcolor: spaceSurface,- border: 0,- borderRadius: "24px",- boxSizing: "border-box",- color: "#FFF",- display: "flex",- flex: "0 0 auto",- flexDirection: "column",- fontFamily:- '"Inter Variable", Inter, sans-serif',- gap: "7px",- height: "100%",- justifyContent: "flex-start",- overflow: "hidden",- p: "24px",- position: "relative",- width: "100%",- }}- >- <Box- sx={{- alignItems: "center",- display: "flex",- flexDirection: "column",- position: "relative",- width: "100%",- zIndex: 1,- }}- >- <Box- component="h1"- sx={{- color: "#FFF",- fontFamily:- '"Nunito", "Inter Variable", sans-serif',- fontSize: 25,- fontWeight: 800,- lineHeight: "30px",- m: 0,- maxWidth: 260,- textAlign: "center",- }}- >- Invite your close friends and- family- </Box>- <Box- component="p"- sx={{- color: "rgba(255, 255, 255, 0.84)",- fontSize: 14,- fontWeight: 500,- lineHeight: "20px",- m: 0,- mt: "10px",- maxWidth: 260,- textAlign: "center",- }}- >- Each person gets a little spot- of their own in your Space.- </Box>- <Box sx={{ mt: "24px" }}>- <SpaceShareInviteButton- profileLink={profileLink}- variant="secondary"- onShareError={(error) =>- log.error(- "Failed to share Space invite link",- error,- )- }- />- </Box>- </Box>- <Box- component="img"- alt=""- aria-hidden- src="/images/ducky-space.svg"- sx={{- alignSelf: "center",- flex: "1 1 0",- maxHeight: 160,- maxWidth: 180,- minHeight: 0,- mt: "16px",- objectFit: "contain",- pointerEvents: "none",- width: "64%",+ {postLayout.addFriend && (+ <SpaceAddFriendTile+ placement={postLayout.addFriend}+ variant={+ postLayout.addFriendVariant+ }+ onClick={() => {+ if (profileLink)+ openSpaceShareLinkDialog(+ profileLink,+ );}}/>- </Box>- )}- </Box>+ )}+ </Box>+ ))}</Box>+ <SpaceOwnPostTile+ profile={profile}+ post={ownLatestPost}+ isLoading={isOwnLatestPostLoading}+ isUnavailable={isOwnLatestPostUnavailable}+ isNewPostDisabled={isPostPhotoButtonDisabled}+ onLoadPostImage={onLoadPostImage}+ onNewPost={openPostPhotoPicker}+ onOpenProfile={onOpenProfile}+ onOpenPost={(imageUrl) => {+ if (!ownLatestPost || !profile) return;++ const self = {+ ...profile,+ id: ownLatestPost.spaceId,+ friendsCount: friends.length,+ };+ openPostPhotos(+ self,+ [ownLatestPost],+ viewerPhotoForPost(+ ownLatestPost,+ self,+ profile.avatarUrl,+ imageUrl,+ ),+ true,+ );+ }}+ /></Box>{selectedContact && (<FriendQuickActionsDialog@@ -2024,6 +1917,18 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({: undefined}onClose={closeSelectedPhoto}+ onDeletePost={+ selectedPhotoIsOwn &&+ selectedPhotoPostId &&+ onDeletePost+ ? () => onDeletePost(selectedPhotoPostId)+ : undefined+ }+ onUpdatePostCaption={+ selectedPhotoIsOwn && onUpdatePostCaption+ ? updateSelectedViewerPostCaption+ : undefined+ }onOpenProfile={selectedPhotoIsOwn && onOpenProfile? () => {diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex da9f1c4607..d2c966c3ff 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -77,7 +77,7 @@ const profileCoverHeight =profileHeaderHeight + profileAvatarTopOffset + profileAvatarSize / 2;const photoMasonryGap = "3px";const photoMasonryPlaceholderBackground = spaceSurface;-const photoMasonryRadius = "12px";+const photoMasonryRadius = "16px";const profileCoverRadius = "12px";const photoMasonryLoadRootMargin = "800px 0px";const publicPhotoMasonryLoadRootMargin = "400px 0px";diff --git a/web/apps/space/src/styles/tiles.ts b/web/apps/space/src/styles/tiles.tsnew file mode 100644index 0000000000..dd080e7a11--- /dev/null+++ b/web/apps/space/src/styles/tiles.ts@@ -0,0 +1,13 @@+export const spacePostTileRadius = 28;++export const spaceTileCornerStyles = (radius: number) => ({+ "--space-tile-radius": `${radius}px`,+ "--space-tile-padding": `${radius / 2}px`,+ borderRadius: "var(--space-tile-radius)",+});++export const spaceTileInnerRadius =+ "calc(var(--space-tile-radius) - var(--space-tile-padding))";++export const spaceTileCircleInset = (diameter: number) =>+ `max(var(--space-tile-padding), calc(var(--space-tile-radius) - ${diameter / 2}px))`;diff --git a/web/apps/space/src/utils/home-tile-layout.ts b/web/apps/space/src/utils/home-tile-layout.tsindex 0fbdbf7d88..10b23587dd 100644--- a/web/apps/space/src/utils/home-tile-layout.ts+++ b/web/apps/space/src/utils/home-tile-layout.ts@@ -1,126 +1,65 @@-import { maximumSpaceFriendCount } from "utils/friend-limits";+import { maximumSpaceFriendCount } from "./friend-limits";-interface TileSlot {- column: number;- row: number;-}--const gridFriendCountStart = 9;-const gridColumnCount = 3;-const tileGapRatio = 0.1;-const verticalInset = 16;+export const homeTileGap = 12;export const maximumHomeTileCount = maximumSpaceFriendCount;-export const usesHomeTileGrid = (count: number) =>- count >= gridFriendCountStart && count <= maximumHomeTileCount;-export interface HomeTilePlacement {- size: number;+ height: number;+ width: number;x: number;y: number;}-export interface HomeTileGridLayout {- gap: number;- rows: number;- size: number;-}--const tileSlotsForCount = (count: number) => {- if (count == 1) {- return { columns: 1, rows: 1, slots: [{ column: 0, row: 0 }] };- }- if (count == 2) {- return {- columns: 1,- rows: 2,- slots: [- { column: 0, row: 0 },- { column: 0, row: 1 },- ],- };- }- if (count == 3) {- return {- columns: 2,- rows: 2,- slots: [- { column: 0.5, row: 0 },- { column: 0, row: 1 },- { column: 1, row: 1 },- ],- };- }-- const columns = 2;- const rows = Math.ceil(count / columns);- const stagger = count % columns ? 0.5 : 0;- const slots: TileSlot[] = [];- for (let index = 0; index < count; index++) {- const column = index % columns;- slots.push({- column,- row: Math.floor(index / columns) + column * stagger,- });- }- return { columns, rows, slots };-};+export type AddFriendTileVariant = "empty" | "tile";-const layoutDimensions = (columns: number, rows: number) => ({- height: rows + (rows - 1) * tileGapRatio,- width: columns + (columns - 1) * tileGapRatio,-});+const friendColumnCount = (count: number) =>+ count == maximumHomeTileCount ? 3 : count <= 2 ? 1 : 2;-export const homeTileGridLayout = (- count: number,- canvasWidth: number,- canvasHeight: number,-): HomeTileGridLayout | undefined => {- if (!usesHomeTileGrid(count) || canvasWidth <= 0 || canvasHeight <= 0) {- return undefined;- }+const friendRowCount = (count: number) =>+ Math.ceil(count / friendColumnCount(count));- const rows = Math.ceil(count / gridColumnCount);- const layout = layoutDimensions(gridColumnCount, rows);- const availableHeight = Math.max(0, canvasHeight - 2 * verticalInset);- const size = Math.min(- canvasWidth / layout.width,- availableHeight / layout.height,- );- return { gap: size * tileGapRatio, rows, size };+export const minimumHomeTileCanvasHeight = (count: number) => {+ const rows = friendRowCount(count);+ return Math.max(320, rows * 104 + Math.max(0, rows - 1) * homeTileGap);};-export const homeTilePlacements = (+export const homeTileLayout = (count: number,canvasWidth: number,canvasHeight: number,-): HomeTilePlacement[] => {- if (- count < 1 ||- count > maximumHomeTileCount ||- usesHomeTileGrid(count) ||- canvasWidth <= 0 ||- canvasHeight <= 0- ) {- return [];+):+ | {+ friends: HomeTilePlacement[];+ addFriend?: HomeTilePlacement;+ addFriendVariant: AddFriendTileVariant;+ }+ | undefined => {+ if (canvasWidth <= 0 || canvasHeight <= 0) return undefined;++ if (count == 0) {+ return {+ friends: [],+ addFriend: { x: 0, y: 0, width: canvasWidth, height: canvasHeight },+ addFriendVariant: "empty",+ };}- const { columns, rows, slots } = tileSlotsForCount(count);- const layout = layoutDimensions(columns, rows);- const availableHeight = Math.max(0, canvasHeight - 2 * verticalInset);- const size = Math.min(- canvasWidth / layout.width,- availableHeight / layout.height,- );- const tileStep = size * (1 + tileGapRatio);- const renderedWidth = size + tileStep * (columns - 1);- const renderedHeight = size * layout.height;- const originX = (canvasWidth - renderedWidth) / 2;- const originY = (canvasHeight - renderedHeight) / 2;- return slots.map(({ column, row }) => ({- size,- x: originX + column * tileStep,- y: originY + row * tileStep,- }));+ const columns = friendColumnCount(count);+ const rows = friendRowCount(count);+ const width = (canvasWidth - (columns - 1) * homeTileGap) / columns;+ const height = (canvasHeight - (rows - 1) * homeTileGap) / rows;+ const placementFor = (index: number): HomeTilePlacement => ({+ x: (index % columns) * (width + homeTileGap),+ y: Math.floor(index / columns) * (height + homeTileGap),+ width,+ height,+ });+ return {+ friends: Array.from({ length: count }, (_, index) =>+ placementFor(index),+ ),+ addFriend: [3, 5, 7].includes(count) ? placementFor(count) : undefined,+ addFriendVariant: "tile",+ };};diff --git a/web/apps/space/src/utils/post-image.ts b/web/apps/space/src/utils/post-image.tsindex 5a3fefbd48..dc151f1f2a 100644--- a/web/apps/space/src/utils/post-image.ts+++ b/web/apps/space/src/utils/post-image.ts@@ -2,6 +2,7 @@ import { lowercaseExtension, nameAndExtension } from "ente-base/file-name";import { isHEICExtension } from "ente-media/formats";import { heicToJPEG } from "ente-media/heic-convert";import { thumbHashBase64FromCanvas } from "utils/thumbhash";+import defaultCoverImage from "../../public/images/default-cover-image.jpg";export interface PreparedSpaceImage {file: File;@@ -47,7 +48,7 @@ export const spaceCoverImageInputAccept = spaceAvatarImageInputAccept;export const spacePostImageInputAccept ="image/jpeg,image/png,image/webp,image/heic,image/heif,.jpg,.jpeg,.png,.webp,.heic,.heif";-export const spaceDefaultCoverImagePath = "/images/default-cover-image.jpg";+export const spaceDefaultCoverImagePath = defaultCoverImage.src;export const spaceProfileCoverAspectRatio = 39 / 17;const spaceAvatarImageMaxEdge = 512;const spaceCoverImageMaxWidth = 1170;diff --git a/web/apps/space/tests/home-tile-layout.test.ts b/web/apps/space/tests/home-tile-layout.test.tsnew file mode 100644index 0000000000..43cb1baf7b--- /dev/null+++ b/web/apps/space/tests/home-tile-layout.test.ts@@ -0,0 +1,115 @@+import { expect, test } from "vitest";+import {+ homeTileLayout,+ minimumHomeTileCanvasHeight,+} from "../src/utils/home-tile-layout";++test("the empty state gives the add-friend tile the whole canvas", () => {+ expect(homeTileLayout(0, 358, 520)).toEqual({+ friends: [],+ addFriend: { x: 0, y: 0, width: 358, height: 520 },+ addFriendVariant: "empty",+ });+});++test.each([1, 2])(+ "%i friends fill the canvas without an add-friend tile",+ (count) => {+ const layout = homeTileLayout(count, 358, 520)!;+ expect(layout.friends).toHaveLength(count);+ for (const friend of layout.friends) {+ expect(friend.x).toBe(0);+ expect(friend.width).toBe(358);+ }+ expect(layout.friends[0]!.y).toBe(0);+ const lastFriend = layout.friends.at(-1)!;+ expect(lastFriend.y + lastFriend.height).toBe(520);+ expect(layout.addFriend).toBeUndefined();+ },+);++test.each([3, 5, 7])(+ "%i friends use the last cell for adding a friend",+ (count) => {+ const layout = homeTileLayout(count, 358, 600)!;+ const lastFriend = layout.friends.at(-1)!;+ expect(layout.addFriend).toEqual({+ x: 185,+ y: lastFriend.y,+ width: lastFriend.width,+ height: lastFriend.height,+ });+ expect(lastFriend.x).toBe(0);+ expect(layout.addFriendVariant).toBe("tile");+ },+);++test.each([4, 6, 8])(+ "%i friends fill two columns without an add-friend tile",+ (count) => {+ const layout = homeTileLayout(count, 358, 600)!;+ expect(new Set(layout.friends.map(({ x }) => x))).toEqual(+ new Set([0, 185]),+ );+ expect(new Set(layout.friends.map(({ y }) => y)).size).toBe(count / 2);+ const lastFriend = layout.friends.at(-1)!;+ expect(lastFriend.y + lastFriend.height).toBe(600);+ expect(layout.addFriend).toBeUndefined();+ },+);++test("nine friends fill a three-by-three grid without an add tile", () => {+ const layout = homeTileLayout(9, 360, 600)!;+ expect(layout.addFriend).toBeUndefined();+ expect(layout.friends).toHaveLength(9);+ expect(new Set(layout.friends.map(({ x }) => x))).toEqual(+ new Set([0, 124, 248]),+ );+ expect(new Set(layout.friends.map(({ y }) => y))).toEqual(+ new Set([0, 204, 408]),+ );+ for (const friend of layout.friends) {+ expect(friend.width).toBe(112);+ expect(friend.height).toBe(192);+ }+ expect(layout.friends.at(-1)).toEqual({+ x: 248,+ y: 408,+ width: 112,+ height: 192,+ });+});++test.each([288, 358])(+ "all layouts fill a %ipx canvas without overlapping",+ (width) => {+ for (let count = 0; count <= 9; count++) {+ const height = minimumHomeTileCanvasHeight(count);+ const layout = homeTileLayout(count, width, height)!;+ const tiles = [+ ...layout.friends,+ ...(layout.addFriend ? [layout.addFriend] : []),+ ];+ expect(tiles).toHaveLength([1, 1, 2, 4, 4, 6, 6, 8, 8, 9][count]!);+ expect(+ Math.max(...tiles.map((tile) => tile.x + tile.width)),+ ).toBeCloseTo(width);+ expect(+ Math.max(...tiles.map((tile) => tile.y + tile.height)),+ ).toBeCloseTo(height);+ for (const [index, tile] of tiles.entries()) {+ expect(tile.x).toBeGreaterThanOrEqual(0);+ expect(tile.y).toBeGreaterThanOrEqual(0);+ expect(tile.height).toBeGreaterThanOrEqual(104);+ for (const other of tiles.slice(index + 1)) {+ expect(+ tile.x + tile.width <= other.x ||+ other.x + other.width <= tile.x ||+ tile.y + tile.height <= other.y ||+ other.y + other.height <= tile.y,+ ).toBe(true);+ }+ }+ }+ },+);