Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Improve Space empty state

Anand Baburajan6f8b73325f07
diff --git a/web/apps/space/src/components/PostUnreadBadge.tsx b/web/apps/space/src/components/PostUnreadBadge.tsx
index 8ba06a9692..e5abaf298b 100644
--- a/web/apps/space/src/components/PostUnreadBadge.tsx
+++ b/web/apps/space/src/components/PostUnreadBadge.tsx
@@ -4,12 +4,14 @@ import React from "react";
interface SpacePostBadgeProps extends React.PropsWithChildren {
backgroundColor: string;
color: string;
+ placement?: "center" | "top-right";
}
export const SpacePostBadge: React.FC<SpacePostBadgeProps> = ({
backgroundColor,
children,
color,
+ placement = "top-right",
}) => (
<Box
component="span"
@@ -21,20 +23,25 @@ export const SpacePostBadge: React.FC<SpacePostBadgeProps> = ({
color,
display: "inline-flex",
fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 10,
+ fontSize: placement == "center" ? 12 : 10,
fontVariantNumeric: "tabular-nums",
fontWeight: 700,
- height: 20,
+ height: placement == "center" ? 24 : 20,
justifyContent: "center",
lineHeight: 1,
minWidth: 20,
pointerEvents: "none",
position: "absolute",
- px: "7px",
- right: "10%",
- top: "10%",
+ px: placement == "center" ? "10px" : "7px",
whiteSpace: "nowrap",
zIndex: 1,
+ ...(placement == "center"
+ ? {
+ left: "50%",
+ top: "50%",
+ transform: "translate(-50%, -50%)",
+ }
+ : { right: "10%", top: "10%" }),
}}
>
{children}
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 133b9c112a..06c68b49ee 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -9,7 +9,7 @@ import {
patchCachedSpaceHomePost,
refreshSpaceHomePosts,
} from "services/home-posts";
-import { consumeSentSpaceInviteFriend } from "services/invite";
+import { consumeSentSpaceInviteFriend, spaceInviteURL } from "services/invite";
import { loadExistingSpaceId } from "services/profile";
import {
loadCurrentFriendAvatarURL,
@@ -204,6 +204,11 @@ const Page: React.FC = () => {
isLatestPostsLoading={isLatestPostsLoading}
isFriendsLoading={isFriendsLoading}
profile={profile}
+ profileLink={
+ profile
+ ? spaceInviteURL({ spaceUsername: profile.username })
+ : undefined
+ }
viewerSpaceId={spaceId ?? profile?.spaceId}
showInstallPrompt={
profileLoadStatus == "ready" &&
diff --git a/web/apps/space/src/pages/index.tsx b/web/apps/space/src/pages/index.tsx
index b154bb0298..135faeac18 100644
--- a/web/apps/space/src/pages/index.tsx
+++ b/web/apps/space/src/pages/index.tsx
@@ -266,10 +266,10 @@ const PublicFriendRequestScreen: React.FC<PublicFriendRequestScreenProps> = ({
sx={{
alignItems: "center",
appearance: "none",
- bgcolor: { xs: "white", sm: "black" },
+ bgcolor: "white",
border: 0,
borderRadius: "24px",
- color: { xs: "black", sm: "white" },
+ color: "black",
cursor: isAddingFriend ? "default" : "pointer",
display: "flex",
fontFamily: '"Inter Variable", Inter, sans-serif',
@@ -283,7 +283,7 @@ const PublicFriendRequestScreen: React.FC<PublicFriendRequestScreenProps> = ({
width: "min(100%, 300px)",
"&:hover": isAddingFriend
? undefined
- : { bgcolor: { xs: "#F4F4F4", sm: "#121212" } },
+ : { bgcolor: "#F4F4F4" },
"&:focus-visible": {
outline: "2px solid rgba(255 255 255 / 0.88)",
outlineOffset: 3,
diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsx
new file mode 100644
index 0000000000..0cfc047bfd
--- /dev/null
+++ b/web/apps/space/src/pages/layout-demo.tsx
@@ -0,0 +1,278 @@
+import { ArrowLeft02Icon, ArrowRight01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box } from "@mui/material";
+import { SpacePostFloatingActionButton } from "components/PostFloatingActionButton";
+import React from "react";
+import { FriendPostCircle } from "screens/HomeScreen";
+import { spaceAppBackground } from "styles/colors";
+import {
+ homeCircleGridLayout,
+ homeCirclePlacements,
+ usesHomeCircleGrid,
+ type HomeCirclePlacement,
+} from "utils/home-circle-layout";
+
+const headerChromeColor = "#202825";
+const headerHeight = 64;
+const maximumFriendCount = 15;
+
+interface CanvasSize {
+ height: number;
+ width: number;
+}
+
+interface LayoutDemoPostProps {
+ index: number;
+ placement?: HomeCirclePlacement;
+}
+
+const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({
+ index,
+ placement,
+}) => (
+ <FriendPostCircle
+ avatarUrl={null}
+ friend={{
+ friendsCount: 0,
+ fullName: `Friend ${index + 1}`,
+ id: `demo-friend-${index + 1}`,
+ username: `friend${index + 1}`,
+ }}
+ isAvatarPending={false}
+ isLoading={false}
+ isRead
+ isUnavailable={false}
+ onOpenPosts={() => undefined}
+ placement={placement}
+ posts={[]}
+ />
+);
+
+const LayoutDemoPage: React.FC = () => {
+ const [friendCount, setFriendCount] = React.useState(1);
+ const [canvasSize, setCanvasSize] = React.useState<CanvasSize>({
+ height: 0,
+ width: 0,
+ });
+ const canvasRef = React.useRef<HTMLDivElement | null>(null);
+
+ React.useEffect(() => {
+ const canvas = canvasRef.current;
+ if (!canvas) return;
+
+ const updateSize = () => {
+ const { height, width } = canvas.getBoundingClientRect();
+ setCanvasSize({ height, width });
+ };
+ const observer = new ResizeObserver(updateSize);
+ observer.observe(canvas);
+ updateSize();
+ return () => observer.disconnect();
+ }, []);
+
+ React.useEffect(() => {
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (event.key == "ArrowLeft") {
+ setFriendCount((count) => Math.max(1, count - 1));
+ } else if (event.key == "ArrowRight") {
+ setFriendCount((count) =>
+ Math.min(maximumFriendCount, count + 1),
+ );
+ }
+ };
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
+ }, []);
+
+ const usesGrid = usesHomeCircleGrid(friendCount);
+ const placements = homeCirclePlacements(
+ friendCount,
+ canvasSize.width,
+ canvasSize.height,
+ );
+ const gridLayout = homeCircleGridLayout(
+ friendCount,
+ canvasSize.width,
+ canvasSize.height,
+ );
+
+ return (
+ <Box
+ component="main"
+ sx={{
+ background: spaceAppBackground,
+ color: "#FFF",
+ display: "grid",
+ minHeight: "100svh",
+ overflowX: "hidden",
+ placeItems: { xs: "stretch", sm: "start center" },
+ position: "relative",
+ }}
+ >
+ <Box
+ sx={{
+ boxSizing: "border-box",
+ maxWidth: "100%",
+ minHeight: "100svh",
+ minWidth: 0,
+ mx: "auto",
+ overflowX: "hidden",
+ position: "relative",
+ width: "100%",
+ "@media (min-width: 600px)": { maxWidth: 390 },
+ }}
+ >
+ <Box
+ component="header"
+ sx={{
+ alignItems: "center",
+ display: "grid",
+ gridTemplateColumns: "48px minmax(0, 1fr) 48px",
+ height: headerHeight,
+ px: "10px",
+ }}
+ >
+ <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: headerChromeColor,
+ border: 0,
+ borderRadius: "50%",
+ color: "#FFF",
+ 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
+ sx={{
+ alignItems: "center",
+ bgcolor: headerChromeColor,
+ borderRadius: "999px",
+ display: "flex",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ height: 36,
+ justifySelf: "center",
+ px: "15px",
+ }}
+ >
+ <Box
+ component="img"
+ alt="Space"
+ src="/images/space.svg"
+ sx={{ display: "block", height: 18, width: "auto" }}
+ />
+ </Box>
+ <Box
+ component="button"
+ type="button"
+ aria-label="Show one more friend"
+ disabled={friendCount == maximumFriendCount}
+ onClick={() =>
+ setFriendCount((count) =>
+ Math.min(maximumFriendCount, count + 1),
+ )
+ }
+ sx={{
+ alignItems: "center",
+ appearance: "none",
+ bgcolor: headerChromeColor,
+ border: 0,
+ borderRadius: "50%",
+ color: "#FFF",
+ cursor:
+ friendCount == maximumFriendCount
+ ? "default"
+ : "pointer",
+ display: "flex",
+ height: 36,
+ justifyContent: "center",
+ justifySelf: "end",
+ opacity:
+ friendCount == maximumFriendCount ? 0.3 : 1,
+ p: 0,
+ width: 36,
+ }}
+ >
+ <HugeiconsIcon
+ icon={ArrowRight01Icon}
+ size={22}
+ strokeWidth={2.2}
+ />
+ </Box>
+ </Box>
+ <Box
+ sx={{
+ boxSizing: "border-box",
+ display: "flex",
+ flexDirection: "column",
+ height: `calc(100svh - ${headerHeight}px)`,
+ minWidth: 0,
+ pb: "calc(env(safe-area-inset-bottom) + 112px)",
+ pt: `calc(env(safe-area-inset-bottom) + 112px - ${headerHeight}px)`,
+ px: "16px",
+ width: "100%",
+ }}
+ >
+ <Box
+ ref={canvasRef}
+ 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: 0,
+ placeContent: usesGrid ? "center" : undefined,
+ position: "relative",
+ width: "100%",
+ }}
+ >
+ {usesGrid && gridLayout
+ ? Array.from(
+ { length: friendCount },
+ (_, index) => (
+ <LayoutDemoPost
+ key={index}
+ index={index}
+ />
+ ),
+ )
+ : placements.map((placement, index) => (
+ <LayoutDemoPost
+ key={index}
+ index={index}
+ placement={placement}
+ />
+ ))}
+ </Box>
+ </Box>
+ <SpacePostFloatingActionButton />
+ </Box>
+ </Box>
+ );
+};
+
+export default LayoutDemoPage;
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 1847cd8dfc..ea3e1f16f5 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -104,6 +104,7 @@ interface HomeScreenProps {
onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;
onWaveFriend?: (friend: FriendProfile) => Promise<void>;
profile: SetupProfile | null;
+ profileLink?: string;
viewerSpaceId?: string;
}
@@ -263,7 +264,7 @@ interface FriendPostCircleProps {
posts: SpacePost[];
}
-const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
+export const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
avatarUrl,
friend,
imageUrl,
@@ -631,12 +632,21 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
}}
/>
)}
- {(!post || postUnavailable) && (
+ {!isLoading && !post && (
+ <SpacePostBadge
+ backgroundColor="rgba(0, 0, 0, 0.18)"
+ color={textSecondary}
+ placement="center"
+ >
+ No posts yet
+ </SpacePostBadge>
+ )}
+ {!isLoading && postUnavailable && (
<SpacePostBadge
backgroundColor="rgba(255, 255, 255, 0.1)"
color={textSecondary}
>
- {postUnavailable ? "Unavailable" : "No posts yet"}
+ Unavailable
</SpacePostBadge>
)}
{!isRead && <SpacePostUnreadBadge count={posts.length} />}
@@ -659,7 +669,7 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
bgcolor: "transparent",
border: displayAvatarUrl
? "2px solid rgba(255, 255, 255, 0.36)"
- : "2px solid rgba(255, 255, 255, 0.12)",
+ : "2px solid rgba(255, 255, 255, 0.28)",
borderRadius: "50%",
bottom: "10%",
boxSizing: "border-box",
@@ -692,8 +702,8 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
aria-hidden
sx={{
alignItems: "center",
- bgcolor: "rgba(53, 65, 61, 0.72)",
- color: "rgba(244, 244, 244, 0.72)",
+ bgcolor: "rgba(255, 255, 255, 0.18)",
+ color: "rgba(255, 255, 255, 0.92)",
display: "flex",
fontSize: 14,
fontWeight: 700,
@@ -800,6 +810,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onSetPostLiked,
onWaveFriend,
profile,
+ profileLink,
viewerSpaceId,
}) => {
const [selectedViewer, setSelectedViewer] =
@@ -811,6 +822,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
useState(false);
const [isDraftPostExiting, setIsDraftPostExiting] = useState(false);
const [isPostPhotoOpening, setIsPostPhotoOpening] = useState(false);
+ const [inviteShareStatus, setInviteShareStatus] = useState<
+ "idle" | "sharing" | "copied"
+ >("idle");
const [loadedFriendAvatarURLsByKey, setLoadedFriendAvatarURLsByKey] =
useState<Record<string, string | null>>({});
const [loadedPostImageURLsByKey, setLoadedPostImageURLsByKey] = useState<
@@ -867,6 +881,14 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
[friends],
);
React.useEffect(() => setOpenedPostIds(new Set()), [viewerSpaceId]);
+ React.useEffect(() => {
+ if (inviteShareStatus != "copied") return;
+ const timeoutID = window.setTimeout(
+ () => setInviteShareStatus("idle"),
+ spaceToastAutoDismissDurationMs,
+ );
+ return () => window.clearTimeout(timeoutID);
+ }, [inviteShareStatus]);
React.useEffect(() => {
const canvas = postCircleCanvasRef.current;
if (!canvas) return;
@@ -891,6 +913,10 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
postCircleCanvasSize.width,
postCircleCanvasSize.height,
);
+ const emptyFriendTileSize = Math.min(
+ postCircleCanvasSize.width,
+ Math.max(0, postCircleCanvasSize.height - 64),
+ );
const isInstallPromptEnabled =
showInstallPrompt && !friendRequestSentToastName && !selectedViewer;
const showUnreadIndicator = hasUnreadMessages === true;
@@ -912,6 +938,36 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
postInputRef.current?.click();
};
+ const shareInviteLink = async () => {
+ if (!profileLink || inviteShareStatus == "sharing") return;
+
+ setInviteShareStatus("sharing");
+ try {
+ if (typeof navigator.share == "function") {
+ try {
+ await navigator.share({ url: profileLink });
+ return;
+ } catch (error) {
+ if (
+ error instanceof DOMException &&
+ error.name == "AbortError"
+ ) {
+ return;
+ }
+ log.warn("Failed to share Space invite link", error);
+ }
+ }
+
+ await navigator.clipboard.writeText(profileLink);
+ setInviteShareStatus("copied");
+ } catch (error) {
+ log.error("Failed to copy Space invite link", error);
+ } finally {
+ setInviteShareStatus((status) =>
+ status == "sharing" ? "idle" : status,
+ );
+ }
+ };
const markPostRead = React.useCallback(
(post: Pick<SpacePost, "postId" | "timestampMs">) => {
if (!viewerSpaceId) return;
@@ -1629,24 +1685,124 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
</Box>
) : (
<Box
- component="p"
sx={{
alignItems: "center",
- color: textSecondary,
display: "flex",
fontFamily:
'"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
height: "100%",
justifyContent: "center",
- lineHeight: "20px",
- m: 0,
- px: 3,
- textAlign: "center",
+ width: "100%",
}}
>
- Your friends’ latest posts will show up here.
+ {emptyFriendTileSize > 0 && (
+ <Box
+ sx={{
+ alignItems: "center",
+ aspectRatio: "1",
+ bgcolor: mediaPlaceholderColor,
+ backgroundImage:
+ 'url("/images/invite-bg.jpg")',
+ backgroundPosition: "center",
+ backgroundSize: "cover",
+ border: 0,
+ borderRadius: "20%",
+ color: textBase,
+ display: "flex",
+ flex: "0 0 auto",
+ flexDirection: "column",
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ gap: "7px",
+ height: emptyFriendTileSize,
+ justifyContent: "center",
+ overflow: "hidden",
+ p: 0,
+ position: "relative",
+ width: emptyFriendTileSize,
+ }}
+ >
+ <Box
+ component="span"
+ sx={{
+ color: textBase,
+ fontFamily:
+ '"Nunito", "Inter Variable", sans-serif',
+ fontSize: 19,
+ fontWeight: 800,
+ lineHeight: "24px",
+ whiteSpace: "nowrap",
+ }}
+ >
+ Invite your friends and family
+ </Box>
+ <Box
+ component="span"
+ sx={{
+ color: "rgba(244, 244, 244, 0.72)",
+ fontSize: 13,
+ fontWeight: 500,
+ lineHeight: "18px",
+ textAlign: "center",
+ whiteSpace: "nowrap",
+ }}
+ >
+ Each friend gets their own tile with
+ their latest post
+ </Box>
+ <Box
+ component="button"
+ type="button"
+ aria-live="polite"
+ disabled={
+ !profileLink ||
+ inviteShareStatus == "sharing"
+ }
+ onClick={() =>
+ void shareInviteLink()
+ }
+ sx={{
+ appearance: "none",
+ bgcolor:
+ "rgba(255, 255, 255, 0.94)",
+ border: 0,
+ borderRadius: "999px",
+ color: "#101815",
+ cursor: profileLink
+ ? "pointer"
+ : "default",
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 700,
+ lineHeight: "18px",
+ minWidth: 184,
+ mt: "15px",
+ px: "16px",
+ py: "9px",
+ transition:
+ "background-color 120ms ease, transform 120ms ease",
+ "&:active": profileLink
+ ? {
+ transform:
+ "scale(0.98)",
+ }
+ : undefined,
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ "&:hover": profileLink
+ ? { bgcolor: "white" }
+ : undefined,
+ }}
+ >
+ {inviteShareStatus == "copied"
+ ? "Copied"
+ : "Invite your first friend"}
+ </Box>
+ </Box>
+ )}
</Box>
)}
</Box>