Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Redesign Space home as friend constellation

Anand Baburajan2939df2a2928
diff --git a/web/apps/space/src/components/MessagesPage.tsx b/web/apps/space/src/components/MessagesPage.tsx
index a47672e817..b3517e3946 100644
--- a/web/apps/space/src/components/MessagesPage.tsx
+++ b/web/apps/space/src/components/MessagesPage.tsx
@@ -117,7 +117,6 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({
profileLoadStatus,
setFriends,
setPendingPostPhotoFile,
- setSkipNextHomeFeedSkeleton,
} = useSpaceAppState();
const [conversations, setConversations] = React.useState<
SpaceMessageConversation[]
@@ -690,7 +689,6 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({
onOpenThread={openConversation}
onPostPhotoSelect={(file) => {
setPendingPostPhotoFile(file);
- setSkipNextHomeFeedSkeleton(true);
void router
.push(spaceRoutes.home)
.catch((error: unknown) => {
diff --git a/web/apps/space/src/pages/add-profile-photo.tsx b/web/apps/space/src/pages/add-profile-photo.tsx
index 247056ba94..c242fa0676 100644
--- a/web/apps/space/src/pages/add-profile-photo.tsx
+++ b/web/apps/space/src/pages/add-profile-photo.tsx
@@ -20,7 +20,6 @@ const Page: React.FC = () => {
profileLoadStatus,
setPendingCreateProfile,
setProfile,
- setSkipNextHomeFeedSkeleton,
} = useSpaceAppState();
const createProfileSource = pendingCreateProfile?.source ?? "verify";
const [setupError, setSetupError] = useState<string>();
@@ -82,11 +81,7 @@ const Page: React.FC = () => {
);
setProfile(savedProfile);
setPendingCreateProfile(null);
- const handledPendingFriendRequest =
- await sendPendingSpaceFriendRequest();
- if (!handledPendingFriendRequest) {
- setSkipNextHomeFeedSkeleton(true);
- }
+ await sendPendingSpaceFriendRequest();
await router.push(spaceRoutes.home);
} catch (error) {
log.error("Space profile setup failed", error);
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 099e224c5d..abc2c9a8a9 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -4,93 +4,49 @@ import log from "ente-base/log";
import React, { useEffect, useState } from "react";
import { HomeScreen, homeBackground } from "screens/HomeScreen";
import {
- cacheCurrentSpaceFeedPage,
- loadCachedSpaceFeed,
patchCachedSpaceFeedPost,
prependCachedSpaceFeedPost,
- removeCachedSpaceFeedPost,
} from "services/feed-cache";
-import { consumeSentSpaceInviteFriend, spaceInviteURL } from "services/invite";
+import { consumeSentSpaceInviteFriend } from "services/invite";
import { loadExistingSpaceId } from "services/profile";
import {
createCurrentPhotoPost,
- deleteCurrentPost,
- isSpacePostLimitReachedError,
- loadCurrentFeedPage,
loadCurrentSpaceFriends,
+ loadCurrentSpaceLatestPost,
loadCurrentSpacePostAssetURL,
loadCurrentSpacePostAvatarURL,
loadCurrentUnreadStatus,
replyToCurrentPost,
setCurrentPostLiked,
- updateCurrentPostCaption,
type SpacePost,
} from "services/space";
import { useSpaceAppState } from "state/app-state";
-import {
- confirmLocalFeedPost,
- createLocalFeedPostID,
- failLocalFeedPost,
-} from "utils/local-feed-post";
import { prepareSpacePostImageFromEdit } from "utils/post-image";
import { useSpaceRouter } from "utils/route-transitions";
import { spaceRoutes } from "utils/routes";
-const inviteFriendsToastDelayMs = 3000;
-
const Page: React.FC = () => {
const router = useSpaceRouter();
const {
friends,
- localFeedPosts,
pendingPostPhotoFile,
profile,
profileLoadError,
profileLoadStatus,
setFriends,
- setLocalFeedPosts,
setPendingPostPhotoFile,
- setSkipNextHomeFeedSkeleton,
- skipNextHomeFeedSkeleton,
} = useSpaceAppState();
const [friendRequestSentToastName, setFriendRequestSentToastName] =
useState<string>();
- const [feedItems, setFeedItems] = useState<SpacePost[]>([]);
- const [hasFeedLoadMoreError, setHasFeedLoadMoreError] = useState(false);
- const [feedNextCursor, setFeedNextCursor] = useState<string>();
+ const [latestPosts, setLatestPosts] = useState<SpacePost[]>([]);
const [hasUnreadMessages, setHasUnreadMessages] = useState<boolean>();
- const [isFeedLoading, setIsFeedLoading] = useState(true);
- const [isFeedLoadingMore, setIsFeedLoadingMore] = useState(false);
+ const [isLatestPostsLoading, setIsLatestPostsLoading] = useState(true);
const [isFriendsLoading, setIsFriendsLoading] = useState(true);
const [spaceId, setSpaceId] = useState<string>();
- const [showInviteFriendsToast, setShowInviteFriendsToast] = useState(false);
- const inviteFriendsToastTimerRef = React.useRef<number | undefined>(
- undefined,
- );
- const isInitialFeedLoading =
- Boolean(spaceId || profile?.spaceId) &&
- isFeedLoading &&
- feedItems.length == 0 &&
- localFeedPosts.length == 0;
- const isSkippingInitialFeedSkeleton =
- isInitialFeedLoading && skipNextHomeFeedSkeleton;
- const isHomeFeedLoading = isFeedLoading && !isSkippingInitialFeedSkeleton;
const closeFriendRequestSentToast = React.useCallback(
() => setFriendRequestSentToastName(undefined),
[],
);
- const closeInviteFriendsToast = React.useCallback(
- () => setShowInviteFriendsToast(false),
- [],
- );
-
- useEffect(
- () => () => {
- if (inviteFriendsToastTimerRef.current !== undefined)
- window.clearTimeout(inviteFriendsToastTimerRef.current);
- },
- [],
- );
useEffect(() => {
if (profileLoadStatus == "ready" && !profile) {
@@ -109,71 +65,22 @@ const Page: React.FC = () => {
useEffect(() => {
let cancelled = false;
- let loadedSpaceId: string | undefined;
setSpaceId(undefined);
- setFeedItems([]);
- setHasFeedLoadMoreError(false);
- setFeedNextCursor(undefined);
+ setLatestPosts([]);
setHasUnreadMessages(undefined);
- setIsFeedLoading(true);
- setIsFeedLoadingMore(false);
+ setIsLatestPostsLoading(true);
setIsFriendsLoading(true);
void loadExistingSpaceId()
- .then(async (nextSpaceId) => {
- if (cancelled) return undefined;
-
- loadedSpaceId = nextSpaceId;
- setSpaceId(nextSpaceId);
- if (!nextSpaceId) return undefined;
-
- let freshFeedApplied = false;
- const cachedFeedLoad = loadCachedSpaceFeed(nextSpaceId);
- const freshFeedLoad = loadCurrentFeedPage(nextSpaceId);
- void cachedFeedLoad.then((cachedFeed) => {
- if (cancelled || freshFeedApplied || !cachedFeed) return;
-
- setFeedItems(cachedFeed.items);
- setFeedNextCursor(
- cachedFeed.dirty ? undefined : cachedFeed.nextCursor,
- );
- });
-
- const feed = await freshFeedLoad;
- freshFeedApplied = true;
- return feed;
- })
- .then((feed) => {
- if (cancelled || !loadedSpaceId || !feed) return;
-
- setFeedItems(feed.items);
- setFeedNextCursor(feed.nextCursor);
- void cacheCurrentSpaceFeedPage(loadedSpaceId, feed);
- const refreshedPostIDs = new Set(
- feed.items.map((item) => item.postId),
- );
- setLocalFeedPosts((currentPosts) =>
- currentPosts.filter(
- (item) =>
- item.status != "ready" ||
- !refreshedPostIDs.has(item.post.postId),
- ),
- );
- })
- .catch((error: unknown) =>
- log.error("Failed to load space feed", error),
- )
- .finally(() => {
+ .then((nextSpaceId) => {
if (cancelled) return;
- setIsFeedLoading(false);
- setSkipNextHomeFeedSkeleton(false);
- if (!loadedSpaceId) {
+ setSpaceId(nextSpaceId);
+ if (!nextSpaceId) {
setHasUnreadMessages(false);
- setIsFriendsLoading(false);
return;
}
- void loadCurrentUnreadStatus(loadedSpaceId)
+ void loadCurrentUnreadStatus(nextSpaceId)
.then((unreadStatus) => {
if (!cancelled) {
setHasUnreadMessages(unreadStatus.messagesUnread);
@@ -182,51 +89,57 @@ const Page: React.FC = () => {
.catch((error: unknown) =>
log.error("Failed to load space unread status", error),
);
- void loadCurrentSpaceFriends(loadedSpaceId)
- .then((nextFriends) => {
- if (!cancelled) setFriends(nextFriends);
- })
- .catch((error: unknown) =>
- log.error("Failed to load space friends", error),
- )
- .finally(() => {
- if (!cancelled) setIsFriendsLoading(false);
- });
- });
- return () => {
- cancelled = true;
- };
- }, [setFriends, setLocalFeedPosts, setSkipNextHomeFeedSkeleton]);
+ return loadCurrentSpaceFriends(nextSpaceId).then(
+ (nextFriends) => {
+ if (cancelled) return;
- const loadMoreFeedItems = React.useCallback(async () => {
- if (!spaceId || !feedNextCursor || isFeedLoadingMore) return;
+ setFriends(nextFriends);
+ setIsFriendsLoading(false);
+ return Promise.all(
+ nextFriends.map(async (friend) => {
+ if (!friend.spaceId) return null;
+ try {
+ return await loadCurrentSpaceLatestPost(
+ friend.spaceId,
+ nextSpaceId,
+ );
+ } catch (error) {
+ log.warn(
+ `Failed to load latest post for ${friend.id}`,
+ error,
+ );
+ return null;
+ }
+ }),
+ ).then((latestPosts) => {
+ if (cancelled) return;
- setHasFeedLoadMoreError(false);
- setIsFeedLoadingMore(true);
- try {
- const feed = await loadCurrentFeedPage(spaceId, feedNextCursor);
- setFeedItems((currentItems) => {
- const existingPostIds = new Set(
- currentItems.map((item) => item.postId),
+ setLatestPosts(
+ latestPosts.filter(
+ (post): post is SpacePost => post !== null,
+ ),
+ );
+ });
+ },
);
- return [
- ...currentItems,
- ...feed.items.filter(
- (item) => !existingPostIds.has(item.postId),
- ),
- ];
+ })
+ .catch((error: unknown) =>
+ log.error("Failed to load space friends", error),
+ )
+ .finally(() => {
+ if (cancelled) return;
+
+ setIsLatestPostsLoading(false);
+ setIsFriendsLoading(false);
});
- setFeedNextCursor(feed.nextCursor);
- } catch (error) {
- setHasFeedLoadMoreError(true);
- log.error("Failed to load more space feed", error);
- } finally {
- setIsFeedLoadingMore(false);
- }
- }, [feedNextCursor, isFeedLoadingMore, spaceId]);
- const setFeedPostLiked = React.useCallback(
+ return () => {
+ cancelled = true;
+ };
+ }, [setFriends]);
+
+ const setLatestPostLiked = React.useCallback(
async (postId: number, liked: boolean) => {
if (!spaceId) throw new Error("Missing space.");
@@ -234,7 +147,7 @@ const Page: React.FC = () => {
void patchCachedSpaceFeedPost(spaceId, postId, {
viewerLiked: liked,
});
- setFeedItems((currentItems) =>
+ setLatestPosts((currentItems) =>
currentItems.map((item) =>
item.postId == postId
? { ...item, viewerLiked: liked }
@@ -261,29 +174,22 @@ const Page: React.FC = () => {
<>
<SpacePageMeta themeColor={homeBackground} />
<HomeScreen
- feedItems={feedItems}
+ latestPosts={latestPosts}
friendRequestSentToastName={friendRequestSentToastName}
- hasFeedLoadMoreError={hasFeedLoadMoreError}
+ friends={friends}
hasUnreadMessages={hasUnreadMessages}
initialPostPhotoFile={pendingPostPhotoFile}
- hasMoreFeedItems={Boolean(feedNextCursor)}
- isFeedLoading={isHomeFeedLoading}
- isFeedLoadingMore={isFeedLoadingMore}
- localFeedPosts={localFeedPosts}
+ isLatestPostsLoading={isLatestPostsLoading}
+ isFriendsLoading={isFriendsLoading}
profile={profile}
viewerSpaceId={spaceId ?? profile?.spaceId}
showInstallPrompt={
profileLoadStatus == "ready" &&
Boolean(profile) &&
- !isHomeFeedLoading
- }
- showInviteFriendsToast={
- showInviteFriendsToast &&
- !isFriendsLoading &&
- friends.length == 0
+ !isLatestPostsLoading &&
+ !isFriendsLoading
}
onFriendRequestSentToastClose={closeFriendRequestSentToast}
- onInviteFriendsToastClose={closeInviteFriendsToast}
onInitialPostPhotoConsumed={() => setPendingPostPhotoFile(null)}
onCreatePost={
profile
@@ -291,129 +197,24 @@ const Page: React.FC = () => {
const spaceId = profile.spaceId;
if (!spaceId) throw new Error("Missing space.");
- const isFirstPost =
- !feedItems.some(
- (item) => item.spaceId == spaceId,
- ) &&
- !localFeedPosts.some(
- (item) => item.status != "failed",
+ const preparedImage =
+ await prepareSpacePostImageFromEdit(
+ image.file,
+ image.cropArea,
+ image.rotationDegrees,
);
- const localPostId = createLocalFeedPostID();
- const displayName =
- profile.fullName.trim() ||
- profile.username.trim();
- setLocalFeedPosts((currentPosts) => [
- {
- avatarUrl: profile.avatarUrl,
- caption: caption.trim() || undefined,
- friendID: spaceId,
- height: image.height,
- id: localPostId,
- imageUrl:
- image.previewUrl ||
- URL.createObjectURL(image.file),
- name: displayName || "You",
- spaceId,
- status: "pending",
- timestampMs: Date.now(),
- width: image.width,
- },
- ...currentPosts,
- ]);
- try {
- const preparedImage =
- await prepareSpacePostImageFromEdit(
- image.file,
- image.cropArea,
- image.rotationDegrees,
- );
- const post = await createCurrentPhotoPost({
- caption,
- file: preparedImage.file,
- height: preparedImage.height,
- spaceId,
- thumbHash: preparedImage.thumbHash,
- width: preparedImage.width,
- });
- confirmLocalFeedPost(
- setLocalFeedPosts,
- localPostId,
- post,
- );
- void prependCachedSpaceFeedPost(
- spaceId,
- post,
- );
- if (isFirstPost) {
- inviteFriendsToastTimerRef.current =
- window.setTimeout(() => {
- setShowInviteFriendsToast(true);
- inviteFriendsToastTimerRef.current =
- undefined;
- }, inviteFriendsToastDelayMs);
- }
- } catch (error) {
- failLocalFeedPost(
- setLocalFeedPosts,
- localPostId,
- isSpacePostLimitReachedError(error)
- ? "post-limit"
- : undefined,
- );
- throw error;
- }
+ const post = await createCurrentPhotoPost({
+ caption,
+ file: preparedImage.file,
+ height: preparedImage.height,
+ spaceId,
+ thumbHash: preparedImage.thumbHash,
+ width: preparedImage.width,
+ });
+ void prependCachedSpaceFeedPost(spaceId, post);
}
: undefined
}
- onDeletePost={async (postId) => {
- const spaceId = profile?.spaceId;
- if (!spaceId) throw new Error("Missing space.");
- await deleteCurrentPost(spaceId, postId);
- void removeCachedSpaceFeedPost(spaceId, postId);
- setLocalFeedPosts((currentPosts) =>
- currentPosts.filter(
- (item) =>
- item.status == "pending" ||
- item.status == "failed" ||
- item.post.postId != postId,
- ),
- );
- setFeedItems((currentItems) =>
- currentItems.filter((item) => item.postId != postId),
- );
- }}
- onUpdatePostCaption={async (postId, caption) => {
- const spaceId = profile?.spaceId;
- if (!spaceId) throw new Error("Missing space.");
-
- await updateCurrentPostCaption(spaceId, postId, caption);
- const normalizedCaption = caption.trim() || undefined;
- void patchCachedSpaceFeedPost(spaceId, postId, {
- caption: normalizedCaption,
- });
- setLocalFeedPosts((currentPosts) =>
- currentPosts.map((item) =>
- (item.status == "posted" ||
- item.status == "ready") &&
- item.post.postId == postId
- ? {
- ...item,
- post: {
- ...item.post,
- caption: normalizedCaption,
- },
- }
- : item,
- ),
- );
- setFeedItems((currentItems) =>
- currentItems.map((item) =>
- item.postId == postId
- ? { ...item, caption: normalizedCaption }
- : item,
- ),
- );
- }}
onOpenFriend={(friendID, username) => {
const friend = friends.find(
(candidate) =>
@@ -428,7 +229,6 @@ const Page: React.FC = () => {
);
}
}}
- onLoadMoreFeedItems={loadMoreFeedItems}
onLoadPostAvatar={loadCurrentSpacePostAvatarURL}
onLoadPostImage={loadCurrentSpacePostAssetURL}
onOpenMessages={() => void router.push(spaceRoutes.messages)}
@@ -455,12 +255,7 @@ const Page: React.FC = () => {
)(profile.spaceId)
: undefined
}
- onSetPostLiked={setFeedPostLiked}
- profileLink={
- profile
- ? spaceInviteURL({ spaceUsername: profile.username })
- : undefined
- }
+ onSetPostLiked={setLatestPostLiked}
/>
</>
);
diff --git a/web/apps/space/src/pages/app/post.tsx b/web/apps/space/src/pages/app/post.tsx
index 1a5a8d16cf..f29afd4b3b 100644
--- a/web/apps/space/src/pages/app/post.tsx
+++ b/web/apps/space/src/pages/app/post.tsx
@@ -24,7 +24,6 @@ const Page: React.FC = () => {
profileLoadError,
profileLoadStatus,
setPendingPostPhotoFile,
- setSkipNextHomeFeedSkeleton,
} = useSpaceAppState();
const inputRef = React.useRef<HTMLInputElement | null>(null);
const [isOpeningPost, setIsOpeningPost] = React.useState(false);
@@ -53,7 +52,6 @@ const Page: React.FC = () => {
setIsOpeningPost(true);
setPendingPostPhotoFile(file);
- setSkipNextHomeFeedSkeleton(true);
void router.push(spaceRoutes.home).catch((error: unknown) => {
log.error("Failed to open post photo draft", error);
setPendingPostPhotoFile(null);
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 3d1389d5bc..3ede9bc960 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -1,12 +1,10 @@
import {
BubbleChatIcon,
- FavouriteIcon,
MultiplicationSignIcon,
UserAdd02Icon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Skeleton } from "@mui/material";
-import { SpaceActionToast } from "components/ActionToast";
import { SpaceAvatarImage } from "components/AvatarImage";
import {
SpaceFileViewer,
@@ -15,17 +13,10 @@ import {
type SpaceViewerPhoto,
type SpaceViewerPostActionMode,
} from "components/FileViewer";
-import { SpaceInlinePostButton } from "components/InlinePostButton";
-import {
- spacePostLikeButtonPop,
- spacePostLikeHeartPop,
- spacePostLikePopDurationMs,
- spacePostLikePopTiming,
-} from "components/post-like-animation";
import { SpacePostFloatingActionButton } from "components/PostFloatingActionButton";
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";
@@ -36,9 +27,8 @@ import {
type SpacePostAssetURLLoader,
type SpacePostAvatarURLLoader,
} from "services/space";
-import type { LocalSpaceFeedPost } from "state/app-state";
import { spaceTouchTargetSize } from "styles/touch-targets";
-import { firstNameFrom, formatSpaceDate } from "utils/display";
+import { firstNameFrom } from "utils/display";
import { createLoadedLocalPostPhoto } from "utils/local-post-photo";
import {
canPreviewSpaceImageFile,
@@ -48,77 +38,46 @@ import {
} from "utils/post-image";
import { thumbHashDataURLFromBase64 } from "utils/thumbhash";
-export const homeBackground = "#F5F5F7";
+export const homeBackground = "#0C1014";
const green = "#08C225";
-const paleGreen = "#E7F6E9";
-const feedCardBackground = "#FFFFFF";
-const feedActionBackground = "#F7F7F7";
-const feedActionBackgroundHover = "#EFEFEF";
-const feedSkeletonElementBackground = "#E6E6E6";
+const inactivePostCircleBorderColor = "rgba(180, 195, 186, 0.1)";
+const mediaSkeletonElementBackground = "#E6E6E6";
const textBase = "#000";
const textSecondary = "#6B6B6B";
const dangerColor = "#F63A3A";
const headerActionSize = spaceTouchTargetSize;
-const headerAvatarSize = 28;
-const feedAvatarSize = 38;
+const headerAvatarSize = 36;
+const headerAvatarImageSize = 26;
+const headerChatCircleSize = 36;
+const headerChromeColor = "#202825";
const headerHeight = 64;
-const headerIconSize = 30;
-const headerSideWidth = 32;
-const feedLikeActionSize = spaceTouchTargetSize;
-const feedActionIconSize = 20;
-const emptyFeedItemGap = "22px";
-const feedHorizontalPadding = "16px";
-const minimumFeedPhotoFrameAspectRatio = 3 / 4;
-const feedMediaLoadRootMargin = "640px 0px";
-const feedLoadMoreRootMargin = "0px 0px 160px 0px";
-const feedRowEnterDurationMs = 460;
-const feedRowEnterStaggerMs = 35;
-const feedRowEnterTiming = "cubic-bezier(0.2, 0.8, 0.2, 1)";
+const headerIconSize = 22;
+const headerSideWidth = 36;
+const homeHorizontalPadding = "16px";
+const postCircleAvatarSize = "clamp(18px, 19%, 32px)";
+const postCircleMediaLoadRootMargin = "640px 0px";
const avatarFadeSx = {
"@keyframes spaceAvatarFade": { from: { opacity: 0 }, to: { opacity: 1 } },
animation: "spaceAvatarFade 320ms cubic-bezier(0.22, 1, 0.36, 1) both",
"@media (prefers-reduced-motion: reduce)": { animation: "none" },
} as const;
-const feedPhotoCaptionTextSx = {
- color: "#FFFFFF",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 650,
- lineHeight: "19px",
- textAlign: "center",
- textWrap: "balance",
-} as const;
-const feedPhotoCaptionBubbleSx = {
- bgcolor: "rgba(48, 48, 48, 0.79)",
- borderRadius: "5px",
- boxDecorationBreak: "clone",
- px: "7px",
- py: "2px",
- WebkitBoxDecorationBreak: "clone",
-} as const;
interface HomeScreenProps {
- feedItems: SpacePost[];
+ latestPosts: SpacePost[];
friendRequestSentToastName?: string;
- hasFeedLoadMoreError?: boolean;
- hasMoreFeedItems?: boolean;
+ friends: FriendProfile[];
hasUnreadMessages?: boolean;
initialPostPhotoFile?: File | null;
- isFeedLoading?: boolean;
- isFeedLoadingMore?: boolean;
- localFeedPosts?: LocalSpaceFeedPost[];
+ isLatestPostsLoading?: boolean;
+ isFriendsLoading?: boolean;
showInstallPrompt?: boolean;
- showInviteFriendsToast?: boolean;
onCreatePost?: (
image: DraftSpacePostImage,
caption: string,
) => Promise<void>;
- onDeletePost?: (postId: number) => Promise<void> | void;
- onLoadMoreFeedItems?: () => Promise<void> | void;
onLoadPostAvatar?: SpacePostAvatarURLLoader;
onLoadPostImage?: SpacePostAssetURLLoader;
onFriendRequestSentToastClose?: () => void;
- onInviteFriendsToastClose?: () => void;
onInitialPostPhotoConsumed?: () => void;
onOpenFriend?: (friendID: string, username?: string) => void;
onOpenMessages?: () => void;
@@ -129,21 +88,10 @@ interface HomeScreenProps {
text: string,
) => Promise<void>;
onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;
- onUpdatePostCaption?: (postId: number, caption: string) => Promise<void>;
- profileLink?: string;
profile: SetupProfile | null;
viewerSpaceId?: string;
}
-interface FeedPhotoDimensions {
- height: number;
- width: number;
-}
-
-interface LoadedFeedPhotoDimensions extends FeedPhotoDimensions {
- src: string;
-}
-
interface DecodedImageState {
failed?: boolean;
height?: number;
@@ -166,284 +114,23 @@ interface DraftSpacePostImage {
cropArea?: SpaceViewerDraftPostEdit["cropArea"];
file: File;
height?: number;
- previewUrl?: string;
rotationDegrees?: number;
width?: number;
}
-type HomeFeedEntry =
- | {
- identity: string;
- item: LocalSpaceFeedPost;
- kind: "local";
- renderKey: string;
- }
- | { identity: string; item: SpacePost; kind: "remote"; renderKey: string };
-
-interface FeedLayoutSnapshot {
- enteringKeys: Set<string>;
- previousTops: Map<string, number>;
-}
-
-interface FeedMotionListProps {
- entries: HomeFeedEntry[];
- renderEntry: (entry: HomeFeedEntry) => React.ReactNode;
-}
-
-class FeedMotionList extends React.Component<FeedMotionListProps> {
- private animations = new Map<string, Animation>();
- private identityKeys = new Map<string, string>();
- private rowElements = new Map<string, HTMLDivElement>();
- private rowRefs = new Map<
- string,
- (element: HTMLDivElement | null) => void
- >();
- private sourceKeys = new Map<string, string>();
-
- private stableKeyFor = (entry: HomeFeedEntry) => {
- const stableKey =
- this.identityKeys.get(entry.identity) ??
- this.sourceKeys.get(entry.renderKey) ??
- entry.renderKey;
- this.identityKeys.set(entry.identity, stableKey);
- this.sourceKeys.set(entry.renderKey, stableKey);
- return stableKey;
- };
-
- private rowRefFor = (key: string) => {
- let rowRef = this.rowRefs.get(key);
- if (!rowRef) {
- rowRef = (element) => {
- if (element) this.rowElements.set(key, element);
- else this.rowElements.delete(key);
- };
- this.rowRefs.set(key, rowRef);
- }
- return rowRef;
- };
-
- private cancelAnimations = () => {
- this.animations.forEach((animation) => animation.cancel());
- this.animations.clear();
- this.rowElements.forEach((element) => {
- element.style.zIndex = "";
- element.style.willChange = "";
- });
- };
-
- getSnapshotBeforeUpdate(
- previousProps: FeedMotionListProps,
- ): FeedLayoutSnapshot | null {
- const previousIdentityOrder = previousProps.entries.map(
- (entry) => entry.identity,
- );
- const identityOrder = this.props.entries.map((entry) => entry.identity);
- if (
- previousIdentityOrder.length == identityOrder.length &&
- previousIdentityOrder.every(
- (identity, index) => identity == identityOrder[index],
- )
- )
- return null;
-
- const previousIdentities = new Set(previousIdentityOrder);
- const addedEntries = this.props.entries.filter(
- (entry) => !previousIdentities.has(entry.identity),
- );
- if (
- previousProps.entries.length == 0 ||
- addedEntries.some((entry) => entry.kind == "local")
- )
- return null;
-
- const firstRetainedIndex = this.props.entries.findIndex((entry) =>
- previousIdentities.has(entry.identity),
- );
- const enteringKeys = new Set(
- firstRetainedIndex > 0
- ? this.props.entries
- .slice(0, firstRetainedIndex)
- .filter((entry) => entry.kind == "remote")
- .map(this.stableKeyFor)
- : [],
- );
- const previousTops = new Map<string, number>();
- this.rowElements.forEach((element, key) => {
- previousTops.set(key, element.getBoundingClientRect().top);
- });
- return { enteringKeys, previousTops };
- }
-
- componentDidUpdate(
- _previousProps: FeedMotionListProps,
- _previousState: unknown,
- snapshot: FeedLayoutSnapshot | null,
- ) {
- if (
- !snapshot ||
- window.matchMedia("(prefers-reduced-motion: reduce)").matches
- )
- return;
-
- this.cancelAnimations();
- let enteringIndex = 0;
- for (const entry of this.props.entries) {
- const key = this.stableKeyFor(entry);
- const element = this.rowElements.get(key);
- if (!element) continue;
-
- let animation: Animation | undefined;
- if (snapshot.enteringKeys.has(key)) {
- const delay = enteringIndex * feedRowEnterStaggerMs;
- const height = element.getBoundingClientRect().height;
- const paddingBottom =
- window.getComputedStyle(element).paddingBottom;
- element.style.zIndex = String(3 - enteringIndex++);
- element.style.willChange = "height, padding-bottom, transform";
- animation = element.animate(
- [
- {
- height: "0px",
- paddingBottom: "0px",
- transform: `translate3d(0, -${height}px, 0)`,
- },
- {
- height: `${height}px`,
- paddingBottom,
- transform: "translate3d(0, 0, 0)",
- },
- ],
- {
- delay,
- duration: feedRowEnterDurationMs,
- easing: feedRowEnterTiming,
- fill: "both",
- },
- );
- } else if (snapshot.enteringKeys.size == 0) {
- const previousTop = snapshot.previousTops.get(key);
- if (previousTop == undefined) continue;
- const offsetY =
- previousTop - element.getBoundingClientRect().top;
- if (!offsetY) continue;
- animation = element.animate(
- [
- { transform: `translate3d(0, ${offsetY}px, 0)` },
- { transform: "translate3d(0, 0, 0)" },
- ],
- {
- duration: feedRowEnterDurationMs,
- easing: feedRowEnterTiming,
- fill: "both",
- },
- );
- }
- if (!animation) continue;
-
- this.animations.set(key, animation);
- void animation.finished.then(
- () => {
- if (this.animations.get(key) != animation) return;
- animation.cancel();
- this.animations.delete(key);
- element.style.zIndex = "";
- element.style.willChange = "";
- },
- () => undefined,
- );
- }
- }
-
- componentWillUnmount() {
- this.cancelAnimations();
- }
-
- render() {
- return this.props.entries.map((entry) => {
- const key = this.stableKeyFor(entry);
- return (
- <Box
- key={key}
- ref={this.rowRefFor(key)}
- sx={{
- boxSizing: "border-box",
- minWidth: 0,
- pb: "24px",
- position: "relative",
- width: "100%",
- }}
- >
- {this.props.renderEntry(entry)}
- </Box>
- );
- });
- }
-}
-
-type FeedTimestampStatus = "failed" | "post-limit" | "posted" | "posting";
-
-interface FeedItemProps {
- aspectRatio: number;
- avatarUrl: string | null;
- caption?: string;
- friendID: string;
- imageUrl?: string;
- isAvatarPending: boolean;
- isOwnPost: boolean;
- isUnavailable?: boolean;
- name: string;
- onLoadAvatar?: () => Promise<string | null | undefined>;
- onLoadImage?: () => Promise<string | undefined>;
- onOpenFriend?: (friendID: string, username?: string) => void;
- onOpenPhoto?: (photo: SpaceViewerPhoto, focusReplyOnOpen?: boolean) => void;
- onOpenProfile?: () => void;
- onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;
- postId: number;
- spaceId?: string;
- thumbHash?: string;
- timestampStatus?: FeedTimestampStatus;
- timestampMs: number;
- username?: string;
- viewerLiked: boolean;
-}
-
interface AddedFriendToastProps {
message: string;
onClose?: () => void;
}
-interface InviteFriendsToastProps {
- profileLink?: string;
- sharing: boolean;
- onClose?: () => void;
- onSharingChange: (sharing: boolean) => void;
-}
-
-const dimensionsFromAspectRatio = (
- aspectRatio: number,
-): FeedPhotoDimensions => {
- const safeAspectRatio =
- Number.isFinite(aspectRatio) && aspectRatio > 0 ? aspectRatio : 1;
- const height = 1000;
-
- return { height, width: Math.round(safeAspectRatio * height) };
-};
-
-const feedPhotoFrameDimensionsFor = (
- dimensions: FeedPhotoDimensions,
-): FeedPhotoDimensions =>
- dimensions.width / dimensions.height < minimumFeedPhotoFrameAspectRatio
- ? { height: 4, width: 3 }
- : dimensions;
-
-const feedPostImageCacheKey = (item: SpacePost) =>
+const postImageCacheKey = (item: SpacePost) =>
[
item.postId,
item.imageAsset?.spaceId ?? item.spaceId,
item.imageAsset?.objectKey ?? item.imageUrl ?? "",
].join(":");
-const feedPostAvatarCacheKey = (item: SpacePost) =>
+const postAvatarCacheKey = (item: SpacePost) =>
[
item.spaceId,
item.avatarKeyVersion ?? "",
@@ -515,212 +202,223 @@ const useDecodedImage = (
return { ready: !src, src };
};
-const scrollPageToTop = () => {
- const behavior = window.matchMedia("(prefers-reduced-motion: reduce)")
- .matches
- ? "auto"
- : "smooth";
- window.scrollTo({ behavior, top: 0 });
-};
+interface PostCirclePlacement {
+ size: number;
+ x: number;
+ y: number;
+}
-const scheduleScrollPageToTop = () => {
- let scrollFrame = 0;
- const closeFrame = window.requestAnimationFrame(() => {
- scrollFrame = window.requestAnimationFrame(scrollPageToTop);
- });
- return () => {
- window.cancelAnimationFrame(closeFrame);
- window.cancelAnimationFrame(scrollFrame);
- };
+interface PostCircleLayout {
+ canvasHeight: number;
+ placements: PostCirclePlacement[];
+}
+
+const placedCircles = (
+ size: number,
+ canvasHeight: number,
+ points: [number, number][],
+): PostCircleLayout => ({
+ canvasHeight,
+ placements: points.map(([x, y]) => ({ size, x, y })),
+});
+
+const diceCircleLayouts: Record<number, PostCircleLayout> = {
+ 1: placedCircles(1, 1, [[0, 0]]),
+ 2: placedCircles(0.82, 1.66, [
+ [0.09, 0],
+ [0.09, 0.84],
+ ]),
+ 3: placedCircles(0.48, 0.91, [
+ [0.26, 0],
+ [0, 0.43],
+ [0.52, 0.43],
+ ]),
+ 4: placedCircles(0.44, 1, [
+ [0, 0],
+ [0.56, 0],
+ [0, 0.56],
+ [0.56, 0.56],
+ ]),
+ 5: placedCircles(0.34, 1, [
+ [0, 0],
+ [0.66, 0],
+ [0.33, 0.33],
+ [0, 0.66],
+ [0.66, 0.66],
+ ]),
+ 6: placedCircles(0.31, 1, [
+ [0, 0],
+ [0.69, 0],
+ [0, 0.345],
+ [0.69, 0.345],
+ [0, 0.69],
+ [0.69, 0.69],
+ ]),
+ 7: placedCircles(0.29, 1, [
+ [0, 0],
+ [0.71, 0],
+ [0, 0.355],
+ [0.355, 0.355],
+ [0.71, 0.355],
+ [0, 0.71],
+ [0.71, 0.71],
+ ]),
};
-const usePostingDotCount = (isPosting: boolean) => {
- const [dotCount, setDotCount] = useState(1);
+const balancedConstellationRowSizes = (count: number) => {
+ const rowCount = Math.ceil(count / 3);
+ const rowSizes = Array<number>(rowCount).fill(Math.floor(count / rowCount));
+ const outerInRowOrder: number[] = [];
+ for (let offset = 0; outerInRowOrder.length < rowCount; offset++) {
+ outerInRowOrder.push(offset);
+ const opposite = rowCount - offset - 1;
+ if (opposite != offset) outerInRowOrder.push(opposite);
+ }
+ const extraCircles = count - rowSizes[0]! * rowCount;
+ for (let index = 0; index < extraCircles; index++) {
+ rowSizes[outerInRowOrder[index]!]! += 1;
+ }
+ return rowSizes;
+};
- React.useEffect(() => {
- if (!isPosting) {
- setDotCount(1);
+const constellationCircleLayout = (count: number): PostCircleLayout => {
+ const rowSizes = balancedConstellationRowSizes(count);
+ const size = Math.max(0.2, 0.29 - (rowSizes.length - 3) * 0.0125);
+ const verticalGap = size * 0.16;
+ const placements: PostCirclePlacement[] = [];
+ rowSizes.forEach((rowSize, rowIndex) => {
+ const y = rowIndex * (size + verticalGap);
+ if (rowSize == 3) {
+ placements.push(
+ { size, x: 0, y },
+ { size, x: (1 - size) / 2, y },
+ { size, x: 1 - size, y },
+ );
return;
}
- const intervalID = window.setInterval(() => {
- setDotCount((count) => (count % 3) + 1);
- }, 500);
-
- return () => window.clearInterval(intervalID);
- }, [isPosting]);
-
- return dotCount;
+ const horizontalGap = size * 0.18;
+ const rowStart = (1 - (size * 2 + horizontalGap)) / 2;
+ placements.push(
+ { size, x: rowStart, y },
+ { size, x: rowStart + size + horizontalGap, y },
+ );
+ });
+ return {
+ canvasHeight:
+ rowSizes.length * size + (rowSizes.length - 1) * verticalGap,
+ placements,
+ };
};
-interface FeedLikeButtonProps {
- isLiked: boolean;
- onClick: () => void;
- popID: number;
-}
-
-const FeedLikeButton: React.FC<FeedLikeButtonProps> = ({
- isLiked,
- onClick,
- popID,
-}) => {
- const isPopping = isLiked && popID > 0;
-
- return (
- <Box
- component="button"
- type="button"
- aria-label={isLiked ? "Unlike post" : "Like post"}
- aria-pressed={isLiked}
- onClick={onClick}
- sx={{
- alignItems: "center",
- animation: isPopping
- ? `${spacePostLikeButtonPop} ${spacePostLikePopDurationMs}ms ${spacePostLikePopTiming} both`
- : undefined,
- appearance: "none",
- bgcolor: isLiked ? paleGreen : feedActionBackground,
- border: 0,
- borderRadius: "50%",
- color: isLiked ? green : textBase,
- cursor: "pointer",
- display: "inline-flex",
- flexShrink: 0,
- height: feedLikeActionSize,
- justifyContent: "center",
- p: 0,
- position: "relative",
- transition:
- "background-color 160ms ease, color 120ms ease, transform 120ms ease",
- width: feedLikeActionSize,
- "&:active": { transform: "scale(0.94)" },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": {
- bgcolor: isLiked ? "#DFF3E2" : feedActionBackgroundHover,
+const postCircleLayoutForCount = (count: number): PostCircleLayout =>
+ diceCircleLayouts[count] ??
+ (count > 7
+ ? constellationCircleLayout(count)
+ : { canvasHeight: 1, placements: [] });
+
+const avatarAttachmentAngleFor = (
+ placement: PostCirclePlacement,
+ placementIndex: number,
+ layout: PostCircleLayout,
+) => {
+ if (layout.placements.length == 1) return -135;
+
+ const centerX = placement.x + placement.size / 2;
+ const centerY = placement.y + placement.size / 2;
+ const layoutCenterX = 0.5;
+ const layoutCenterY = layout.canvasHeight / 2;
+ const outwardX = centerX - layoutCenterX;
+ const outwardY = centerY - layoutCenterY;
+ const outwardLength = Math.hypot(outwardX, outwardY);
+ const radius = placement.size / 2;
+ const avatarRadius = placement.size * 0.095;
+ const candidateAngles = [-90, 90, 180, 0, -135, -45, 135, 45];
+
+ return candidateAngles.reduce((bestAngle, angle) => {
+ const scoreFor = (candidateAngle: number) => {
+ const radians = (candidateAngle * Math.PI) / 180;
+ const directionX = Math.cos(radians);
+ const directionY = Math.sin(radians);
+ const avatarCenterX = centerX + directionX * radius;
+ const avatarCenterY = centerY + directionY * radius;
+ const nearestCircleClearance = layout.placements.reduce(
+ (nearest, otherPlacement, otherIndex) => {
+ if (otherIndex == placementIndex) return nearest;
+ const otherCenterX =
+ otherPlacement.x + otherPlacement.size / 2;
+ const otherCenterY =
+ otherPlacement.y + otherPlacement.size / 2;
+ const clearance =
+ Math.hypot(
+ avatarCenterX - otherCenterX,
+ avatarCenterY - otherCenterY,
+ ) -
+ otherPlacement.size / 2 -
+ avatarRadius;
+ return Math.min(nearest, clearance);
},
- "@media (prefers-reduced-motion: reduce)": {
- animation: "none",
- transition: "background-color 120ms ease, color 120ms ease",
- },
- }}
- >
- <Box
- key={isPopping ? `heart-${popID}` : "heart"}
- component="span"
- sx={{
- animation: isPopping
- ? `${spacePostLikeHeartPop} ${spacePostLikePopDurationMs}ms ${spacePostLikePopTiming} both`
- : undefined,
- display: "flex",
- lineHeight: 0,
- position: "relative",
- transformOrigin: "50% 58%",
- zIndex: 1,
- "@media (prefers-reduced-motion: reduce)": {
- animation: "none",
- },
- }}
- >
- <HugeiconsIcon
- fill={isLiked ? green : "none"}
- icon={FavouriteIcon}
- primaryColor={isLiked ? green : textBase}
- size={feedActionIconSize}
- strokeWidth={2}
- />
- </Box>
- </Box>
- );
-};
+ Number.POSITIVE_INFINITY,
+ );
+ const outwardAlignment = outwardLength
+ ? (directionX * outwardX + directionY * outwardY) /
+ outwardLength
+ : 0;
+ return nearestCircleClearance + outwardAlignment * placement.size;
+ };
-const FeedPhotoCaption: React.FC<{ caption: string }> = ({ caption }) => {
- return (
- <Box
- title={caption}
- sx={{
- ...feedPhotoCaptionTextSx,
- bottom: 20,
- display: "-webkit-box",
- left: "50%",
- maxWidth: "78%",
- overflow: "hidden",
- pointerEvents: "none",
- position: "absolute",
- textShadow: "0 1px 10px rgba(0, 0, 0, 0.74)",
- transform: "translateX(-50%)",
- WebkitBoxOrient: "vertical",
- WebkitLineClamp: 2,
- width: "max-content",
- zIndex: 2,
- }}
- >
- <Box component="span" sx={feedPhotoCaptionBubbleSx}>
- {caption}
- </Box>
- </Box>
- );
+ return scoreFor(angle) > scoreFor(bestAngle) ? angle : bestAngle;
+ }, candidateAngles[0]!);
};
-const FeedItem: React.FC<FeedItemProps> = ({
- aspectRatio,
+interface FriendPostCircleProps {
+ avatarAttachmentAngle: number;
+ avatarUrl?: string | null;
+ friend: FriendProfile;
+ imageUrl?: string;
+ isAvatarPending: boolean;
+ isLoading: boolean;
+ isUnavailable: boolean;
+ onLoadAvatar?: () => Promise<string | null | undefined>;
+ onLoadImage?: () => Promise<string | undefined>;
+ onOpenFriend?: (friendID: string, username?: string) => void;
+ onOpenPhoto: (photo: SpaceViewerPhoto) => void;
+ placement: PostCirclePlacement;
+ placementCanvasHeight: number;
+ post?: SpacePost;
+}
+
+const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
+ avatarAttachmentAngle,
avatarUrl,
- caption,
- friendID,
+ friend,
imageUrl,
isAvatarPending,
- isOwnPost,
- isUnavailable = false,
- name,
+ isLoading,
+ isUnavailable,
onLoadAvatar,
onLoadImage,
onOpenFriend,
onOpenPhoto,
- onOpenProfile,
- onSetPostLiked,
- postId,
- spaceId,
- thumbHash,
- timestampStatus,
- timestampMs,
- username,
- viewerLiked,
+ placement,
+ placementCanvasHeight,
+ post,
}) => {
- const [isLiked, setIsLiked] = useState(viewerLiked);
- const [likePopID, setLikePopID] = useState(0);
- const [shouldLoadMedia, setShouldLoadMedia] = useState(
- !isUnavailable && Boolean(imageUrl) && !isAvatarPending,
+ const rootRef = React.useRef<HTMLLIElement | null>(null);
+ const [shouldLoadMedia, setShouldLoadMedia] = useState(Boolean(imageUrl));
+ const decodedPhoto = useDecodedImage(imageUrl, true);
+ const decodedAvatar = useDecodedImage(
+ avatarUrl ?? friend.avatarUrl ?? null,
+ true,
);
- const rootRef = React.useRef<HTMLElement | null>(null);
- const firstName = firstNameFrom(name);
- const dateLabel = formatSpaceDate(timestampMs);
- const postingDotCount = usePostingDotCount(timestampStatus == "posting");
- const displayCaption = caption?.trim();
const thumbHashDataURL = React.useMemo(
- () => thumbHashDataURLFromBase64(thumbHash),
- [thumbHash],
+ () => thumbHashDataURLFromBase64(post?.thumbHash),
+ [post?.thumbHash],
);
- const canOpenAuthor = isOwnPost
- ? Boolean(onOpenProfile)
- : Boolean(onOpenFriend);
- const authorProfileLabel = isOwnPost
- ? "Open your profile"
- : `Open ${firstName}'s profile`;
- const openAuthor = () => {
- if (isOwnPost) {
- onOpenProfile?.();
- return;
- }
- onOpenFriend?.(friendID, username);
- };
- const [loadedPhotoDimensions, setLoadedPhotoDimensions] =
- useState<LoadedFeedPhotoDimensions | null>(null);
- const decodedPhoto = useDecodedImage(imageUrl, true);
- const decodedAvatar = useDecodedImage(avatarUrl, true);
- const isPostUnavailable = isUnavailable || decodedPhoto.failed;
- const showFooter = !isOwnPost && !isPostUnavailable;
+ const displayName = friend.fullName.trim() || friend.username.trim();
+ const firstName = firstNameFrom(displayName);
+ const initial = firstName.charAt(0).toLocaleUpperCase();
+ const postUnavailable = isUnavailable || decodedPhoto.failed;
const displayImageUrl =
(decodedPhoto.failed
? undefined
@@ -732,85 +430,18 @@ const FeedItem: React.FC<FeedItemProps> = ({
? undefined
: decodedAvatar.ready
? decodedAvatar.src
- : avatarUrl) ?? undefined;
- const isAvatarReady = !isAvatarPending && decodedAvatar.ready;
- const photoDimensions =
- loadedPhotoDimensions && loadedPhotoDimensions.src == displayImageUrl
- ? loadedPhotoDimensions
- : dimensionsFromAspectRatio(aspectRatio);
- const feedPhotoFrameDimensions =
- feedPhotoFrameDimensionsFor(photoDimensions);
+ : avatarUrl) ?? null;
const isPhotoReady = Boolean(displayImageUrl) && decodedPhoto.ready;
- const canOpenPhoto =
- !isPostUnavailable && isPhotoReady && Boolean(onOpenPhoto);
- const [showResolvedPhoto, setShowResolvedPhoto] = useState(false);
- const decodedPhotoHeight = decodedPhoto.height;
- const decodedPhotoSrc = decodedPhoto.src;
- const decodedPhotoWidth = decodedPhoto.width;
- const rememberLoadedPhotoDimensions: React.ReactEventHandler<
- HTMLImageElement
- > = ({ currentTarget }) => {
- if (!displayImageUrl) return;
- const { naturalHeight, naturalWidth } = currentTarget;
- if (!naturalHeight || !naturalWidth) return;
-
- setLoadedPhotoDimensions((currentDimensions) => {
- if (
- currentDimensions?.height == naturalHeight &&
- currentDimensions.src == displayImageUrl &&
- currentDimensions.width == naturalWidth
- ) {
- return currentDimensions;
- }
-
- return {
- height: naturalHeight,
- src: displayImageUrl,
- width: naturalWidth,
- };
- });
- };
- const openPhoto = (focusReplyOnOpen = false) => {
- if (!canOpenPhoto || !displayImageUrl) return;
-
- onOpenPhoto?.(
- {
- alt: `${name} post`,
- avatarUrl: displayAvatarUrl ?? null,
- caption,
- friendID,
- height: photoDimensions.height,
- imageUrl: displayImageUrl,
- name,
- postId,
- spaceId,
- timestampMs,
- username,
- viewerLiked: isLiked,
- width: photoDimensions.width,
- },
- focusReplyOnOpen,
- );
- };
- const handleLikeClick = () => {
- if (isOwnPost) return;
-
- const nextLiked = !isLiked;
- setIsLiked(nextLiked);
- if (nextLiked) setLikePopID((id) => id + 1);
- void onSetPostLiked?.(postId, nextLiked).catch((error: unknown) => {
- log.error("Failed to update post like", error);
- setIsLiked(!nextLiked);
- });
- };
-
- React.useEffect(() => {
- setIsLiked(viewerLiked);
- }, [viewerLiked]);
+ const canOpenPost = Boolean(post) && !postUnavailable && isPhotoReady;
+ const isCircleDisabled =
+ isLoading || Boolean(post && !postUnavailable && !isPhotoReady);
+ const avatarAttachmentRadians = (avatarAttachmentAngle * Math.PI) / 180;
+ const avatarAttachmentX = 50 + Math.cos(avatarAttachmentRadians) * 50;
+ const avatarAttachmentY = 50 + Math.sin(avatarAttachmentRadians) * 50;
+ const avatarCutoutMask = `radial-gradient(circle at ${avatarAttachmentX}% ${avatarAttachmentY}%, transparent calc(clamp(9px, 9.5%, 16px) + 3px), #000 calc(clamp(9px, 9.5%, 16px) + 3.5px))`;
React.useEffect(() => {
- if (isPostUnavailable) return;
- if (shouldLoadMedia) return;
+ if (isLoading || !post || postUnavailable || shouldLoadMedia) return;
const element = rootRef.current;
if (!element) return;
if (
@@ -828,112 +459,79 @@ const FeedItem: React.FC<FeedItemProps> = ({
observer.disconnect();
}
},
- { rootMargin: feedMediaLoadRootMargin },
+ { rootMargin: postCircleMediaLoadRootMargin },
);
observer.observe(element);
return () => observer.disconnect();
- }, [isPostUnavailable, shouldLoadMedia]);
+ }, [isLoading, post, postUnavailable, shouldLoadMedia]);
React.useEffect(() => {
- if (isPostUnavailable) return;
- if (!shouldLoadMedia) return;
-
- if (!imageUrl) {
- void onLoadImage?.();
- }
- if (isAvatarPending) {
- void onLoadAvatar?.();
- }
+ if (!shouldLoadMedia || postUnavailable) return;
+ if (!imageUrl) void onLoadImage?.();
+ if (isAvatarPending) void onLoadAvatar?.();
}, [
imageUrl,
isAvatarPending,
- isPostUnavailable,
onLoadAvatar,
onLoadImage,
+ postUnavailable,
shouldLoadMedia,
]);
- React.useEffect(() => {
- if (!decodedPhoto.failed) return;
- log.warn(
- `Post ${postId} is unavailable because the browser could not decode its image`,
- );
- }, [decodedPhoto.failed, postId]);
-
- React.useEffect(() => {
- if (!decodedPhotoHeight || !decodedPhotoWidth) return;
- if (!decodedPhotoSrc) return;
-
- setLoadedPhotoDimensions((currentDimensions) => {
- if (
- currentDimensions?.height == decodedPhotoHeight &&
- currentDimensions.src == decodedPhotoSrc &&
- currentDimensions.width == decodedPhotoWidth
- ) {
- return currentDimensions;
- }
-
- return {
- height: decodedPhotoHeight,
- src: decodedPhotoSrc,
- width: decodedPhotoWidth,
- };
- });
- }, [decodedPhotoHeight, decodedPhotoSrc, decodedPhotoWidth]);
-
- React.useEffect(() => {
- if (likePopID == 0) return;
-
- const timeoutID = window.setTimeout(
- () => setLikePopID(0),
- spacePostLikePopDurationMs,
- );
- return () => window.clearTimeout(timeoutID);
- }, [likePopID]);
-
- React.useEffect(() => {
- setShowResolvedPhoto(false);
- if (!isPhotoReady) return;
- if (!thumbHashDataURL) {
- setShowResolvedPhoto(true);
+ const openCircle = () => {
+ if (!post || postUnavailable) {
+ onOpenFriend?.(friend.id, friend.username);
return;
}
-
- const frameID = window.requestAnimationFrame(() =>
- setShowResolvedPhoto(true),
- );
- return () => window.cancelAnimationFrame(frameID);
- }, [displayImageUrl, isPhotoReady, thumbHashDataURL]);
+ if (!canOpenPost || !displayImageUrl) return;
+
+ onOpenPhoto({
+ alt: `${displayName} post`,
+ avatarUrl: displayAvatarUrl,
+ caption: post.caption,
+ friendID: post.friendID,
+ height: decodedPhoto.height ?? post.height,
+ imageUrl: displayImageUrl,
+ name: displayName,
+ postId: post.postId,
+ spaceId: post.spaceId,
+ timestampMs: post.timestampMs,
+ username: friend.username,
+ viewerLiked: post.viewerLiked,
+ width: decodedPhoto.width ?? post.width,
+ });
+ };
return (
<Box
ref={rootRef}
- component="article"
+ component="li"
sx={{
- bgcolor: feedCardBackground,
- borderRadius: "17px",
- boxSizing: "border-box",
- display: "flex",
- flexDirection: "column",
- maxWidth: "100%",
+ aspectRatio: "1",
+ left: `${placement.x * 100}%`,
+ listStyle: "none",
minWidth: 0,
- overflow: "hidden",
- pl: "5px",
- pb: isOwnPost ? "5px" : "8px",
- pr: "5px",
- pt: "5px",
- width: "100%",
+ position: "absolute",
+ top: `${(placement.y / placementCanvasHeight) * 100}%`,
+ transition:
+ "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)",
+ width: `${placement.size * 100}%`,
+ "@media (prefers-reduced-motion: reduce)": {
+ transition: "none",
+ },
}}
>
<Box
sx={{
- aspectRatio: `${feedPhotoFrameDimensions.width} / ${feedPhotoFrameDimensions.height}`,
- bgcolor: "transparent",
- borderRadius: "13px",
- maxWidth: "100%",
- minWidth: 0,
- overflow: "hidden",
+ aspectRatio: "1",
+ border: `3px solid ${inactivePostCircleBorderColor}`,
+ borderRadius: "50%",
+ boxSizing: "border-box",
+ height: "100%",
+ maskImage: avatarCutoutMask,
+ p: "4px",
position: "relative",
+ WebkitMaskImage: avatarCutoutMask,
width: "100%",
}}
>
@@ -941,388 +539,135 @@ const FeedItem: React.FC<FeedItemProps> = ({
component="button"
type="button"
aria-label={
- isPostUnavailable
- ? "Post unavailable"
- : `Open ${name} photo`
+ isLoading
+ ? `Loading ${firstName}'s latest post`
+ : post && !postUnavailable
+ ? `Open ${firstName}'s latest post`
+ : `Open ${firstName}'s profile`
}
- disabled={!canOpenPhoto}
- onClick={() => openPhoto()}
+ disabled={isCircleDisabled}
+ onClick={openCircle}
sx={{
+ alignItems: "center",
appearance: "none",
- bgcolor: "transparent",
+ aspectRatio: "1",
+ bgcolor: "#E5E7EA",
border: 0,
- cursor: canOpenPhoto ? "pointer" : "default",
- display: "block",
+ borderRadius: "50%",
+ color: textBase,
+ cursor: isCircleDisabled ? "default" : "pointer",
+ display: "flex",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
height: "100%",
- maxWidth: "100%",
- minWidth: 0,
+ justifyContent: "center",
overflow: "hidden",
p: 0,
position: "relative",
width: "100%",
"&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: -2,
+ outline: `3px solid ${green}`,
+ outlineOffset: 3,
},
}}
>
- {!isPostUnavailable &&
- !thumbHashDataURL &&
- !isPhotoReady && (
- <Skeleton
- variant="rectangular"
- sx={{
- bgcolor: feedSkeletonElementBackground,
- display: "block",
- height: "100%",
- transform: "none",
- width: "100%",
- }}
- />
- )}
- {!isPostUnavailable && 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}
- {!isPostUnavailable && isPhotoReady && (
- <Box
- component="img"
- alt={`${name} post`}
- src={displayImageUrl}
- onLoad={rememberLoadedPhotoDimensions}
+ {isLoading ? (
+ <Skeleton
+ variant="circular"
sx={{
- display: "block",
+ bgcolor: mediaSkeletonElementBackground,
height: "100%",
- inset: 0,
- maxWidth: "100%",
- minWidth: 0,
- objectFit: "cover",
- objectPosition: "center",
- opacity: showResolvedPhoto ? 1 : 0,
- position: "absolute",
- transition: thumbHashDataURL
- ? "opacity 220ms ease"
- : "none",
+ transform: "none",
width: "100%",
- zIndex: 1,
- "@media (prefers-reduced-motion: reduce)": {
- opacity: 1,
- transition: "none",
- },
}}
/>
- )}
- {isPostUnavailable && (
+ ) : post && !postUnavailable ? (
+ <>
+ {!thumbHashDataURL && !isPhotoReady && (
+ <Skeleton
+ variant="circular"
+ sx={{
+ bgcolor: mediaSkeletonElementBackground,
+ height: "100%",
+ transform: "none",
+ width: "100%",
+ }}
+ />
+ )}
+ {thumbHashDataURL && (
+ <Box
+ component="img"
+ alt=""
+ aria-hidden
+ src={thumbHashDataURL}
+ sx={{
+ filter: "blur(14px)",
+ height: "100%",
+ inset: 0,
+ objectFit: "cover",
+ position: "absolute",
+ transform: "scale(1.08)",
+ width: "100%",
+ }}
+ />
+ )}
+ {isPhotoReady && (
+ <Box
+ component="img"
+ alt={`${displayName} post`}
+ src={displayImageUrl}
+ sx={{
+ height: "100%",
+ inset: 0,
+ objectFit: "cover",
+ position: "absolute",
+ width: "100%",
+ }}
+ />
+ )}
+ </>
+ ) : (
<Box
sx={{
alignItems: "center",
- bgcolor: feedSkeletonElementBackground,
- color: "#6D6D72",
+ background:
+ "linear-gradient(145deg, #ECF7ED, #D9EDDC)",
+ color: green,
display: "flex",
- fontSize: 14,
- fontWeight: 600,
+ fontSize: 40,
+ fontWeight: 700,
height: "100%",
justifyContent: "center",
width: "100%",
}}
>
- Post unavailable
+ {initial}
</Box>
)}
</Box>
- <Box
+ </Box>
+ <Box
+ aria-hidden
+ sx={{
+ aspectRatio: "1",
+ border: 0,
+ borderRadius: "50%",
+ boxSizing: "border-box",
+ left: `${avatarAttachmentX}%`,
+ overflow: "hidden",
+ pointerEvents: "none",
+ position: "absolute",
+ top: `${avatarAttachmentY}%`,
+ transform: "translate(-50%, -50%)",
+ width: postCircleAvatarSize,
+ zIndex: 2,
+ }}
+ >
+ <SpaceAvatarImage
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,
- zIndex: 1,
- }}
+ borderRadius="50%"
+ src={displayAvatarUrl}
/>
- <Box
- sx={{
- alignItems: "center",
- boxSizing: "border-box",
- color: "#FFFFFF",
- display: "grid",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- gap: "8px",
- gridTemplateColumns: `${feedAvatarSize}px minmax(0, 1fr)`,
- left: 12,
- lineHeight: "20px",
- minHeight: 32,
- pointerEvents: "none",
- position: "absolute",
- right: 12,
- top: 12,
- zIndex: 2,
- }}
- >
- <Box
- component="button"
- type="button"
- aria-label={authorProfileLabel}
- onClick={openAuthor}
- sx={{
- alignItems: "center",
- appearance: "none",
- bgcolor: "transparent",
- border: 0,
- borderRadius: "50%",
- cursor: canOpenAuthor ? "pointer" : "default",
- display: "flex",
- flexShrink: 0,
- height: feedAvatarSize,
- justifyContent: "center",
- overflow: "visible",
- p: 0,
- pointerEvents: "auto",
- position: "relative",
- width: feedAvatarSize,
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- }}
- >
- <Box
- aria-hidden
- sx={{
- bgcolor: "rgba(255, 255, 255, 0.2)",
- borderRadius: "50%",
- inset: 0,
- position: "absolute",
- zIndex: 0,
- }}
- />
- {isAvatarReady ? (
- <Box
- key={displayAvatarUrl ?? "default-avatar"}
- sx={{
- ...avatarFadeSx,
- borderRadius: "50%",
- height: feedAvatarSize,
- overflow: "hidden",
- position: "relative",
- width: feedAvatarSize,
- zIndex: 1,
- }}
- >
- <SpaceAvatarImage
- src={displayAvatarUrl}
- borderRadius="50%"
- />
- </Box>
- ) : null}
- <Box
- aria-hidden
- sx={{
- border: "2px solid rgba(255, 255, 255, 0.35)",
- borderRadius: "50%",
- inset: -2,
- pointerEvents: "none",
- position: "absolute",
- zIndex: 2,
- }}
- />
- </Box>
- <Box sx={{ minWidth: 0 }}>
- <Box
- component="button"
- type="button"
- aria-label={authorProfileLabel}
- onClick={openAuthor}
- sx={{
- appearance: "none",
- bgcolor: "transparent",
- border: 0,
- color: "inherit",
- cursor: canOpenAuthor ? "pointer" : "default",
- display: "block",
- fontFamily: "inherit",
- fontSize: 14,
- fontWeight: 650,
- lineHeight: "18px",
- maxWidth: "100%",
- minWidth: 0,
- overflow: "hidden",
- p: 0,
- pointerEvents: "auto",
- textAlign: "left",
- textOverflow: "ellipsis",
- whiteSpace: "nowrap",
- "&:focus-visible": {
- borderRadius: "4px",
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- }}
- >
- {firstName}
- </Box>
- {timestampStatus ? (
- <Box
- component="span"
- aria-label={
- timestampStatus == "posting"
- ? "Posting"
- : timestampStatus == "post-limit"
- ? "Post limit reached. Please contact support."
- : timestampStatus == "failed"
- ? "Failed"
- : "Posted"
- }
- sx={{
- alignItems: "center",
- color:
- timestampStatus == "failed" ||
- timestampStatus == "post-limit"
- ? dangerColor
- : "rgba(255, 255, 255, 0.86)",
- display: "flex",
- fontSize: 12,
- fontWeight: 500,
- height: 16,
- lineHeight: "16px",
- minWidth: "10ch",
- whiteSpace: "nowrap",
- }}
- >
- {timestampStatus == "posted" ? (
- <Box component="span">Posted</Box>
- ) : timestampStatus == "post-limit" ? (
- <Box component="span">
- Post limit reached. Please contact
- support.
- </Box>
- ) : timestampStatus == "failed" ? (
- <Box component="span">Failed</Box>
- ) : (
- <>
- <Box component="span">Posting</Box>
- <Box
- component="span"
- aria-hidden
- sx={{
- display: "inline-block",
- textAlign: "left",
- width: 12,
- }}
- >
- {".".repeat(postingDotCount)}
- </Box>
- </>
- )}
- </Box>
- ) : (
- <Box
- component="time"
- dateTime={new Date(timestampMs).toISOString()}
- sx={{
- alignItems: "center",
- color: "rgba(255, 255, 255, 0.86)",
- display: "flex",
- fontSize: 12,
- fontWeight: 500,
- height: 16,
- lineHeight: "16px",
- whiteSpace: "nowrap",
- }}
- >
- {dateLabel}
- </Box>
- )}
- </Box>
- </Box>
- {!isPostUnavailable && displayCaption && (
- <FeedPhotoCaption caption={displayCaption} />
- )}
</Box>
- {showFooter && (
- <Box
- sx={{
- alignItems: "center",
- boxSizing: "border-box",
- display: "grid",
- gap: "6px",
- gridTemplateColumns: "minmax(0, 1fr) auto",
- minHeight: feedLikeActionSize,
- mt: "8px",
- px: "4px",
- width: "100%",
- }}
- >
- <Box
- component="button"
- type="button"
- aria-label={`Reply privately to ${firstName}'s post`}
- disabled={!canOpenPhoto}
- onClick={() => openPhoto(true)}
- sx={{
- appearance: "none",
- bgcolor: feedActionBackground,
- border: 0,
- borderRadius: "22px",
- color: textSecondary,
- cursor: canOpenPhoto ? "pointer" : "default",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
- height: feedLikeActionSize,
- lineHeight: "20px",
- minWidth: 0,
- overflow: "hidden",
- px: "16px",
- textAlign: "left",
- textOverflow: "ellipsis",
- transition:
- "background-color 120ms ease, transform 120ms ease",
- whiteSpace: "nowrap",
- "&:active": {
- transform: canOpenPhoto
- ? "scale(0.99)"
- : undefined,
- },
- "&:disabled": { color: textSecondary },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:not(:disabled):hover": {
- bgcolor: feedActionBackgroundHover,
- },
- }}
- >
- Reply...
- </Box>
- <FeedLikeButton
- isLiked={isLiked}
- onClick={handleLikeClick}
- popID={likePopID}
- />
- </Box>
- )}
</Box>
);
};
@@ -1335,7 +680,7 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({
sx={{
boxSizing: "border-box",
left: "50%",
- px: feedHorizontalPadding,
+ px: homeHorizontalPadding,
pointerEvents: "none",
position: "fixed",
top: "calc(env(safe-area-inset-top) + 10px)",
@@ -1423,97 +768,26 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({
</Box>
);
-const InviteFriendsToast: React.FC<InviteFriendsToastProps> = ({
- profileLink,
- sharing,
- onClose,
- onSharingChange,
-}) => (
- <SpaceActionToast
- action={
- <SpaceShareInviteButton
- className="green-bg"
- label="Invite"
- profileLink={profileLink}
- sharing={sharing}
- showIcon={false}
- onShareComplete={onClose}
- onShareError={(error) =>
- log.error("Failed to share space invite", error)
- }
- onSharingChange={onSharingChange}
- sx={{
- alignItems: "center",
- bgcolor: green,
- border: 0,
- borderRadius: "14px",
- color: "#FFFFFF",
- cursor: profileLink && !sharing ? "pointer" : "default",
- display: "flex",
- flexShrink: 0,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 700,
- height: 34,
- justifyContent: "center",
- lineHeight: "18px",
- minWidth: 48,
- px: "17px",
- transition: "filter 120ms ease",
- "&:active":
- profileLink && !sharing
- ? { filter: "brightness(0.96)" }
- : undefined,
- "&:disabled": { opacity: 0.45 },
- "&:focus-visible": {
- outline: "2px solid rgba(0 0 0 / 0.72)",
- outlineOffset: 2,
- },
- "&:hover":
- profileLink && !sharing
- ? { filter: "brightness(0.98)" }
- : undefined,
- }}
- />
- }
- animateEntrance
- closeLabel="Close invite prompt"
- icon={
- <HugeiconsIcon icon={UserAdd02Icon} size={24} strokeWidth={1.9} />
- }
- message="Invite friends to your Space"
- onClose={onClose}
- />
-);
-
export const HomeScreen: React.FC<HomeScreenProps> = ({
- feedItems,
+ latestPosts,
friendRequestSentToastName,
- hasFeedLoadMoreError = false,
- hasMoreFeedItems = false,
+ friends,
hasUnreadMessages,
initialPostPhotoFile,
- isFeedLoading = false,
- isFeedLoadingMore = false,
- localFeedPosts = [],
+ isLatestPostsLoading = false,
+ isFriendsLoading = false,
showInstallPrompt = false,
- showInviteFriendsToast = false,
onCreatePost,
- onDeletePost,
- onLoadMoreFeedItems,
onLoadPostAvatar,
onLoadPostImage,
onFriendRequestSentToastClose,
- onInviteFriendsToastClose,
onInitialPostPhotoConsumed,
onOpenFriend,
onOpenMessages,
onOpenProfile,
onReplyToPost,
onSetPostLiked,
- onUpdatePostCaption,
profile,
- profileLink,
viewerSpaceId,
}) => {
const [selectedViewer, setSelectedViewer] =
@@ -1521,27 +795,24 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
const [isDraftPostExitAnimating, setIsDraftPostExitAnimating] =
useState(false);
const [isDraftPostExiting, setIsDraftPostExiting] = useState(false);
- const [isInviteSharing, setIsInviteSharing] = useState(false);
const [isPostPhotoOpening, setIsPostPhotoOpening] = useState(false);
- const [loadedFeedAvatarURLsByKey, setLoadedFeedAvatarURLsByKey] = useState<
+ const [loadedPostAvatarURLsByKey, setLoadedPostAvatarURLsByKey] = useState<
Record<string, string | null>
>({});
- const [loadedFeedImageURLsByKey, setLoadedFeedImageURLsByKey] = useState<
+ const [loadedPostImageURLsByKey, setLoadedPostImageURLsByKey] = useState<
Record<string, string>
>({});
- const [unavailableFeedPostsByKey, setUnavailableFeedPostsByKey] = useState<
+ const [unavailablePostsByKey, setUnavailablePostsByKey] = useState<
Record<string, true>
>({});
- const [feedScrollRequest, setFeedScrollRequest] = useState(0);
const postInputRef = React.useRef<HTMLInputElement | null>(null);
const initialPostPhotoFileRef = React.useRef<File | null>(null);
- const feedLoadMoreRef = React.useRef<HTMLDivElement | null>(null);
const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());
const activeLocalPostObjectUrlRef = React.useRef<string | null>(null);
- const feedAvatarLoadsInFlightRef = React.useRef<
+ const avatarLoadsInFlightRef = React.useRef<
Map<string, Promise<string | null>>
>(new Map());
- const feedImageLoadsInFlightRef = React.useRef<
+ const imageLoadsInFlightRef = React.useRef<
Map<string, Promise<string | undefined>>
>(new Map());
const isPostPhotoButtonDisabled =
@@ -1549,50 +820,30 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
const selectedPhotoFriendID = selectedViewer?.photo.friendID;
const selectedPhotoIsOwn =
Boolean(viewerSpaceId) && selectedPhotoFriendID == viewerSpaceId;
- const desiredFeedEntries = React.useMemo<HomeFeedEntry[]>(() => {
- const localResolvedPostIds = new Set(
- localFeedPosts
- .filter(
- (item) => item.status == "posted" || item.status == "ready",
- )
- .map((item) => item.post.postId),
- );
- return [
- ...localFeedPosts.map(
- (item): HomeFeedEntry => ({
- identity:
- item.status == "posted" || item.status == "ready"
- ? `post:${item.post.postId}`
- : `local:${item.id}`,
- item,
- kind: "local",
- renderKey: `local:${item.id}`,
- }),
+ const latestPostByFriendID = React.useMemo(() => {
+ const posts = new Map<string, SpacePost>();
+ for (const post of latestPosts) {
+ posts.set(post.friendID, post);
+ posts.set(post.spaceId, post);
+ }
+ return posts;
+ }, [latestPosts]);
+ const orderedFriends = React.useMemo(
+ () =>
+ [...friends].sort((a, b) =>
+ (a.spaceId ?? a.id).localeCompare(b.spaceId ?? b.id),
),
- ...feedItems
- .filter((item) => !localResolvedPostIds.has(item.postId))
- .map(
- (item): HomeFeedEntry => ({
- identity: `post:${item.postId}`,
- item,
- kind: "remote",
- renderKey: `post:${item.postId}`,
- }),
- ),
- ];
- }, [feedItems, localFeedPosts]);
- const hasFeedItems = desiredFeedEntries.length > 0;
- const isEmptyFeedLoading = !hasFeedItems && isFeedLoading;
- const showFeedCards = hasFeedItems;
+ [friends],
+ );
+ const postCircleLayout = React.useMemo(
+ () => postCircleLayoutForCount(orderedFriends.length),
+ [orderedFriends.length],
+ );
const isInstallPromptEnabled =
- showInstallPrompt &&
- !friendRequestSentToastName &&
- !showInviteFriendsToast &&
- !selectedViewer;
+ showInstallPrompt && !friendRequestSentToastName && !selectedViewer;
const showUnreadIndicator = hasUnreadMessages === true;
const profileDisplayName =
profile?.fullName.trim() || profile?.username.trim() || "";
- const profileFirstName = profile?.fullName.trim().split(/\s+/)[0];
const revokeLocalPostObjectUrls = React.useCallback(() => {
localPostObjectUrlsRef.current.forEach((objectUrl) =>
URL.revokeObjectURL(objectUrl),
@@ -1601,6 +852,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
}, []);
const releaseLocalPostObjectUrl = React.useCallback((objectUrl: string) => {
localPostObjectUrlsRef.current.delete(objectUrl);
+ URL.revokeObjectURL(objectUrl);
}, []);
const openPostPhotoPicker = () => {
@@ -1608,7 +860,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
postInputRef.current?.click();
};
- const openFeedPhoto = (
+ const openPostPhoto = (
photo: SpaceViewerPhoto,
focusReplyOnOpen = false,
) => {
@@ -1633,46 +885,39 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onClose: () => {
if (!isDraftPostExiting) closeSelectedPhoto();
},
- stateKey: "space-feed-viewer",
+ stateKey: "space-home-viewer",
});
- const deleteSelectedPost = async () => {
- const postId = selectedViewer?.photo.postId;
- if (!postId || !onDeletePost) return;
-
- await onDeletePost(postId);
- };
- const loadedFeedImageURLFor = React.useCallback(
+ const loadedPostImageURLFor = React.useCallback(
(item: SpacePost) =>
- item.imageUrl ??
- loadedFeedImageURLsByKey[feedPostImageCacheKey(item)],
- [loadedFeedImageURLsByKey],
+ item.imageUrl ?? loadedPostImageURLsByKey[postImageCacheKey(item)],
+ [loadedPostImageURLsByKey],
);
- const loadedFeedAvatarURLFor = React.useCallback(
+ const loadedPostAvatarURLFor = React.useCallback(
(item: SpacePost) => {
if (item.avatarUrl) return item.avatarUrl;
if (!item.avatarObjectID) return null;
- return loadedFeedAvatarURLsByKey[feedPostAvatarCacheKey(item)];
+ return loadedPostAvatarURLsByKey[postAvatarCacheKey(item)];
},
- [loadedFeedAvatarURLsByKey],
+ [loadedPostAvatarURLsByKey],
);
- const loadFeedPostImage = React.useCallback(
+ const loadPostImage = React.useCallback(
(item: SpacePost) => {
- const loadedImageUrl = loadedFeedImageURLFor(item);
+ const loadedImageUrl = loadedPostImageURLFor(item);
if (loadedImageUrl) return Promise.resolve(loadedImageUrl);
if (!item.imageAsset || !onLoadPostImage) {
return Promise.resolve(undefined);
}
- const cacheKey = feedPostImageCacheKey(item);
- if (unavailableFeedPostsByKey[cacheKey]) {
+ const cacheKey = postImageCacheKey(item);
+ if (unavailablePostsByKey[cacheKey]) {
return Promise.resolve(undefined);
}
- const inFlight = feedImageLoadsInFlightRef.current.get(cacheKey);
+ const inFlight = imageLoadsInFlightRef.current.get(cacheKey);
if (inFlight) return inFlight;
const load = onLoadPostImage(item.imageAsset)
.then((imageUrl) => {
- setLoadedFeedImageURLsByKey((currentURLs) =>
+ setLoadedPostImageURLsByKey((currentURLs) =>
currentURLs[cacheKey] == imageUrl
? currentURLs
: { ...currentURLs, [cacheKey]: imageUrl },
@@ -1680,9 +925,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
return imageUrl;
})
.catch((error: unknown) => {
- log.warn("Failed to load feed post image", error);
+ log.warn("Failed to load latest post image", error);
if (isSpaceContentError(error)) {
- setUnavailableFeedPostsByKey((current) => ({
+ setUnavailablePostsByKey((current) => ({
...current,
[cacheKey]: true,
}));
@@ -1690,16 +935,16 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
return undefined;
})
.finally(() => {
- feedImageLoadsInFlightRef.current.delete(cacheKey);
+ imageLoadsInFlightRef.current.delete(cacheKey);
});
- feedImageLoadsInFlightRef.current.set(cacheKey, load);
+ imageLoadsInFlightRef.current.set(cacheKey, load);
return load;
},
- [loadedFeedImageURLFor, onLoadPostImage, unavailableFeedPostsByKey],
+ [loadedPostImageURLFor, onLoadPostImage, unavailablePostsByKey],
);
- const loadFeedPostAvatar = React.useCallback(
+ const loadPostAvatar = React.useCallback(
(item: SpacePost) => {
- const loadedAvatarUrl = loadedFeedAvatarURLFor(item);
+ const loadedAvatarUrl = loadedPostAvatarURLFor(item);
if (loadedAvatarUrl !== undefined) {
return Promise.resolve(loadedAvatarUrl);
}
@@ -1707,13 +952,13 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
return Promise.resolve(null);
}
- const cacheKey = feedPostAvatarCacheKey(item);
- const inFlight = feedAvatarLoadsInFlightRef.current.get(cacheKey);
+ const cacheKey = postAvatarCacheKey(item);
+ const inFlight = avatarLoadsInFlightRef.current.get(cacheKey);
if (inFlight) return inFlight;
const load = onLoadPostAvatar(item)
.then((avatarUrl) => {
- setLoadedFeedAvatarURLsByKey((currentURLs) =>
+ setLoadedPostAvatarURLsByKey((currentURLs) =>
currentURLs[cacheKey] == avatarUrl
? currentURLs
: { ...currentURLs, [cacheKey]: avatarUrl },
@@ -1721,8 +966,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
return avatarUrl;
})
.catch((error: unknown) => {
- log.warn("Failed to load feed avatar", error);
- setLoadedFeedAvatarURLsByKey((currentURLs) =>
+ log.warn("Failed to load latest post avatar", error);
+ setLoadedPostAvatarURLsByKey((currentURLs) =>
currentURLs[cacheKey] === null
? currentURLs
: { ...currentURLs, [cacheKey]: null },
@@ -1730,155 +975,58 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
return null;
})
.finally(() => {
- feedAvatarLoadsInFlightRef.current.delete(cacheKey);
+ avatarLoadsInFlightRef.current.delete(cacheKey);
});
- feedAvatarLoadsInFlightRef.current.set(cacheKey, load);
+ avatarLoadsInFlightRef.current.set(cacheKey, load);
return load;
},
- [loadedFeedAvatarURLFor, onLoadPostAvatar],
+ [loadedPostAvatarURLFor, onLoadPostAvatar],
);
- const feedItemFor = (
- item: SpacePost,
- key: React.Key,
- timestampStatus?: FeedTimestampStatus,
- ) => {
- const imageUrl = loadedFeedImageURLFor(item);
- const avatarUrl = loadedFeedAvatarURLFor(item);
- const isAvatarPending = !item.isUnavailable && avatarUrl === undefined;
- const isUnavailable =
- Boolean(item.isUnavailable) ||
- Boolean(unavailableFeedPostsByKey[feedPostImageCacheKey(item)]);
+ const friendPostCircleFor = (friend: FriendProfile, index: number) => {
+ const item = latestPostByFriendID.get(friend.spaceId ?? friend.id);
+ const imageUrl = item ? loadedPostImageURLFor(item) : undefined;
+ const avatarUrl = item ? loadedPostAvatarURLFor(item) : null;
+ const isAvatarPending = Boolean(
+ item && !item.isUnavailable && avatarUrl === undefined,
+ );
+ const isUnavailable = Boolean(
+ item &&
+ (item.isUnavailable ||
+ unavailablePostsByKey[postImageCacheKey(item)]),
+ );
return (
- <FeedItem
- key={key}
- aspectRatio={
- item.width && item.height ? item.width / item.height : 1
- }
- avatarUrl={avatarUrl ?? null}
- caption={item.caption}
- friendID={item.friendID}
+ <FriendPostCircle
+ key={friend.id}
+ avatarAttachmentAngle={avatarAttachmentAngleFor(
+ postCircleLayout.placements[index]!,
+ index,
+ postCircleLayout,
+ )}
+ avatarUrl={avatarUrl}
+ friend={friend}
imageUrl={imageUrl}
isAvatarPending={isAvatarPending}
- isOwnPost={
- Boolean(viewerSpaceId) && item.spaceId == viewerSpaceId
- }
+ isLoading={isFriendsLoading || isLatestPostsLoading}
isUnavailable={isUnavailable}
- name={item.name}
onLoadAvatar={
- isAvatarPending && !isUnavailable
- ? () => loadFeedPostAvatar(item)
+ item && isAvatarPending
+ ? () => loadPostAvatar(item)
: undefined
}
onLoadImage={
- imageUrl || isUnavailable
- ? undefined
- : () => loadFeedPostImage(item)
+ item && !imageUrl && !isUnavailable
+ ? () => loadPostImage(item)
+ : undefined
}
onOpenFriend={onOpenFriend}
- onOpenPhoto={openFeedPhoto}
- onOpenProfile={onOpenProfile}
- onSetPostLiked={onSetPostLiked}
- postId={item.postId}
- spaceId={item.spaceId}
- thumbHash={item.thumbHash}
- timestampStatus={timestampStatus}
- timestampMs={item.timestampMs}
- username={item.username}
- viewerLiked={item.viewerLiked}
- />
- );
- };
- const localFeedItemFor = (item: LocalSpaceFeedPost) => {
- if (item.status == "posted" || item.status == "ready") {
- return feedItemFor(
- item.post,
- item.id,
- item.status == "posted" ? "posted" : undefined,
- );
- }
-
- return (
- <FeedItem
- key={item.id}
- aspectRatio={
- item.width && item.height ? item.width / item.height : 1
- }
- avatarUrl={item.avatarUrl ?? null}
- caption={item.caption}
- friendID={item.friendID}
- imageUrl={item.imageUrl}
- isAvatarPending={false}
- isOwnPost
- name={item.name}
- onOpenProfile={onOpenProfile}
- postId={0}
- timestampStatus={
- item.status == "failed"
- ? item.reason == "post-limit"
- ? "post-limit"
- : "failed"
- : "posting"
- }
- timestampMs={item.timestampMs}
- viewerLiked={false}
+ onOpenPhoto={openPostPhoto}
+ placement={postCircleLayout.placements[index]!}
+ placementCanvasHeight={postCircleLayout.canvasHeight}
+ post={item}
/>
);
};
- React.useEffect(() => {
- if (feedScrollRequest == 0) return;
-
- return scheduleScrollPageToTop();
- }, [feedScrollRequest]);
-
- React.useEffect(() => {
- if (
- hasFeedLoadMoreError ||
- !hasMoreFeedItems ||
- isFeedLoadingMore ||
- !onLoadMoreFeedItems
- ) {
- return;
- }
-
- const element = feedLoadMoreRef.current;
- if (!element) return;
-
- let didRequestLoad = false;
- const loadMore = () => {
- if (didRequestLoad) return;
-
- didRequestLoad = true;
- void Promise.resolve(onLoadMoreFeedItems()).catch(
- (error: unknown) => {
- log.error("Failed to load more space feed", error);
- },
- );
- };
-
- if (
- typeof window == "undefined" ||
- !("IntersectionObserver" in window)
- ) {
- loadMore();
- return;
- }
-
- const observer = new IntersectionObserver(
- (entries) => {
- if (entries.some((entry) => entry.isIntersecting)) loadMore();
- },
- { rootMargin: feedLoadMoreRootMargin },
- );
- observer.observe(element);
- return () => observer.disconnect();
- }, [
- hasFeedLoadMoreError,
- hasMoreFeedItems,
- isFeedLoadingMore,
- onLoadMoreFeedItems,
- ]);
-
const prepareSelectedPostPhoto = React.useCallback(
async (file: File) => {
if (!profile) return;
@@ -2022,7 +1170,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
<Box
component="main"
sx={{
- bgcolor: homeBackground,
+ background:
+ "radial-gradient(ellipse 120% 95% at 50% 58%, rgba(38, 78, 52, 0.16), transparent 72%), #0C1014",
color: textBase,
display: "grid",
minHeight: "100svh",
@@ -2036,7 +1185,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
)}
<Box
sx={{
- bgcolor: homeBackground,
+ bgcolor: "transparent",
boxSizing: "border-box",
maxWidth: "100%",
minHeight: "100svh",
@@ -2057,6 +1206,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
gap: "12px",
gridTemplateColumns: `${headerSideWidth}px minmax(0, 1fr) ${headerSideWidth}px`,
height: headerHeight,
+ color: "#FFF",
maxWidth: "100%",
pb: 2,
position: "relative",
@@ -2069,7 +1219,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
WebkitMaskImage:
"linear-gradient(to bottom, #000 0%, transparent 100%)",
backdropFilter: "blur(4px)",
- background: `linear-gradient(to bottom, ${homeBackground}, rgba(245, 245, 247, 0.35) 75%, transparent)`,
+ background: `linear-gradient(to bottom, ${homeBackground}, rgba(0, 0, 0, 0.35) 75%, transparent)`,
content: '""',
height: "calc(100% + 28px)",
left: 0,
@@ -2115,22 +1265,20 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
p: 0,
placeSelf: "center start",
width: headerActionSize,
- "&:focus-visible": {
- borderRadius: "50%",
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
}}
>
<Box
sx={{
alignItems: "center",
- bgcolor: feedSkeletonElementBackground,
+ bgcolor: "transparent",
+ border: `2.5px solid ${headerChromeColor}`,
borderRadius: "50%",
+ boxSizing: "border-box",
display: "flex",
height: headerAvatarSize,
justifyContent: "center",
overflow: "hidden",
+ p: "2.5px",
width: headerAvatarSize,
}}
>
@@ -2140,23 +1288,22 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
key={profile.avatarUrl ?? "default-avatar"}
sx={{
...avatarFadeSx,
- height: "100%",
- width: "100%",
+ borderRadius: "50%",
+ height: headerAvatarImageSize,
+ overflow: "hidden",
+ width: headerAvatarImageSize,
}}
>
- <SpaceAvatarImage
- src={profile.avatarUrl}
- borderRadius="50%"
- />
+ <SpaceAvatarImage src={profile.avatarUrl} />
</Box>
) : (
<Skeleton
variant="circular"
sx={{
- bgcolor: feedSkeletonElementBackground,
- height: "100%",
+ bgcolor: mediaSkeletonElementBackground,
+ height: headerAvatarImageSize,
transform: "none",
- width: "100%",
+ width: headerAvatarImageSize,
}}
/>
)}
@@ -2164,26 +1311,27 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
</Box>
<Box
sx={{
+ alignItems: "center",
alignSelf: "center",
- color: textBase,
+ bgcolor: headerChromeColor,
+ borderRadius: "999px",
+ boxSizing: "border-box",
+ display: "flex",
+ height: 36,
+ justifyContent: "center",
justifySelf: "center",
lineHeight: 0,
minWidth: 0,
overflow: "visible",
placeSelf: "center",
- width: 61,
+ px: "16px",
}}
>
<Box
component="img"
alt="Space"
src="/images/space.svg"
- sx={{
- display: "block",
- filter: "invert(1)",
- height: 18,
- width: "auto",
- }}
+ sx={{ display: "block", height: 18, width: "auto" }}
/>
</Box>
<Box
@@ -2201,7 +1349,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
bgcolor: "transparent",
border: 0,
boxSizing: "border-box",
- color: textBase,
+ color: "#FFF",
cursor: onOpenMessages ? "pointer" : "default",
display: "flex",
fontSize: 0,
@@ -2221,48 +1369,42 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
},
}}
>
- <HugeiconsIcon
- icon={BubbleChatIcon}
- size={headerIconSize}
- strokeWidth={1.5}
- />
- {showUnreadIndicator && (
- <Box
- aria-hidden
- sx={{
- "@keyframes spaceUnreadBadgePing": {
- "75%, 100%": {
- opacity: 0,
- transform: "scale(2.5)",
- },
- },
- "@media (prefers-reduced-motion: reduce)": {
- "&::after": { display: "none" },
- },
- bgcolor: dangerColor,
- border: `2px solid ${homeBackground}`,
- borderRadius: "50%",
- height: 13,
- position: "absolute",
- right: 7,
- top: 7,
- width: 13,
- zIndex: 0,
- "&::after": {
- animation:
- "spaceUnreadBadgePing 1.25s cubic-bezier(0, 0, 0.2, 1) 1",
+ <Box
+ aria-hidden
+ sx={{
+ alignItems: "center",
+ bgcolor: headerChromeColor,
+ borderRadius: "50%",
+ display: "flex",
+ height: headerChatCircleSize,
+ justifyContent: "center",
+ position: "relative",
+ width: headerChatCircleSize,
+ "& svg path:first-of-type": { display: "none" },
+ }}
+ >
+ <HugeiconsIcon
+ icon={BubbleChatIcon}
+ size={headerIconSize}
+ strokeWidth={2.5}
+ />
+ {showUnreadIndicator && (
+ <Box
+ sx={{
bgcolor: dangerColor,
+ border: `2px solid ${headerChromeColor}`,
borderRadius: "50%",
- content: '""',
- inset: 0,
- opacity: 0.75,
- pointerEvents: "none",
+ boxSizing: "border-box",
+ height: 11,
position: "absolute",
- zIndex: -1,
- },
- }}
- />
- )}
+ right: 5.5,
+ top: 6,
+ width: 11,
+ zIndex: 1,
+ }}
+ />
+ )}
+ </Box>
</Box>
</Box>
<Box
@@ -2270,92 +1412,20 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
boxSizing: "border-box",
display: "flex",
flexDirection: "column",
- gap: 0,
- justifyContent: showFeedCards ? "flex-start" : "center",
+ justifyContent:
+ orderedFriends.length <= 12
+ ? "center"
+ : "flex-start",
minHeight: "calc(100svh - 64px)",
minWidth: 0,
- pb: showFeedCards
- ? "calc(env(safe-area-inset-bottom) + 112px)"
- : "56px",
- px: showFeedCards ? feedHorizontalPadding : 0,
- pt: showFeedCards ? "4px" : 0,
+ pb: "calc(env(safe-area-inset-bottom) + 112px)",
+ px: homeHorizontalPadding,
+ pt: "12px",
width: "100%",
}}
>
- {initialPostPhotoFile ? null : hasFeedItems ? (
- <>
- <FeedMotionList
- entries={desiredFeedEntries}
- renderEntry={(entry) =>
- entry.kind == "local"
- ? localFeedItemFor(entry.item)
- : feedItemFor(
- entry.item,
- entry.item.postId,
- )
- }
- />
- {hasMoreFeedItems && onLoadMoreFeedItems && (
- <Box
- ref={feedLoadMoreRef}
- aria-live="polite"
- sx={{
- alignItems: "center",
- alignSelf: "center",
- display: "flex",
- height: 48,
- justifyContent: "center",
- mb: 0,
- mt: "12px",
- width: "100%",
- }}
- >
- {hasFeedLoadMoreError ? (
- <Box
- component="button"
- type="button"
- aria-label="Retry loading posts"
- onClick={onLoadMoreFeedItems}
- sx={{
- alignItems: "center",
- appearance: "none",
- bgcolor: paleGreen,
- border: 0,
- borderRadius: "18px",
- color: green,
- cursor: "pointer",
- display: "inline-flex",
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 600,
- height: spaceTouchTargetSize,
- justifyContent: "center",
- lineHeight: "18px",
- minWidth: 116,
- px: "18px",
- whiteSpace: "nowrap",
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": {
- bgcolor: "#DDF1E1",
- },
- }}
- >
- Retry
- </Box>
- ) : (
- <SpaceLoadingSpinner
- ariaLabel="Loading more posts"
- size={22}
- />
- )}
- </Box>
- )}
- </>
- ) : isEmptyFeedLoading ? (
+ {initialPostPhotoFile ? null : isFriendsLoading &&
+ orderedFriends.length == 0 ? (
<Box
sx={{
alignItems: "center",
@@ -2364,62 +1434,46 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
width: "100%",
}}
>
- <SpaceLoadingSpinner ariaLabel="Loading posts" />
+ <SpaceLoadingSpinner ariaLabel="Loading friends" />
+ </Box>
+ ) : orderedFriends.length > 0 ? (
+ <Box
+ component="ul"
+ aria-label="Friends' latest posts"
+ sx={{
+ aspectRatio: `1 / ${postCircleLayout.canvasHeight}`,
+ flexShrink: 0,
+ m: 0,
+ p: 0,
+ position: "relative",
+ width: "100%",
+ }}
+ >
+ {orderedFriends.map(friendPostCircleFor)}
</Box>
) : (
<Box
+ component="p"
sx={{
- alignItems: "center",
- display: "flex",
- flexDirection: "column",
- justifyContent: "center",
+ color: textSecondary,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ m: 0,
px: 3,
textAlign: "center",
- width: "100%",
}}
>
- <Box
- component="img"
- alt=""
- src="/images/ducky-camera.svg"
- sx={{
- display: "block",
- height: "auto",
- width: 220,
- "@media (max-width: 340px)": { width: 196 },
- }}
- />
- <Box
- component="p"
- sx={{
- color: textSecondary,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
- lineHeight: "20px",
- m: 0,
- mt: emptyFeedItemGap,
- maxWidth: 280,
- }}
- >
- Welcome to your space, {profileFirstName}.
- <br />
- Share a little moment from your day.
- </Box>
- <SpaceInlinePostButton
- disabled={isPostPhotoButtonDisabled}
- onClick={openPostPhotoPicker}
- />
+ Your friends’ latest posts will show up here.
</Box>
)}
</Box>
- {hasFeedItems && (
- <SpacePostFloatingActionButton
- disabled={isPostPhotoButtonDisabled}
- onClick={openPostPhotoPicker}
- />
- )}
+ <SpacePostFloatingActionButton
+ disabled={isPostPhotoButtonDisabled}
+ onClick={openPostPhotoPicker}
+ />
{selectedViewer && (
<SpaceFileViewer
focusReplyOnOpen={selectedViewer.focusReplyOnOpen}
@@ -2463,13 +1517,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
? onReplyToPost
: undefined
}
- onDeletePost={
- selectedPhotoIsOwn &&
- selectedViewer.photo.postId &&
- onDeletePost
- ? deleteSelectedPost
- : undefined
- }
onPublishDraftPost={
selectedViewer.draftFile && onCreatePost
? (caption, edit) => {
@@ -2480,15 +1527,15 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
cropArea: edit.cropArea,
file: selectedViewer.draftFile!,
height: edit.height,
- previewUrl,
rotationDegrees:
edit.rotationDegrees,
width: edit.width,
},
caption,
);
- releaseLocalPostObjectUrl(previewUrl);
- return publishPromise;
+ return publishPromise.finally(() =>
+ releaseLocalPostObjectUrl(previewUrl),
+ );
}
: undefined
}
@@ -2498,13 +1545,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onDraftPostExitStart={() => {
setIsDraftPostExiting(true);
}}
- onDraftPostPublished={() => {
- setFeedScrollRequest((request) => request + 1);
- }}
onSetPostLiked={onSetPostLiked}
- onUpdatePostCaption={
- selectedPhotoIsOwn ? onUpdatePostCaption : undefined
- }
/>
)}
{friendRequestSentToastName ? (
@@ -2512,13 +1553,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
message={`Friend request sent to @${friendRequestSentToastName}`}
onClose={onFriendRequestSentToastClose}
/>
- ) : showInviteFriendsToast ? (
- <InviteFriendsToast
- profileLink={profileLink}
- sharing={isInviteSharing}
- onClose={onInviteFriendsToastClose}
- onSharingChange={setIsInviteSharing}
- />
) : (
<SpacePWAInstallPrompt enabled={isInstallPromptEnabled} />
)}
diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.ts
index 08d6b2f178..c364974463 100644
--- a/web/apps/space/src/services/space.ts
+++ b/web/apps/space/src/services/space.ts
@@ -1214,6 +1214,25 @@ export const loadCurrentSpaceProfilePostsPage = async (
}
};
+export const loadCurrentSpaceLatestPost = async (
+ spaceId: string,
+ viewerSpaceId: string,
+): Promise<SpacePost | null> => {
+ const ctx = await ensureCurrentSpaceContext();
+ try {
+ const page = (await ctx.listPosts(
+ spaceId,
+ viewerSpaceId,
+ null,
+ 1,
+ )) as SpacePostPageResponse;
+ const post = page.items?.[0];
+ return post ? profilePostFromPost(post) : null;
+ } finally {
+ releaseCurrentSpaceContext(ctx);
+ }
+};
+
export const loadCurrentSpacePost = async (
spaceId: string,
postId: number,
diff --git a/web/apps/space/src/state/AppStateProvider.tsx b/web/apps/space/src/state/AppStateProvider.tsx
index 97e04163b0..9c47e27c19 100644
--- a/web/apps/space/src/state/AppStateProvider.tsx
+++ b/web/apps/space/src/state/AppStateProvider.tsx
@@ -61,8 +61,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
const [profileLoadError, setProfileLoadError] = useState<string>();
const [profileLoadStatus, setProfileLoadStatus] =
useState<SpaceProfileLoadStatus>("loading");
- const [skipNextHomeFeedSkeleton, setSkipNextHomeFeedSkeleton] =
- useState(false);
const [signupEmail, setSignupEmail] = useState("");
const avatarURLRef = useRef<string | null>(null);
const coverURLRef = useRef<string | null>(null);
@@ -235,7 +233,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
setPendingProfileCoverFile(null);
setPendingCreateProfile(null);
setOnboardingEntrySource("direct");
- setSkipNextHomeFeedSkeleton(false);
setLocalFeedPosts([]);
setFriends(initialFriends());
}, [applyProfile]);
@@ -290,7 +287,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
profile,
profileLoadError,
profileLoadStatus,
- skipNextHomeFeedSkeleton,
refreshProfile,
resetAfterLogout,
setFriends,
@@ -304,7 +300,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
setPendingProfileCoverFile,
setPendingCreateProfile,
setProfile: applyProfile,
- setSkipNextHomeFeedSkeleton,
setSignupEmail,
signupEmail,
}),
@@ -322,7 +317,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
profile,
profileLoadError,
profileLoadStatus,
- skipNextHomeFeedSkeleton,
refreshProfile,
resetAfterLogout,
signupEmail,
diff --git a/web/apps/space/src/state/app-state.tsx b/web/apps/space/src/state/app-state.tsx
index 55c4970c55..9e6d5c57b7 100644
--- a/web/apps/space/src/state/app-state.tsx
+++ b/web/apps/space/src/state/app-state.tsx
@@ -70,7 +70,6 @@ export interface SpaceAppState {
profile: SetupProfile | null;
profileLoadError?: string;
profileLoadStatus: SpaceProfileLoadStatus;
- skipNextHomeFeedSkeleton: boolean;
signupEmail: string;
refreshProfile: (
options?: RefreshSpaceProfileOptions,
@@ -101,7 +100,6 @@ export interface SpaceAppState {
React.SetStateAction<PendingCreateProfile | null>
>;
setProfile: (profile: SetupProfile | null) => void;
- setSkipNextHomeFeedSkeleton: React.Dispatch<React.SetStateAction<boolean>>;
setSignupEmail: React.Dispatch<React.SetStateAction<string>>;
}