Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove the current user tile from Space home

Anand Baburajan433e8201debc
diff --git a/web/apps/space/src/components/NewPostButton.tsx b/web/apps/space/src/components/NewPostButton.tsx
new file mode 100644
index 0000000000..06a98bda25
--- /dev/null
+++ b/web/apps/space/src/components/NewPostButton.tsx
@@ -0,0 +1,51 @@
+import { Add01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box } from "@mui/material";
+import React from "react";
+import { useSpaceAppState } from "state/app-state";
+
+const green = "#08C225";
+
+export const SpaceNewPostButton: React.FC<{
+ isDisabled?: boolean;
+ onClick: () => void;
+}> = ({ isDisabled = false, onClick }) => {
+ const { postPublication } = useSpaceAppState();
+ const disabled = isDisabled || postPublication?.phase == "posting";
+
+ return (
+ <Box
+ className="green-bg"
+ component="button"
+ type="button"
+ aria-label="New post"
+ disabled={disabled}
+ onClick={onClick}
+ sx={{
+ alignItems: "center",
+ alignSelf: "flex-end",
+ appearance: "none",
+ bgcolor: green,
+ border: 0,
+ borderRadius: "50%",
+ boxShadow: "0 4px 12px rgba(0, 0, 0, 0.32)",
+ color: "#FFFFFF",
+ cursor: disabled ? "default" : "pointer",
+ display: "flex",
+ flexShrink: 0,
+ height: 64,
+ justifyContent: "center",
+ opacity: disabled ? 0.6 : 1,
+ p: 0,
+ width: 64,
+ "&:hover:not(:disabled)": { bgcolor: "#07B422" },
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 3,
+ },
+ }}
+ >
+ <HugeiconsIcon icon={Add01Icon} size={32} strokeWidth={2} />
+ </Box>
+ );
+};
diff --git a/web/apps/space/src/components/OwnPostTile.tsx b/web/apps/space/src/components/OwnPostTile.tsx
deleted file mode 100644
index a9ecf3d8dd..0000000000
--- a/web/apps/space/src/components/OwnPostTile.tsx
+++ /dev/null
@@ -1,388 +0,0 @@
-import { Add01Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import { Box, Fade, Skeleton } from "@mui/material";
-import { SpaceAvatarImage } from "components/AvatarImage";
-import log from "ente-base/log";
-import React from "react";
-import type { SetupProfile } from "screens/SetupProfileScreen";
-import type { SpacePost, SpacePostAssetURLLoader } from "services/space";
-import { useSpaceAppState, type SpacePostPublishPhase } from "state/app-state";
-import {
- spaceAppBackground,
- spaceSurface,
- spaceTextMuted,
-} from "styles/colors";
-import {
- spacePostTileRadius,
- spaceTileCircleInset,
- spaceTileCornerStyles,
-} from "styles/tiles";
-import { homeTileGap } from "utils/home-tile-layout";
-import { spaceDefaultCoverImagePath } from "utils/post-image";
-import { thumbHashDataURLFromBase64 } from "utils/thumbhash";
-
-const green = "#08C225";
-const actionSize = 64;
-
-const PostStatus: React.FC<{
- phase: SpacePostPublishPhase;
- expiresAtMs?: number;
-}> = ({ phase, expiresAtMs }) => {
- const [dotCount, setDotCount] = React.useState(1);
- const [isVisible, setIsVisible] = React.useState(
- () => !expiresAtMs || expiresAtMs > Date.now(),
- );
-
- React.useEffect(() => {
- setIsVisible(!expiresAtMs || expiresAtMs > Date.now());
- if (!expiresAtMs) return;
-
- const timeoutID = window.setTimeout(
- () => setIsVisible(false),
- Math.max(0, expiresAtMs - Date.now()),
- );
- return () => window.clearTimeout(timeoutID);
- }, [expiresAtMs]);
-
- React.useEffect(() => {
- if (phase != "posting") return;
-
- setDotCount(1);
- const intervalID = window.setInterval(() => {
- setDotCount((count) => (count % 3) + 1);
- }, 500);
- return () => window.clearInterval(intervalID);
- }, [phase]);
-
- const label =
- phase == "posting"
- ? "Posting"
- : phase == "posted"
- ? "Posted"
- : "Failed";
-
- return (
- <Fade in={isVisible} appear={false} timeout={200} unmountOnExit>
- <Box
- role="status"
- aria-label={label}
- sx={{
- bgcolor:
- phase == "posted"
- ? green
- : phase == "failed"
- ? "#F63A3A"
- : "rgba(0, 0, 0, 0.64)",
- borderRadius: "999px",
- color: "#FFFFFF",
- display: "inline-flex",
- fontSize: 12,
- fontWeight: 500,
- lineHeight: "16px",
- pointerEvents: "none",
- position: "absolute",
- px: "10px",
- py: "4px",
- right: "var(--space-tile-padding)",
- top: "50%",
- transform: "translateY(-50%)",
- whiteSpace: "nowrap",
- }}
- >
- {label}
- {phase == "posting" && (
- <Box component="span" aria-hidden sx={{ width: 12 }}>
- {".".repeat(dotCount)}
- </Box>
- )}
- </Box>
- </Fade>
- );
-};
-
-interface SpaceOwnPostTileProps {
- profile: SetupProfile | null;
- post?: SpacePost;
- avatarSize?: number;
- isLoading?: boolean;
- isUnavailable?: boolean;
- isNewPostDisabled?: boolean;
- onLoadPostImage?: SpacePostAssetURLLoader;
- onOpenPost?: () => void;
- onOpenProfile?: () => void;
- onNewPost: () => void;
-}
-
-export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({
- profile,
- post,
- avatarSize = 36,
- isLoading = false,
- isUnavailable = false,
- isNewPostDisabled = false,
- onLoadPostImage,
- onOpenPost,
- onOpenProfile,
- onNewPost,
-}) => {
- const { cachedProfileAvatarUrl, postPublication } = useSpaceAppState();
- const tileRef = React.useRef<HTMLElement>(null);
- const publishPhase =
- postPublication?.post == post ? postPublication?.phase : undefined;
- const hasPublication = Boolean(publishPhase);
- const avatarUrl = profile ? profile.avatarUrl : cachedProfileAvatarUrl;
- const isAvatarLoading =
- !avatarUrl && (!profile || Boolean(profile.avatarObjectID));
- const [loadedImage, setLoadedImage] = React.useState<{
- post: SpacePost;
- url?: string;
- failed?: boolean;
- }>();
- const postImage = loadedImage?.post == post ? loadedImage : undefined;
- const imageUrl = post?.imageUrl ?? postImage?.url;
- const thumbHashDataURL = React.useMemo(
- () => thumbHashDataURLFromBase64(post?.thumbHash),
- [post?.thumbHash],
- );
- const unavailable =
- isUnavailable || post?.isUnavailable || postImage?.failed;
- const canOpenPost = Boolean(
- post && onOpenPost && (!publishPhase || publishPhase == "posted"),
- );
- const loading =
- isLoading || Boolean(post?.imageAsset && !imageUrl && !unavailable);
- const isEmpty = !post && !loading && !unavailable;
- const coverUrl = isEmpty ? spaceDefaultCoverImagePath : imageUrl;
-
- React.useEffect(() => {
- if (hasPublication)
- tileRef.current?.scrollIntoView({ block: "nearest" });
- }, [hasPublication]);
-
- React.useEffect(() => {
- if (!post?.imageAsset || post.imageUrl || !onLoadPostImage) return;
-
- let cancelled = false;
- void onLoadPostImage(post.imageAsset)
- .then((url) => {
- if (!cancelled) setLoadedImage({ post, url });
- })
- .catch((error: unknown) => {
- log.warn("Failed to load own latest post image", error);
- if (!cancelled) setLoadedImage({ post, failed: true });
- });
- return () => {
- cancelled = true;
- };
- }, [onLoadPostImage, post]);
-
- return (
- <Box sx={{ display: "flex", flexShrink: 0, gap: `${homeTileGap}px` }}>
- <Box
- ref={tileRef}
- component="section"
- aria-label="Your latest post"
- sx={{
- ...spaceTileCornerStyles(spacePostTileRadius),
- bgcolor: unavailable ? spaceSurface : "transparent",
- flex: 1,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- height: actionSize,
- minWidth: 0,
- overflow: "hidden",
- position: "relative",
- "& button:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: -4,
- },
- }}
- >
- <Box
- component="button"
- type="button"
- aria-label="Open your posts"
- disabled={!canOpenPost}
- onClick={onOpenPost}
- sx={{
- appearance: "none",
- bgcolor: "transparent",
- border: 0,
- borderRadius: "inherit",
- color: spaceTextMuted,
- cursor: canOpenPost ? "pointer" : "default",
- font: "inherit",
- inset: 0,
- p: 0,
- position: "absolute",
- width: "100%",
- }}
- >
- {(coverUrl || thumbHashDataURL) && !unavailable ? (
- <>
- {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%",
- }}
- />
- )}
- {coverUrl && (
- <Box
- component="img"
- alt={
- isEmpty
- ? ""
- : post?.caption ||
- "Your latest post"
- }
- src={coverUrl}
- onError={() =>
- post &&
- setLoadedImage({ post, failed: true })
- }
- sx={{
- display: "block",
- height: "100%",
- objectFit: "cover",
- position: "relative",
- width: "100%",
- }}
- />
- )}
- </>
- ) : !loading ? (
- <Box
- sx={{
- fontSize: 12,
- lineHeight: "18px",
- pl: `calc(var(--space-tile-padding) * 2 + ${avatarSize}px)`,
- pr: "var(--space-tile-padding)",
- textAlign: "left",
- }}
- >
- Couldn&apos;t load your latest post
- </Box>
- ) : null}
- {isEmpty && (
- <Box
- sx={{
- alignItems: "center",
- bgcolor: "rgba(0, 0, 0, 0.4)",
- color: "#FFFFFF",
- display: "flex",
- fontSize: 12,
- fontWeight: 500,
- inset: 0,
- lineHeight: "18px",
- pl: `calc(var(--space-tile-padding) * 2 + ${avatarSize}px)`,
- position: "absolute",
- pr: "var(--space-tile-padding)",
- textAlign: "left",
- }}
- >
- Your latest post will show up here
- </Box>
- )}
- </Box>
- <Box
- component="button"
- type="button"
- aria-label="Open your profile"
- onClick={onOpenProfile}
- sx={{
- alignItems: "center",
- appearance: "none",
- bgcolor: "transparent",
- border: 0,
- borderRadius: "50%",
- cursor: onOpenProfile ? "pointer" : "default",
- display: "flex",
- height: avatarSize,
- justifyContent: "center",
- left: spaceTileCircleInset(avatarSize),
- p: 0,
- position: "absolute",
- top: "50%",
- transform: "translateY(-50%)",
- width: avatarSize,
- }}
- >
- <Box
- sx={{
- backgroundClip: "padding-box",
- bgcolor: spaceAppBackground,
- border: "3px solid rgba(28, 28, 30, 0.75)",
- borderRadius: "50%",
- boxSizing: "border-box",
- flexShrink: 0,
- height: avatarSize,
- overflow: "hidden",
- width: avatarSize,
- }}
- >
- {isAvatarLoading ? (
- <Skeleton
- variant="circular"
- sx={{
- bgcolor: spaceSurface,
- height: "100%",
- width: "100%",
- }}
- />
- ) : (
- <SpaceAvatarImage src={avatarUrl} />
- )}
- </Box>
- </Box>
- {publishPhase && (
- <PostStatus
- phase={publishPhase}
- expiresAtMs={postPublication?.statusExpiresAtMs}
- />
- )}
- </Box>
- <Box
- className="green-bg"
- component="button"
- type="button"
- aria-label="New post"
- disabled={isNewPostDisabled}
- onClick={onNewPost}
- sx={{
- alignItems: "center",
- appearance: "none",
- bgcolor: green,
- border: 0,
- borderRadius: "50%",
- boxShadow: "0 4px 12px rgba(0, 0, 0, 0.32)",
- color: "#FFFFFF",
- cursor: isNewPostDisabled ? "default" : "pointer",
- display: "flex",
- flexShrink: 0,
- height: actionSize,
- justifyContent: "center",
- opacity: isNewPostDisabled ? 0.6 : 1,
- p: 0,
- width: actionSize,
- "&:hover": { bgcolor: "#07B422" },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 3,
- },
- }}
- >
- <HugeiconsIcon icon={Add01Icon} size={32} strokeWidth={2} />
- </Box>
- </Box>
- );
-};
diff --git a/web/apps/space/src/hooks/use-own-latest-post.ts b/web/apps/space/src/hooks/use-own-latest-post.ts
deleted file mode 100644
index 8bbf613ab0..0000000000
--- a/web/apps/space/src/hooks/use-own-latest-post.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import log from "ente-base/log";
-import { useCallback, useEffect, useState } from "react";
-import { loadCachedOwnLatestPost } from "services/post-cache";
-import {
- deleteCurrentPost,
- loadCurrentSpaceProfilePostsPage,
- updateCurrentPostCaption,
- type SpacePost,
-} from "services/space";
-import { useSpaceAppState } from "state/app-state";
-
-export const useOwnLatestPost = (spaceId: string | undefined) => {
- const { postPublication, setPostPublication } = useSpaceAppState();
- const isPublishingPost = postPublication?.phase == "posting";
- const [ownLatestPost, setOwnLatestPost] = useState<SpacePost>();
- const [ownPostsVersion, setOwnPostsVersion] = useState(0);
- const [isOwnLatestPostLoading, setIsOwnLatestPostLoading] = useState(true);
- const [isOwnLatestPostUnavailable, setIsOwnLatestPostUnavailable] =
- useState(false);
-
- useEffect(() => {
- setOwnLatestPost(undefined);
- setIsOwnLatestPostLoading(true);
- setIsOwnLatestPostUnavailable(false);
- if (!spaceId || isPublishingPost) return;
-
- let cancelled = false;
- let cachedPost: SpacePost | undefined;
- void loadCachedOwnLatestPost(spaceId)
- .then((post) => {
- if (cancelled) return;
- cachedPost = post;
- if (post) {
- setOwnLatestPost(post);
- setIsOwnLatestPostLoading(false);
- }
- return loadCurrentSpaceProfilePostsPage(spaceId, spaceId);
- })
- .then((page) => {
- if (!cancelled && page) setOwnLatestPost(page.items[0]);
- })
- .catch((error: unknown) => {
- log.error("Failed to load own latest Space post", error);
- if (!cancelled && !cachedPost)
- setIsOwnLatestPostUnavailable(true);
- })
- .finally(() => {
- if (!cancelled) setIsOwnLatestPostLoading(false);
- });
- return () => {
- cancelled = true;
- };
- }, [spaceId, ownPostsVersion, isPublishingPost]);
-
- const deleteOwnPost = useCallback(
- async (postId: number) => {
- if (!spaceId) throw new Error("Missing space.");
-
- await deleteCurrentPost(spaceId, postId);
- if (
- ownLatestPost?.postId == postId ||
- postPublication?.post.postId == postId
- ) {
- setPostPublication((current) =>
- current?.post.postId == postId ? null : current,
- );
- setOwnLatestPost(undefined);
- setIsOwnLatestPostLoading(true);
- setOwnPostsVersion((version) => version + 1);
- }
- },
- [spaceId, ownLatestPost?.postId, postPublication, setPostPublication],
- );
-
- const updateOwnPostCaption = useCallback(
- async (postId: number, caption: string) => {
- if (!spaceId) throw new Error("Missing space.");
-
- await updateCurrentPostCaption(spaceId, postId, caption);
- setPostPublication((current) =>
- current?.post.postId == postId
- ? {
- ...current,
- post: {
- ...current.post,
- caption: caption.trim() || undefined,
- },
- }
- : current,
- );
- setOwnLatestPost((post) =>
- post?.postId == postId
- ? { ...post, caption: caption.trim() || undefined }
- : post,
- );
- },
- [spaceId, setPostPublication],
- );
-
- return {
- ownLatestPost: postPublication?.post ?? ownLatestPost,
- isOwnLatestPostLoading: !postPublication && isOwnLatestPostLoading,
- isOwnLatestPostUnavailable:
- !postPublication && isOwnLatestPostUnavailable,
- deleteOwnPost,
- updateOwnPostCaption,
- };
-};
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 6b0858c034..1bc002ab9e 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -4,7 +4,6 @@ import { SpaceFriendRequestCanceledToast } from "components/FriendRequestCancele
import { SpacePageMeta } from "components/PageMeta";
import { SpaceRouteFallback } from "components/RouteFallback";
import log from "ente-base/log";
-import { useOwnLatestPost } from "hooks/use-own-latest-post";
import React, { useEffect, useState } from "react";
import { HomeScreen } from "screens/HomeScreen";
import {
@@ -62,13 +61,6 @@ const Page: React.FC = () => {
);
const [latestPosts, setLatestPosts] = useState<SpacePost[]>([]);
const [spaceId, setSpaceId] = useState<string>();
- const {
- ownLatestPost,
- isOwnLatestPostLoading,
- isOwnLatestPostUnavailable,
- deleteOwnPost,
- updateOwnPostCaption,
- } = useOwnLatestPost(spaceId);
const [unreadPosts, setUnreadPosts] = useState<SpacePost[]>([]);
const [hasUnreadMessages, setHasUnreadMessages] = useState<boolean>();
const [isLatestPostsLoading, setIsLatestPostsLoading] = useState(true);
@@ -258,9 +250,6 @@ const Page: React.FC = () => {
<>
<SpacePageMeta themeColor={spaceAppBackgroundColor} />
<HomeScreen
- ownLatestPost={ownLatestPost}
- isOwnLatestPostLoading={isOwnLatestPostLoading}
- isOwnLatestPostUnavailable={isOwnLatestPostUnavailable}
latestPosts={latestPosts}
unreadPosts={unreadPosts}
friendRequestSentToastName={friendRequestSentToastName}
@@ -345,8 +334,6 @@ const Page: React.FC = () => {
}
: undefined
}
- onDeletePost={deleteOwnPost}
- onUpdatePostCaption={updateOwnPostCaption}
onOpenFriend={(friendID, username, section) => {
const friend = friends.find(
(candidate) =>
@@ -427,13 +414,6 @@ const Page: React.FC = () => {
);
await refreshUnreadStatus(profile.spaceId);
}}
- onOpenOwnPost={() =>
- void router.push(
- `${spaceRoutes.profile}?section=latest`,
- undefined,
- { scroll: false },
- )
- }
onOpenProfile={
profile
? () => void router.push(spaceRoutes.profile)
diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsx
index 89b29074d5..e77b0afd19 100644
--- a/web/apps/space/src/pages/layout-demo.tsx
+++ b/web/apps/space/src/pages/layout-demo.tsx
@@ -5,7 +5,7 @@ import { SpaceAddFriendDialog } from "components/AddFriendDialog";
import { SpaceAddFriendTile } from "components/AddFriendTile";
import { SpaceFileViewer } from "components/FileViewer";
import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";
-import { SpaceOwnPostTile } from "components/OwnPostTile";
+import { SpaceNewPostButton } from "components/NewPostButton";
import { useBrowserBackClose } from "hooks/use-browser-back-close";
import React from "react";
import { FriendPostTile } from "screens/HomeScreen";
@@ -30,18 +30,6 @@ const demoProfile: SetupProfile = {
spaceId: "demo-self",
username: "you",
};
-const demoOwnPosts: SpacePost[] = [
- spaceDefaultCoverImagePath,
- "/images/invite-bg.jpg",
-].map((imageUrl, index) => ({
- friendID: "demo-self",
- imageUrl,
- name: demoProfile.fullName,
- postId: 100 - index,
- spaceId: "demo-self",
- timestampMs: 1_700_000_000_000 - index * 86_400_000,
- viewerLiked: false,
-}));
interface CanvasSize {
height: number;
@@ -144,36 +132,18 @@ const LayoutDemoPage: React.FC = () => {
const router = useSpaceRouter();
const [isAddFriendOpen, setIsAddFriendOpen] = React.useState(false);
const [profileLink, setProfileLink] = React.useState<string>();
- const [{ friendCount, ownPosts }, setDemo] = React.useState({
- friendCount: 0,
- ownPosts: [] as SpacePost[],
- });
+ const [friendCount, setFriendCount] = React.useState(0);
const changeFriendCount = React.useCallback((delta: number) => {
- setDemo(({ friendCount }) => {
- const count = Math.max(
- 0,
- Math.min(maximumHomeTileCount, friendCount + delta),
- );
- return {
- friendCount: count,
- ownPosts: count % 2 == 0 ? [] : demoOwnPosts,
- };
- });
+ setFriendCount((count) =>
+ Math.max(0, Math.min(maximumHomeTileCount, count + delta)),
+ );
}, []);
- const [ownViewerPosts, setOwnViewerPosts] = React.useState<SpacePost[]>([]);
- const [ownPostIndex, setOwnPostIndex] = React.useState<number>();
- const ownViewerOpen = ownPostIndex !== undefined;
+ const [isPostPreviewOpen, setIsPostPreviewOpen] = React.useState(false);
useBrowserBackClose({
- open: ownViewerOpen,
- onClose: () => setOwnPostIndex(undefined),
+ open: isPostPreviewOpen,
+ onClose: () => setIsPostPreviewOpen(false),
stateKey: "space-layout-demo-viewer",
});
- const ownPostPhotos = ownViewerPosts.map((post) => ({
- ...post,
- alt: "Your post",
- avatarUrl: demoProfile.avatarUrl,
- imageUrl: post.imageUrl ?? "",
- }));
const [canvasSize, setCanvasSize] = React.useState<CanvasSize>({
height: 0,
width: 0,
@@ -195,7 +165,7 @@ const LayoutDemoPage: React.FC = () => {
}, []);
React.useEffect(() => {
- if (ownViewerOpen || isAddFriendOpen) return;
+ if (isPostPreviewOpen || isAddFriendOpen) return;
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key == "ArrowLeft") {
@@ -206,7 +176,7 @@ const LayoutDemoPage: React.FC = () => {
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
- }, [changeFriendCount, isAddFriendOpen, ownViewerOpen]);
+ }, [changeFriendCount, isAddFriendOpen, isPostPreviewOpen]);
const layout = homeTileLayout(
friendCount,
@@ -368,19 +338,8 @@ const LayoutDemoPage: React.FC = () => {
</>
)}
</Box>
- <SpaceOwnPostTile
- profile={demoProfile}
- post={ownPosts[0]}
- onNewPost={() =>
- setDemo((current) => ({
- ...current,
- ownPosts: demoOwnPosts,
- }))
- }
- onOpenPost={() => {
- setOwnViewerPosts(ownPosts);
- setOwnPostIndex(0);
- }}
+ <SpaceNewPostButton
+ onClick={() => setIsPostPreviewOpen(true)}
/>
</Box>
<SpaceAddFriendDialog
@@ -395,41 +354,18 @@ const LayoutDemoPage: React.FC = () => {
profileLink={profileLink}
username={demoProfile.username}
/>
- {ownPostIndex !== undefined && (
+ {isPostPreviewOpen && (
<SpaceFileViewer
- photo={ownPostPhotos[ownPostIndex]!}
- photos={ownPostPhotos}
- photoIndex={ownPostIndex}
- onPhotoIndexChange={setOwnPostIndex}
- postActionMode="hidden"
- onClose={() => setOwnPostIndex(undefined)}
- onDeletePost={() => {
- const postId = ownViewerPosts[ownPostIndex]!.postId;
- setDemo((current) => ({
- ...current,
- ownPosts: current.ownPosts.filter(
- (post) => post.postId != postId,
- ),
- }));
- }}
- onUpdatePostCaption={(postId, caption) => {
- const updatePosts = (posts: SpacePost[]) =>
- posts.map((post) =>
- post.postId == postId
- ? {
- ...post,
- caption:
- caption.trim() || undefined,
- }
- : post,
- );
- setDemo((current) => ({
- ...current,
- ownPosts: updatePosts(current.ownPosts),
- }));
- setOwnViewerPosts(updatePosts);
- return Promise.resolve();
+ photo={{
+ alt: "Your post",
+ avatarUrl: demoProfile.avatarUrl,
+ imageUrl: spaceDefaultCoverImagePath,
+ name: demoProfile.fullName,
+ timestampMs: 1_700_000_000_000,
}}
+ postActionMode="draft-post"
+ onClose={() => setIsPostPreviewOpen(false)}
+ onPublishDraftPost={() => Promise.resolve()}
/>
)}
</Box>
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 4d3c1ca2a3..efea5e467c 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -16,7 +16,7 @@ import {
} from "components/FileViewer";
import { FriendQuickActionsDialog } from "components/FriendQuickActionsDialog";
import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";
-import { SpaceOwnPostTile } from "components/OwnPostTile";
+import { SpaceNewPostButton } from "components/NewPostButton";
import {
SpacePostBadge,
SpacePostUnreadBadge,
@@ -78,9 +78,6 @@ const tileBadgeBackground = "#343438";
const homeHorizontalPadding = "16px";
const postTileMediaLoadRootMargin = "640px 0px";
interface HomeScreenProps {
- ownLatestPost?: SpacePost;
- isOwnLatestPostLoading?: boolean;
- isOwnLatestPostUnavailable?: boolean;
latestPosts: SpacePost[];
unreadPosts: SpacePost[];
friendRequestSentToastName?: string;
@@ -96,8 +93,6 @@ interface HomeScreenProps {
image: SpaceDraftPostImage,
caption: string,
) => Promise<void>;
- onDeletePost?: (postId: number) => Promise<void>;
- onUpdatePostCaption?: (postId: number, caption: string) => Promise<void>;
onLoadFriendAvatar?: (friend: FriendProfile) => Promise<string | null>;
onLoadPostImage?: SpacePostAssetURLLoader;
onFriendRequestSentToastClose?: () => void;
@@ -113,7 +108,6 @@ interface HomeScreenProps {
onOpenMessages?: () => void;
onMessageFriend: (friend: FriendProfile) => void;
onPokeFriend: (friend: FriendProfile) => Promise<void>;
- onOpenOwnPost?: () => void;
onOpenProfile?: () => void;
onReplyToPost?: (
postSpaceId: string,
@@ -994,9 +988,6 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({
);
export const HomeScreen: React.FC<HomeScreenProps> = ({
- ownLatestPost,
- isOwnLatestPostLoading = false,
- isOwnLatestPostUnavailable = false,
latestPosts,
unreadPosts,
friendRequestSentToastName,
@@ -1009,8 +1000,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
isHomeCacheLoading = false,
showInstallPrompt = false,
onCreatePost,
- onDeletePost,
- onUpdatePostCaption,
onAcceptFriendRequest,
onAddFriend,
onDiscardFriendRequest,
@@ -1022,7 +1011,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onOpenMessages,
onMessageFriend,
onPokeFriend,
- onOpenOwnPost,
onOpenProfile,
onReplyToPost,
onSetPostLiked,
@@ -1064,7 +1052,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
const isPostPhotoButtonDisabled =
isPostPhotoOpening || !viewerSpaceId || !onCreatePost;
const selectedPhotoFriendID = selectedViewer?.photo.friendID;
- const selectedPhotoPostId = selectedViewer?.photo.postId;
const selectedPhotoIsOwn =
Boolean(viewerSpaceId) && selectedPhotoFriendID == viewerSpaceId;
const latestPostByFriendID = React.useMemo(() => {
@@ -1138,7 +1125,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
postTileCanvasSize.width,
postTileCanvasSize.height,
);
- const firstFriendTile = postLayout?.friends[0];
const isInstallPromptEnabled =
showInstallPrompt && !friendRequestSentToastName && !selectedViewer;
const isHomeItemsLoading = isFriendsLoading || isFriendRequestsLoading;
@@ -1389,29 +1375,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
},
[onSetPostLiked],
);
- const updateSelectedViewerPostCaption = async (
- postId: number,
- caption: string,
- ) => {
- await onUpdatePostCaption?.(postId, caption);
- const normalizedCaption = caption.trim() || undefined;
- setSelectedViewer((viewer) =>
- viewer
- ? {
- ...viewer,
- photo:
- viewer.photo.postId == postId
- ? { ...viewer.photo, caption: normalizedCaption }
- : viewer.photo,
- posts: viewer.posts?.map((post) =>
- post.postId == postId
- ? { ...post, caption: normalizedCaption }
- : post,
- ),
- }
- : viewer,
- );
- };
React.useEffect(() => {
if (!selectedViewerPosts || selectedViewerPostIndex == undefined)
@@ -1774,25 +1737,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
)
)}
</Box>
- <SpaceOwnPostTile
- profile={profile}
- post={ownLatestPost}
- avatarSize={
- firstFriendTile
- ? spaceTileAvatarSize(
- firstFriendTile,
- orderedHomeItems.length ==
- maximumHomeTileCount,
- )
- : undefined
- }
- isLoading={isOwnLatestPostLoading}
- isUnavailable={isOwnLatestPostUnavailable}
- isNewPostDisabled={isPostPhotoButtonDisabled}
- onLoadPostImage={onLoadPostImage}
- onNewPost={openPostPhotoPicker}
- onOpenProfile={onOpenProfile}
- onOpenPost={onOpenOwnPost}
+ <SpaceNewPostButton
+ isDisabled={isPostPhotoButtonDisabled}
+ onClick={openPostPhotoPicker}
/>
</Box>
{selectedContact && (
@@ -1834,18 +1781,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
: undefined
}
onClose={closeSelectedPhoto}
- onDeletePost={
- selectedPhotoIsOwn &&
- selectedPhotoPostId &&
- onDeletePost
- ? () => onDeletePost(selectedPhotoPostId)
- : undefined
- }
- onUpdatePostCaption={
- selectedPhotoIsOwn && onUpdatePostCaption
- ? updateSelectedViewerPostCaption
- : undefined
- }
onOpenProfile={
selectedPhotoIsOwn && onOpenProfile
? () => {
diff --git a/web/apps/space/src/state/AppStateProvider.tsx b/web/apps/space/src/state/AppStateProvider.tsx
index fdffc096e6..20e3b3eed9 100644
--- a/web/apps/space/src/state/AppStateProvider.tsx
+++ b/web/apps/space/src/state/AppStateProvider.tsx
@@ -36,8 +36,6 @@ import {
} from "state/app-state";
import { prepareSpacePostImageFromEdit } from "utils/post-image";
-const postStatusDurationMs = 2000;
-
export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
children,
}) => {
@@ -152,7 +150,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
...publication,
phase: "posted",
post,
- statusExpiresAtMs: Date.now() + postStatusDurationMs,
});
}
return post;
diff --git a/web/apps/space/src/state/app-state.tsx b/web/apps/space/src/state/app-state.tsx
index f01b80bfc9..9aa7dd61f3 100644
--- a/web/apps/space/src/state/app-state.tsx
+++ b/web/apps/space/src/state/app-state.tsx
@@ -17,7 +17,6 @@ export interface SpacePostPublication {
phase: SpacePostPublishPhase;
post: SpacePost;
previewUrl: string;
- statusExpiresAtMs?: number;
}
export type PendingCreateProfile = SetupProfileDetails & {
source: CreateProfileSource;