π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add own post tile and history to Space home
Anand Baburajan5f56ed7ece72
diff --git a/web/apps/space/src/components/OwnPostTile.tsx b/web/apps/space/src/components/OwnPostTile.tsxnew file mode 100644index 0000000000..cf7e8d4701--- /dev/null+++ b/web/apps/space/src/components/OwnPostTile.tsx@@ -0,0 +1,228 @@+import { Add01Icon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { Box, 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 { spaceSurface, spaceText, spaceTextMuted } from "styles/colors";++const green = "#08C225";++interface SpaceOwnPostTileProps {+ profile: SetupProfile | null;+ post?: SpacePost;+ isLoading?: boolean;+ isUnavailable?: boolean;+ isNewPostDisabled?: boolean;+ onLoadPostImage?: SpacePostAssetURLLoader;+ onOpenPost?: (imageUrl: string) => void;+ onOpenProfile?: () => void;+ onNewPost: () => void;+}++export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({+ profile,+ post,+ isLoading = false,+ isUnavailable = false,+ isNewPostDisabled = false,+ onLoadPostImage,+ onOpenPost,+ onOpenProfile,+ onNewPost,+}) => {+ 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 unavailable =+ isUnavailable || post?.isUnavailable || postImage?.failed;+ const loading =+ isLoading || Boolean(post?.imageAsset && !imageUrl && !unavailable);++ 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+ component="section"+ aria-label="Your latest post"+ sx={{+ aspectRatio: "1.7",+ bgcolor: spaceSurface,+ borderRadius: "24px",+ flexShrink: 0,+ fontFamily: '"Inter Variable", Inter, sans-serif',+ overflow: "hidden",+ position: "relative",+ width: "100%",+ "& button:focus-visible": {+ outline: `2px solid ${green}`,+ outlineOffset: -4,+ },+ }}+ >+ <Box+ component="button"+ type="button"+ aria-label="Open your posts"+ disabled={!imageUrl || unavailable || !onOpenPost}+ onClick={() => imageUrl && onOpenPost?.(imageUrl)}+ sx={{+ appearance: "none",+ bgcolor: "transparent",+ border: 0,+ borderRadius: "inherit",+ color: spaceTextMuted,+ cursor: imageUrl && onOpenPost ? "pointer" : "default",+ font: "inherit",+ inset: 0,+ p: 0,+ position: "absolute",+ width: "100%",+ }}+ >+ {imageUrl && !unavailable ? (+ <Box+ component="img"+ alt={post?.caption || "Your latest post"}+ src={imageUrl}+ onError={() =>+ post && setLoadedImage({ post, failed: true })+ }+ sx={{+ display: "block",+ height: "100%",+ objectFit: "cover",+ width: "100%",+ }}+ />+ ) : loading ? (+ <Skeleton+ variant="rectangular"+ sx={{ height: "100%", transform: "none" }}+ />+ ) : (+ <Box sx={{ fontSize: 15, pb: "56px", px: "24px" }}>+ {unavailable+ ? "Couldn't load your latest post"+ : "Share your first photo"}+ </Box>+ )}+ </Box>+ <Box+ sx={{+ alignItems: "center",+ background:+ imageUrl && !unavailable+ ? "linear-gradient(transparent, rgba(0, 0, 0, 0.72))"+ : undefined,+ bottom: 0,+ display: "flex",+ gap: "12px",+ justifyContent: "space-between",+ left: 0,+ p: "32px 16px 16px",+ pointerEvents: "none",+ position: "absolute",+ right: 0,+ }}+ >+ <Box+ component="button"+ type="button"+ aria-label="Open your profile"+ onClick={onOpenProfile}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: "transparent",+ border: 0,+ borderRadius: "12px",+ color: spaceText,+ cursor: onOpenProfile ? "pointer" : "default",+ display: "flex",+ font: "inherit",+ gap: "10px",+ minWidth: 0,+ p: 0,+ pointerEvents: "auto",+ textAlign: "left",+ }}+ >+ <Box+ sx={{+ border: "2px solid rgba(255, 255, 255, 0.8)",+ borderRadius: "50%",+ boxSizing: "border-box",+ flexShrink: 0,+ height: 44,+ overflow: "hidden",+ width: 44,+ }}+ >+ <SpaceAvatarImage src={profile?.avatarUrl} />+ </Box>+ <Box>+ <Box sx={{ fontSize: 16, fontWeight: 650 }}>You</Box>+ {post && (+ <Box sx={{ fontSize: 11, mt: "3px", opacity: 0.8 }}>+ Latest post+ </Box>+ )}+ </Box>+ </Box>+ <Box+ className="green-bg"+ component="button"+ type="button"+ disabled={isNewPostDisabled}+ onClick={onNewPost}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: green,+ border: 0,+ borderRadius: "999px",+ color: "#FFFFFF",+ cursor: isNewPostDisabled ? "default" : "pointer",+ display: "flex",+ flexShrink: 0,+ font: "inherit",+ fontSize: 13,+ fontWeight: 650,+ gap: "6px",+ minHeight: 44,+ opacity: isNewPostDisabled ? 0.6 : 1,+ px: "14px",+ pointerEvents: "auto",+ "&:hover": { bgcolor: "#07B422" },+ "&:focus-visible": { outlineColor: "#FFFFFF" },+ }}+ >+ <HugeiconsIcon icon={Add01Icon} size={20} strokeWidth={2} />+ New post+ </Box>+ </Box>+ </Box>+ );+};diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsxindex 5d02782a37..99368ae124 100644--- a/web/apps/space/src/pages/app/index.tsx+++ b/web/apps/space/src/pages/app/index.tsx@@ -58,6 +58,10 @@ const Page: React.FC = () => {[],);const [latestPosts, setLatestPosts] = useState<SpacePost[]>([]);+ const [ownLatestPost, setOwnLatestPost] = useState<SpacePost>();+ const [isOwnLatestPostLoading, setIsOwnLatestPostLoading] = useState(true);+ const [isOwnLatestPostUnavailable, setIsOwnLatestPostUnavailable] =+ useState(false);const [unreadPosts, setUnreadPosts] = useState<SpacePost[]>([]);const [hasUnreadMessages, setHasUnreadMessages] = useState<boolean>();const [isLatestPostsLoading, setIsLatestPostsLoading] = useState(true);@@ -98,6 +102,29 @@ const Page: React.FC = () => {setFriendRequestSentToastName(sentFriend.username.trim());}, [router.isReady]);+ useEffect(() => {+ if (profileLoadStatus != "ready" || !profile?.spaceId) return;++ let cancelled = false;+ setOwnLatestPost(undefined);+ setIsOwnLatestPostLoading(true);+ setIsOwnLatestPostUnavailable(false);+ void loadCurrentSpaceProfilePostsPage(profile.spaceId, profile.spaceId)+ .then((page) => {+ if (!cancelled) setOwnLatestPost(page.items[0]);+ })+ .catch((error: unknown) => {+ log.error("Failed to load own latest Space post", error);+ if (!cancelled) setIsOwnLatestPostUnavailable(true);+ })+ .finally(() => {+ if (!cancelled) setIsOwnLatestPostLoading(false);+ });+ return () => {+ cancelled = true;+ };+ }, [profile?.spaceId, profileLoadStatus]);+useEffect(() => {const request = { cancelled: false };const isCancelled = () => request.cancelled;@@ -248,6 +275,9 @@ const Page: React.FC = () => {<><SpacePageMeta themeColor={spaceAppBackgroundColor} /><HomeScreen+ ownLatestPost={ownLatestPost}+ isOwnLatestPostLoading={isOwnLatestPostLoading}+ isOwnLatestPostUnavailable={isOwnLatestPostUnavailable}latestPosts={latestPosts}unreadPosts={unreadPosts}friendRequestSentToastName={friendRequestSentToastName}@@ -332,7 +362,10 @@ const Page: React.FC = () => {onCreatePost={profile? async (image, caption) => {- await publishPost(image, caption);+ const post = await publishPost(image, caption);+ setOwnLatestPost(post);+ setIsOwnLatestPostLoading(false);+ setIsOwnLatestPostUnavailable(false);}: undefined}diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsxindex 1207f96e03..46254301c5 100644--- a/web/apps/space/src/pages/layout-demo.tsx+++ b/web/apps/space/src/pages/layout-demo.tsx@@ -1,8 +1,10 @@import { ArrowLeft02Icon, ArrowRight02Icon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box } from "@mui/material";+import { SpaceFileViewer } from "components/FileViewer";import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";-import { SpacePostFloatingActionButton } from "components/PostFloatingActionButton";+import { SpaceOwnPostTile } from "components/OwnPostTile";+import { useBrowserBackClose } from "hooks/use-browser-back-close";import React from "react";import { FriendPostTile } from "screens/HomeScreen";import type { SpacePost } from "services/space";@@ -20,6 +22,20 @@ import { spaceRoutes } from "utils/routes";const controlButtonColor = spaceSurface;+const demoOwnPosts: SpacePost[] = [+ "/images/default-cover-image.jpg",+ "/images/invite-bg.jpg",+ "/images/default-profile-pic.png",+].map((imageUrl, index) => ({+ friendID: "demo-self",+ imageUrl,+ name: "You",+ postId: 100 - index,+ spaceId: "demo-self",+ timestampMs: 1_700_000_000_000 - index * 86_400_000,+ viewerLiked: false,+}));+interface CanvasSize {height: number;width: number;@@ -119,6 +135,18 @@ const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({const LayoutDemoPage: React.FC = () => {const router = useSpaceRouter();const { profile } = useSpaceAppState();+ const [ownPostIndex, setOwnPostIndex] = React.useState<number>();+ useBrowserBackClose({+ open: ownPostIndex !== undefined,+ onClose: () => setOwnPostIndex(undefined),+ stateKey: "space-layout-demo-viewer",+ });+ const ownPostPhotos = demoOwnPosts.map((post) => ({+ ...post,+ alt: "Your post",+ avatarUrl: profile?.avatarUrl,+ imageUrl: post.imageUrl!,+ }));const [friendCount, setFriendCount] = React.useState(1);const [canvasSize, setCanvasSize] = React.useState<CanvasSize>({height: 0,@@ -208,14 +236,24 @@ const LayoutDemoPage: React.FC = () => {boxSizing: "border-box",display: "flex",flexDirection: "column",- height: `calc(100svh - ${spaceHomeHeaderHeight}px)`,+ gap: "16px",+ minHeight: `calc(100svh - ${spaceHomeHeaderHeight}px)`,minWidth: 0,- pb: "calc(env(safe-area-inset-bottom) + 112px)",+ pb: "calc(env(safe-area-inset-bottom) + 72px)",px: "16px",- pt: `calc(env(safe-area-inset-bottom) + 112px - ${spaceHomeHeaderHeight}px)`,+ pt: "12px",width: "100%",}}>+ <SpaceOwnPostTile+ profile={profile}+ post={demoOwnPosts[0]}+ onNewPost={() => void router.push("/app/post")}+ onOpenPost={() => setOwnPostIndex(0)}+ onOpenProfile={() =>+ void router.push(spaceRoutes.profile)+ }+ /><Boxref={canvasRef}sx={{@@ -228,7 +266,7 @@ const LayoutDemoPage: React.FC = () => {gridTemplateRows: gridLayout? `repeat(${gridLayout.rows}, ${gridLayout.size}px)`: undefined,- minHeight: 0,+ minHeight: 320,placeContent: usesGrid ? "center" : undefined,position: "relative",width: "100%",@@ -332,7 +370,16 @@ const LayoutDemoPage: React.FC = () => {/></Box></Box>- <SpacePostFloatingActionButton />+ {ownPostIndex !== undefined && (+ <SpaceFileViewer+ photo={ownPostPhotos[ownPostIndex]!}+ photos={ownPostPhotos}+ photoIndex={ownPostIndex}+ onPhotoIndexChange={setOwnPostIndex}+ postActionMode="hidden"+ onClose={() => setOwnPostIndex(undefined)}+ />+ )}</Box></Box>);diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex b74629c524..b23d4c2287 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -15,7 +15,7 @@ import {} from "components/FileViewer";import { FriendQuickActionsDialog } from "components/FriendQuickActionsDialog";import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";-import { SpacePostFloatingActionButton } from "components/PostFloatingActionButton";+import { SpaceOwnPostTile } from "components/OwnPostTile";import {SpacePostBadge,SpacePostUnreadBadge,@@ -72,6 +72,9 @@ const tileBadgeBackground = "#343438";const homeHorizontalPadding = "16px";const postTileMediaLoadRootMargin = "640px 0px";interface HomeScreenProps {+ ownLatestPost?: SpacePost;+ isOwnLatestPostLoading?: boolean;+ isOwnLatestPostUnavailable?: boolean;latestPosts: SpacePost[];unreadPosts: SpacePost[];friendRequestSentToastName?: string;@@ -1012,6 +1015,9 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({);export const HomeScreen: React.FC<HomeScreenProps> = ({+ ownLatestPost,+ isOwnLatestPostLoading = false,+ isOwnLatestPostUnavailable = false,latestPosts,unreadPosts,friendRequestSentToastName,@@ -1758,19 +1764,50 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({boxSizing: "border-box",display: "flex",flexDirection: "column",- height: `calc(100svh - ${spaceHomeHeaderHeight}px)`,+ gap: "16px",+ minHeight: `calc(100svh - ${spaceHomeHeaderHeight}px)`,minWidth: 0,- pb: "calc(env(safe-area-inset-bottom) + 112px)",+ pb: "calc(env(safe-area-inset-bottom) + 72px)",px: homeHorizontalPadding,- pt: `calc(env(safe-area-inset-bottom) + 112px - ${spaceHomeHeaderHeight}px)`,+ pt: "12px",width: "100%",}}>+ <SpaceOwnPostTile+ profile={profile}+ post={ownLatestPost}+ isLoading={isOwnLatestPostLoading}+ isUnavailable={isOwnLatestPostUnavailable}+ isNewPostDisabled={isPostPhotoButtonDisabled}+ onLoadPostImage={onLoadPostImage}+ onNewPost={openPostPhotoPicker}+ onOpenProfile={onOpenProfile}+ onOpenPost={(imageUrl) => {+ if (!ownLatestPost || !profile) return;++ const self = {+ ...profile,+ id: ownLatestPost.spaceId,+ friendsCount: friends.length,+ };+ openPostPhotos(+ self,+ [ownLatestPost],+ viewerPhotoForPost(+ ownLatestPost,+ self,+ profile.avatarUrl,+ imageUrl,+ ),+ true,+ );+ }}+ /><Boxref={postTileCanvasRef}sx={{flex: "1 1 auto",- minHeight: 0,+ minHeight: 320,position: "relative",width: "100%",}}@@ -1838,9 +1875,10 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({display: "flex",fontFamily:'"Inter Variable", Inter, sans-serif',- height: "calc(100% + 32px)",+ height: "100%",+ inset: 0,justifyContent: "center",- mt: "-32px",+ position: "absolute",width: "100%",}}>@@ -1862,8 +1900,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({height: "100%",justifyContent: "flex-start",overflow: "hidden",- px: "24px",- pt: "32px",+ p: "24px",position: "relative",width: "100%",}}@@ -1873,13 +1910,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({alignItems: "center",display: "flex",flexDirection: "column",- mt: "40px",position: "relative",width: "100%",zIndex: 1,- "@media (max-height: 720px)": {- mt: 0,- },}}><Box@@ -1934,19 +1967,15 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({aria-hiddensrc="/images/ducky-space.svg"sx={{- bottom: 0,- height: "auto",- left: "52%",- maxWidth: 300,+ alignSelf: "center",+ flex: "1 1 0",+ maxHeight: 160,+ maxWidth: 180,+ minHeight: 0,+ mt: "16px",+ objectFit: "contain",pointerEvents: "none",- position: "absolute",- transform:- "translate(-50%, -7%)",- width: "84%",- "@media (max-height: 720px)": {- maxWidth: 228,- width: "64%",- },+ width: "64%",}}/></Box>@@ -1955,10 +1984,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({)}</Box></Box>- <SpacePostFloatingActionButton- disabled={isPostPhotoButtonDisabled}- onClick={openPostPhotoPicker}- />{selectedContact && (<FriendQuickActionsDialog{...selectedContact}