Skip to content

armgit / ente

Public Imported from GitHub
0

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

Restore Space own-post footer and refine home layout

Anand Baburajan00c8f3b1dcf7
diff --git a/web/apps/space/src/components/AddFriendButton.tsx b/web/apps/space/src/components/AddFriendButton.tsx
deleted file mode 100644
index aedafff013..0000000000
--- a/web/apps/space/src/components/AddFriendButton.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import { UserAdd02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import { Box } from "@mui/material";
-import React from "react";
-import { spaceEmptyStateButtonSx } from "styles/buttons";
-import { spaceSurface } from "styles/colors";
-
-export const SpaceAddFriendButton: React.FC<{ onClick: () => void }> = ({
- onClick,
-}) => (
- <Box
- component="button"
- type="button"
- aria-label="Add friend"
- onClick={onClick}
- sx={{
- ...spaceEmptyStateButtonSx,
- bgcolor: "transparent",
- borderRadius: "50%",
- color: "#585860",
- height: 64,
- p: 0,
- width: 64,
- "&:hover:not(:disabled)": { bgcolor: spaceSurface },
- }}
- >
- <HugeiconsIcon icon={UserAdd02Icon} size={24} strokeWidth={1.5} />
- </Box>
-);
diff --git a/web/apps/space/src/components/HomeHeader.tsx b/web/apps/space/src/components/HomeHeader.tsx
index b362e6b564..5c39b1c9ad 100644
--- a/web/apps/space/src/components/HomeHeader.tsx
+++ b/web/apps/space/src/components/HomeHeader.tsx
@@ -26,6 +26,7 @@ const avatarFadeSx = {
} as const;
export const spaceHomeHeaderHeight = 64;
+export const spaceHomeHeaderBarHeight = 44;
interface SpaceHomeHeaderProps {
children?: React.ReactNode;
@@ -66,7 +67,7 @@ export const SpaceHomeHeader: React.FC<SpaceHomeHeaderProps> = ({
bgcolor: spaceSurface,
borderRadius: "999px",
content: '""',
- height: 44,
+ height: spaceHomeHeaderBarHeight,
left: "16px",
pointerEvents: "none",
position: "absolute",
diff --git a/web/apps/space/src/components/NewPostButton.tsx b/web/apps/space/src/components/NewPostButton.tsx
index b61a31db6e..575b4204ab 100644
--- a/web/apps/space/src/components/NewPostButton.tsx
+++ b/web/apps/space/src/components/NewPostButton.tsx
@@ -6,6 +6,9 @@ import { useSpaceAppState } from "state/app-state";
const green = "#08C225";
+export const spaceNewPostButtonSize = 28;
+export const spaceNewPostButtonRadius = spaceNewPostButtonSize / 2;
+
export const SpaceNewPostButton: React.FC<{
isDisabled?: boolean;
onClick: () => void;
@@ -23,22 +26,19 @@ export const SpaceNewPostButton: React.FC<{
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)",
+ borderRadius: `${spaceNewPostButtonRadius}px`,
color: "#FFFFFF",
cursor: disabled ? "default" : "pointer",
display: "flex",
flexShrink: 0,
- height: 64,
+ height: spaceNewPostButtonSize,
justifyContent: "center",
- ml: "auto",
opacity: disabled ? 0.6 : 1,
p: 0,
- width: 64,
+ width: spaceNewPostButtonSize,
"&:hover:not(:disabled)": { bgcolor: "#07B422" },
"&:focus-visible": {
outline: `2px solid ${green}`,
@@ -46,7 +46,7 @@ export const SpaceNewPostButton: React.FC<{
},
}}
>
- <HugeiconsIcon icon={Add01Icon} size={32} strokeWidth={2} />
+ <HugeiconsIcon icon={Add01Icon} size={20} strokeWidth={2} />
</Box>
);
};
diff --git a/web/apps/space/src/components/OwnPostTile.tsx b/web/apps/space/src/components/OwnPostTile.tsx
new file mode 100644
index 0000000000..e300345655
--- /dev/null
+++ b/web/apps/space/src/components/OwnPostTile.tsx
@@ -0,0 +1,329 @@
+import { Image01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box, Skeleton } from "@mui/material";
+import { spaceHomeHeaderBarHeight } from "components/HomeHeader";
+import {
+ SpaceNewPostButton,
+ spaceNewPostButtonRadius,
+ spaceNewPostButtonSize,
+} from "components/NewPostButton";
+import log from "ente-base/log";
+import React from "react";
+import type { SpacePost, SpacePostAssetURLLoader } from "services/space";
+import { useSpaceAppState, type SpacePostPublishPhase } from "state/app-state";
+import {
+ spaceSurface,
+ spaceSurfaceHover,
+ spaceText,
+ spaceTextMuted,
+} from "styles/colors";
+import { formatSpaceDate } from "utils/display";
+import { thumbHashDataURLFromBase64 } from "utils/thumbhash";
+
+const green = "#08C225";
+const groupInset = 8;
+const groupGap = groupInset * 1.5;
+const groupHeight = spaceHomeHeaderBarHeight;
+const groupRadius = groupHeight / 2;
+
+const PostTimestamp: React.FC<{
+ timestampMs: number;
+ phase?: SpacePostPublishPhase;
+ expiresAtMs?: number;
+}> = ({ timestampMs, phase, expiresAtMs }) => {
+ const [now, setNow] = React.useState(Date.now);
+
+ React.useEffect(() => {
+ setNow(Date.now());
+ const intervalID = window.setInterval(
+ () => setNow(Date.now()),
+ phase == "posting" ? 500 : 60_000,
+ );
+ const timeoutID = expiresAtMs
+ ? window.setTimeout(
+ () => setNow(Date.now()),
+ Math.max(0, expiresAtMs - Date.now()),
+ )
+ : undefined;
+ return () => {
+ window.clearInterval(intervalID);
+ window.clearTimeout(timeoutID);
+ };
+ }, [phase, expiresAtMs]);
+
+ const status =
+ phase && (!expiresAtMs || expiresAtMs > now) ? phase : undefined;
+ const label =
+ status == "posting"
+ ? "Posting"
+ : status == "posted"
+ ? "Posted"
+ : status == "failed"
+ ? "Failed"
+ : formatSpaceDate(timestampMs);
+
+ return (
+ <Box
+ component="span"
+ role="status"
+ aria-label={label}
+ sx={{
+ color:
+ status == "posted"
+ ? "color(display-p3 0.0314 0.7608 0.1451 / 0.85)"
+ : status == "failed"
+ ? "#FF8585"
+ : spaceTextMuted,
+ display: "block",
+ fontSize: 12,
+ lineHeight: "18px",
+ }}
+ >
+ {status ? (
+ label
+ ) : (
+ <time dateTime={new Date(timestampMs).toISOString()}>
+ {label}
+ </time>
+ )}
+ {status == "posting" && (
+ <Box component="span" aria-hidden>
+ {".".repeat((Math.floor(now / 500) % 3) + 1)}
+ </Box>
+ )}
+ </Box>
+ );
+};
+
+interface SpaceOwnPostTileProps {
+ post?: SpacePost;
+ isLoading?: boolean;
+ isUnavailable?: boolean;
+ isNewPostDisabled?: boolean;
+ onLoadPostImage?: SpacePostAssetURLLoader;
+ onOpenPost?: () => void;
+ onNewPost: () => void;
+}
+
+export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({
+ post,
+ isLoading = false,
+ isUnavailable = false,
+ isNewPostDisabled = false,
+ onLoadPostImage,
+ onOpenPost,
+ onNewPost,
+}) => {
+ const { postPublication } = useSpaceAppState();
+ const tileRef = React.useRef<HTMLElement>(null);
+ const publishPhase =
+ postPublication?.post == post ? postPublication?.phase : undefined;
+ const hasPublication = Boolean(publishPhase);
+ 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 [showSkeleton, setShowSkeleton] = React.useState(false);
+ const isEmpty = !post && !loading && !unavailable;
+
+ React.useEffect(() => {
+ setShowSkeleton(false);
+ if (!loading) return;
+
+ const timeoutID = window.setTimeout(() => setShowSkeleton(true), 200);
+ return () => window.clearTimeout(timeoutID);
+ }, [loading]);
+
+ 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
+ ref={tileRef}
+ component="section"
+ aria-label="Your latest post"
+ sx={{
+ alignItems: "center",
+ bgcolor: spaceSurface,
+ borderRadius: `${groupRadius}px`,
+ boxSizing: "border-box",
+ display: "flex",
+ flexShrink: 0,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ gap: `${groupGap}px`,
+ height: groupHeight,
+ minWidth: 0,
+ p: `${groupInset}px`,
+ "& .MuiSkeleton-root": {
+ visibility: showSkeleton ? "visible" : "hidden",
+ },
+ }}
+ >
+ <Box
+ component="button"
+ type="button"
+ aria-label="Open your posts"
+ disabled={!canOpenPost}
+ onClick={onOpenPost}
+ sx={{
+ alignItems: "center",
+ appearance: "none",
+ bgcolor: "transparent",
+ border: 0,
+ borderRadius: `${spaceNewPostButtonRadius}px`,
+ color: spaceText,
+ cursor: canOpenPost ? "pointer" : "default",
+ display: "flex",
+ flex: 1,
+ font: "inherit",
+ gap: `${groupGap}px`,
+ minWidth: 0,
+ p: 0,
+ textAlign: "left",
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ }}
+ >
+ <Box
+ component="span"
+ sx={{
+ bgcolor: spaceSurfaceHover,
+ borderRadius: `${spaceNewPostButtonRadius}px`,
+ display: "grid",
+ flexShrink: 0,
+ height: spaceNewPostButtonSize,
+ overflow: "hidden",
+ placeItems: "center",
+ position: "relative",
+ width: spaceNewPostButtonSize,
+ }}
+ >
+ {isEmpty && (
+ <HugeiconsIcon
+ icon={Image01Icon}
+ size={18}
+ strokeWidth={1.6}
+ color={spaceTextMuted}
+ aria-hidden
+ />
+ )}
+ {thumbHashDataURL && !unavailable && (
+ <Box
+ component="img"
+ alt=""
+ src={thumbHashDataURL}
+ sx={{
+ filter: "blur(8px)",
+ height: "100%",
+ inset: 0,
+ objectFit: "cover",
+ position: "absolute",
+ transform: "scale(1.08)",
+ width: "100%",
+ }}
+ />
+ )}
+ {imageUrl && !unavailable ? (
+ <Box
+ component="img"
+ alt=""
+ src={imageUrl}
+ onError={() =>
+ post && setLoadedImage({ post, failed: true })
+ }
+ sx={{
+ display: "block",
+ height: "100%",
+ objectFit: "cover",
+ position: "relative",
+ width: "100%",
+ }}
+ />
+ ) : loading && !thumbHashDataURL ? (
+ <Skeleton
+ variant="rectangular"
+ sx={{ height: "100%", width: "100%" }}
+ />
+ ) : null}
+ </Box>
+ <Box
+ component="span"
+ sx={{
+ display: "grid",
+ flex: 1,
+ minWidth: 0,
+ placeItems: "center",
+ }}
+ >
+ {post ? (
+ <PostTimestamp
+ timestampMs={post.timestampMs}
+ phase={publishPhase}
+ expiresAtMs={postPublication?.statusExpiresAtMs}
+ />
+ ) : loading ? (
+ <Skeleton
+ width={72}
+ sx={{ fontSize: 12, lineHeight: "18px" }}
+ />
+ ) : (
+ <Box
+ component="span"
+ sx={{
+ color: isEmpty ? spaceText : spaceTextMuted,
+ display: "block",
+ fontSize: 12,
+ fontWeight: 400,
+ lineHeight: "18px",
+ whiteSpace: "nowrap",
+ }}
+ >
+ {unavailable
+ ? "Post unavailable"
+ : "Share your first post."}
+ </Box>
+ )}
+ </Box>
+ </Box>
+ <SpaceNewPostButton
+ isDisabled={isNewPostDisabled}
+ onClick={onNewPost}
+ />
+ </Box>
+ );
+};
diff --git a/web/apps/space/src/components/PostComposer.tsx b/web/apps/space/src/components/PostComposer.tsx
index 128d6fff37..12b055284d 100644
--- a/web/apps/space/src/components/PostComposer.tsx
+++ b/web/apps/space/src/components/PostComposer.tsx
@@ -16,6 +16,8 @@ import {
spacePostPreviewImageForFile,
type SpaceDraftPostImage,
} from "utils/post-image";
+import { useSpaceRouter } from "utils/route-transitions";
+import { spaceRoutes } from "utils/routes";
interface PendingPostDraft {
error?: string;
@@ -39,6 +41,7 @@ const SpacePostComposer: React.FC<SpacePostComposerProps> = ({
onPublish,
profile,
}) => {
+ const router = useSpaceRouter();
const publishedPreviewURLRef = React.useRef<string>(undefined);
const displayName =
profile.fullName.trim() || profile.username.trim() || "You";
@@ -131,7 +134,9 @@ const SpacePostComposer: React.FC<SpacePostComposerProps> = ({
}
onDraftPostExitStart={() => setIsDraftPostExiting(true)}
onDraftPostPublished={() => {
- void clearBrowserBackState("back");
+ void clearBrowserBackState("back").then(() =>
+ router.push(spaceRoutes.home),
+ );
}}
onPublishDraftPost={
draft.isPreviewPending || draft.error
diff --git a/web/apps/space/src/components/PostFloatingActionButton.tsx b/web/apps/space/src/components/PostFloatingActionButton.tsx
index b830820c29..6458ec0295 100644
--- a/web/apps/space/src/components/PostFloatingActionButton.tsx
+++ b/web/apps/space/src/components/PostFloatingActionButton.tsx
@@ -5,8 +5,8 @@ import React from "react";
const green = "#08C225";
const paleGreen = "#E7F6E9";
-const buttonSize = 64;
-const iconSize = 34;
+const buttonSize = 48;
+const iconSize = 28;
interface SpacePostFloatingActionButtonProps {
disabled?: boolean;
diff --git a/web/apps/space/src/components/PostToast.tsx b/web/apps/space/src/components/PostToast.tsx
deleted file mode 100644
index bd618c9502..0000000000
--- a/web/apps/space/src/components/PostToast.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import { AlertCircleIcon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import { Box } from "@mui/material";
-import { SpaceActionFeedbackIcon } from "components/ActionFeedback";
-import {
- SpaceActionToast,
- spaceToastAutoDismissDurationMs,
-} from "components/ActionToast";
-import React from "react";
-import { useSpaceAppState } from "state/app-state";
-import { spaceToastActionButtonSx } from "styles/buttons";
-import { useSpaceRouter } from "utils/route-transitions";
-import { spaceRoutes } from "utils/routes";
-
-const dangerColor = "#F63A3A";
-
-export const SpacePostToast: React.FC = () => {
- const router = useSpaceRouter();
- const { postPublication, setPostPublication } = useSpaceAppState();
- const dismissPostPublishToast = React.useCallback(() => {
- setPostPublication(null);
- }, [setPostPublication]);
-
- if (!postPublication) return null;
-
- const phase = postPublication.phase;
- const isPosting = phase == "posting";
- const isFailed = phase == "failed";
- const isPosted = phase == "posted";
- return (
- <SpaceActionToast
- action={
- isPosted && (
- <Box
- component="button"
- type="button"
- onClick={() => {
- dismissPostPublishToast();
- void router.push(
- `${spaceRoutes.profile}?section=latest`,
- undefined,
- { scroll: false },
- );
- }}
- sx={spaceToastActionButtonSx}
- >
- View post
- </Box>
- )
- }
- animateEntrance={isPosting}
- autoDismissAfterMs={
- isFailed ? spaceToastAutoDismissDurationMs : undefined
- }
- closeLabel="Dismiss post status"
- icon={
- isFailed ? (
- <HugeiconsIcon
- color={dangerColor}
- icon={AlertCircleIcon}
- size={20}
- strokeWidth={1.8}
- />
- ) : (
- <SpaceActionFeedbackIcon
- phase={isPosting ? "busy" : "done"}
- size={20}
- />
- )
- }
- message={isPosting ? "Posting..." : isFailed ? "Failed" : "Posted"}
- onClose={dismissPostPublishToast}
- showCloseButton={isPosted}
- zIndex={1400}
- />
- );
-};
diff --git a/web/apps/space/src/components/PostUnreadBadge.tsx b/web/apps/space/src/components/PostUnreadBadge.tsx
index 003ea7572f..8d342ed166 100644
--- a/web/apps/space/src/components/PostUnreadBadge.tsx
+++ b/web/apps/space/src/components/PostUnreadBadge.tsx
@@ -1,6 +1,6 @@
import { Box } from "@mui/material";
import React from "react";
-import { spaceTileCircleInset, spaceTilePillInset } from "styles/tiles";
+import { spaceTilePillInset } from "styles/tiles";
interface SpacePostBadgeProps extends React.PropsWithChildren {
backgroundColor: string;
@@ -16,11 +16,8 @@ export const SpacePostBadge: React.FC<SpacePostBadgeProps> = ({
placement = "top-right",
variant = "default",
}) => {
- const height = variant == "unread" || placement == "center" ? 24 : 18;
- const inset =
- variant == "unread"
- ? spaceTileCircleInset(height)
- : spaceTilePillInset(height);
+ const height = placement == "center" ? 24 : variant == "unread" ? 20 : 18;
+ const inset = spaceTilePillInset(height);
return (
<Box
component="span"
@@ -57,11 +54,7 @@ export const SpacePostBadge: React.FC<SpacePostBadgeProps> = ({
top: inset,
maxWidth: `calc(100% - 2 * (${inset}))`,
}),
- ...(variant == "unread" && {
- border: "1px solid #FFFFFF",
- fontSize: 12,
- px: "6px",
- }),
+ ...(variant == "unread" && { fontSize: 10, px: "6px" }),
}}
>
<Box
@@ -78,6 +71,6 @@ export const SpacePostUnreadBadge: React.FC<{ count: number }> = ({
count,
}) => (
<SpacePostBadge backgroundColor="#F63A3A" color="#FFFFFF" variant="unread">
- {count}
+ {count} new
</SpacePostBadge>
);
diff --git a/web/apps/space/src/hooks/use-own-latest-post.ts b/web/apps/space/src/hooks/use-own-latest-post.ts
new file mode 100644
index 0000000000..b857395720
--- /dev/null
+++ b/web/apps/space/src/hooks/use-own-latest-post.ts
@@ -0,0 +1,73 @@
+import log from "ente-base/log";
+import { useEffect, useState } from "react";
+import { savedSpaceOwnedSpaces } from "services/persistent-session";
+import { loadCachedOwnLatestPost } from "services/post-cache";
+import { loadExistingSpaceId } from "services/profile";
+import {
+ loadCurrentSpaceProfilePostsPage,
+ type SpacePost,
+} from "services/space";
+import { useSpaceAppState } from "state/app-state";
+
+export const useOwnLatestPost = () => {
+ const { postPublication } = useSpaceAppState();
+ const isPublishingPost = postPublication?.phase == "posting";
+ const [ownLatestPost, setOwnLatestPost] = useState<SpacePost>();
+ const [isOwnLatestPostLoading, setIsOwnLatestPostLoading] = useState(true);
+ const [isOwnLatestPostUnavailable, setIsOwnLatestPostUnavailable] =
+ useState(false);
+
+ useEffect(() => {
+ setIsOwnLatestPostLoading(true);
+ setIsOwnLatestPostUnavailable(false);
+ if (isPublishingPost) return;
+
+ let cancelled = false;
+ const isCancelled = () => cancelled;
+ let cachedPost: SpacePost | undefined;
+ void (async () => {
+ const cachedSpaceId = savedSpaceOwnedSpaces()?.[0]?.spaceId;
+ if (cachedSpaceId) {
+ cachedPost = await loadCachedOwnLatestPost(cachedSpaceId);
+ if (isCancelled()) return;
+ if (cachedPost) {
+ setOwnLatestPost(cachedPost);
+ setIsOwnLatestPostLoading(false);
+ }
+ }
+
+ const spaceId = await loadExistingSpaceId();
+ if (isCancelled()) return;
+ if (cachedPost?.spaceId != spaceId) {
+ cachedPost = undefined;
+ setOwnLatestPost(undefined);
+ setIsOwnLatestPostLoading(true);
+ }
+ if (!spaceId) return;
+
+ const page = await loadCurrentSpaceProfilePostsPage(
+ spaceId,
+ spaceId,
+ );
+ if (!isCancelled()) 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;
+ };
+ }, [isPublishingPost]);
+
+ return {
+ ownLatestPost: postPublication?.post ?? ownLatestPost,
+ isOwnLatestPostLoading: !postPublication && isOwnLatestPostLoading,
+ isOwnLatestPostUnavailable:
+ !postPublication && isOwnLatestPostUnavailable,
+ };
+};
diff --git a/web/apps/space/src/pages/_app.tsx b/web/apps/space/src/pages/_app.tsx
index f448127ffa..4a54248bf9 100644
--- a/web/apps/space/src/pages/_app.tsx
+++ b/web/apps/space/src/pages/_app.tsx
@@ -3,7 +3,6 @@ import "@fontsource/nunito/800.css";
import { CssBaseline } from "@mui/material";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { SpacePostComposerHost } from "components/PostComposer";
-import { SpacePostToast } from "components/PostToast";
import { SpaceRouteTransitionBoundary } from "components/RouteTransitionBoundary";
import "configure-zod";
import { CustomHead } from "ente-base/components/Head";
@@ -155,7 +154,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<SpaceAppStateProvider>
<Component {...pageProps} />
<SpacePostComposerHost />
- <SpacePostToast />
</SpaceAppStateProvider>
</SpaceRouteTransitionBoundary>
</ThemeProvider>
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 1bc002ab9e..e4c41de91e 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -4,6 +4,7 @@ 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 {
@@ -61,6 +62,11 @@ const Page: React.FC = () => {
);
const [latestPosts, setLatestPosts] = useState<SpacePost[]>([]);
const [spaceId, setSpaceId] = useState<string>();
+ const {
+ ownLatestPost,
+ isOwnLatestPostLoading,
+ isOwnLatestPostUnavailable,
+ } = useOwnLatestPost();
const [unreadPosts, setUnreadPosts] = useState<SpacePost[]>([]);
const [hasUnreadMessages, setHasUnreadMessages] = useState<boolean>();
const [isLatestPostsLoading, setIsLatestPostsLoading] = useState(true);
@@ -250,6 +256,9 @@ const Page: React.FC = () => {
<>
<SpacePageMeta themeColor={spaceAppBackgroundColor} />
<HomeScreen
+ ownLatestPost={ownLatestPost}
+ isOwnLatestPostLoading={isOwnLatestPostLoading}
+ isOwnLatestPostUnavailable={isOwnLatestPostUnavailable}
latestPosts={latestPosts}
unreadPosts={unreadPosts}
friendRequestSentToastName={friendRequestSentToastName}
@@ -414,6 +423,13 @@ 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/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index 28e677f3cb..e68b34c9a3 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -132,14 +132,9 @@ const Page: React.FC = () => {
profile={profile}
showPostLoadingIndicator={showInitialPostLoadingIndicator}
onBack={() => void router.push(spaceRoutes.home)}
+ onPostSubmitted={() => void router.push(spaceRoutes.home)}
onCreatePost={async (image, caption) => {
- const post = await publishPost(image, caption);
- setPosts((currentPosts) => [
- post,
- ...currentPosts.filter(
- (currentPost) => currentPost.postId != post.postId,
- ),
- ]);
+ await publishPost(image, caption);
}}
onDeletePost={async (postId) => {
const spaceId = profile.spaceId;
diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsx
index 38bfff719d..22eddaf65e 100644
--- a/web/apps/space/src/pages/layout-demo.tsx
+++ b/web/apps/space/src/pages/layout-demo.tsx
@@ -1,12 +1,11 @@
import { ArrowLeft02Icon, ArrowRight02Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
-import { SpaceAddFriendButton } from "components/AddFriendButton";
import { SpaceAddFriendDialog } from "components/AddFriendDialog";
import { SpaceAddFriendTile } from "components/AddFriendTile";
import { SpaceFileViewer } from "components/FileViewer";
import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";
-import { SpaceNewPostButton } from "components/NewPostButton";
+import { SpaceOwnPostTile } from "components/OwnPostTile";
import { useBrowserBackClose } from "hooks/use-browser-back-close";
import React from "react";
import { FriendPostTile } from "screens/HomeScreen";
@@ -31,6 +30,15 @@ const demoProfile: SetupProfile = {
spaceId: "demo-self",
username: "you",
};
+const demoOwnPost: SpacePost = {
+ friendID: "demo-self",
+ imageUrl: spaceDefaultCoverImagePath,
+ name: demoProfile.fullName,
+ postId: 100,
+ spaceId: "demo-self",
+ timestampMs: 1_700_000_000_000,
+ viewerLiked: false,
+};
const singleFriendVariants = [
"no-posts",
@@ -178,10 +186,14 @@ const LayoutDemoPage: React.FC = () => {
Math.max(0, Math.min(maximumHomeTileCount, count + delta)),
);
}, []);
- const [isPostPreviewOpen, setIsPostPreviewOpen] = React.useState(false);
+ const [ownPost, setOwnPost] = React.useState<SpacePost>();
+ const [postPreviewActionMode, setPostPreviewActionMode] = React.useState<
+ "draft-post" | "hidden"
+ >();
+ const isPostPreviewOpen = postPreviewActionMode !== undefined;
useBrowserBackClose({
open: isPostPreviewOpen,
- onClose: () => setIsPostPreviewOpen(false),
+ onClose: () => setPostPreviewActionMode(undefined),
stateKey: "space-layout-demo-viewer",
});
const [canvasSize, setCanvasSize] = React.useState<CanvasSize>({
@@ -332,12 +344,12 @@ const LayoutDemoPage: React.FC = () => {
boxSizing: "border-box",
display: "flex",
flexDirection: "column",
- gap: `${homeTileGap}px`,
+ gap: `${homeTileGap * 2.5}px`,
minHeight: `calc(100svh - ${spaceHomeHeaderHeight}px)`,
minWidth: 0,
pb: "calc(env(safe-area-inset-bottom) + 16px)",
px: "16px",
- pt: "4px",
+ pt: "22px",
width: "100%",
}}
>
@@ -374,21 +386,11 @@ const LayoutDemoPage: React.FC = () => {
</>
)}
</Box>
- <Box
- sx={{
- alignItems: "center",
- display: "flex",
- gap: `${homeTileGap}px`,
- justifyContent: "flex-end",
- }}
- >
- {[1, 2, 4, 6, 8].includes(friendCount) && (
- <SpaceAddFriendButton onClick={openAddFriend} />
- )}
- <SpaceNewPostButton
- onClick={() => setIsPostPreviewOpen(true)}
- />
- </Box>
+ <SpaceOwnPostTile
+ post={ownPost}
+ onNewPost={() => setPostPreviewActionMode("draft-post")}
+ onOpenPost={() => setPostPreviewActionMode("hidden")}
+ />
</Box>
<SpaceAddFriendDialog
friendRequests={[]}
@@ -405,15 +407,21 @@ const LayoutDemoPage: React.FC = () => {
{isPostPreviewOpen && (
<SpaceFileViewer
photo={{
+ ...(ownPost ?? demoOwnPost),
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()}
+ postActionMode={postPreviewActionMode}
+ onClose={() => setPostPreviewActionMode(undefined)}
+ onPublishDraftPost={(caption) => {
+ setOwnPost({
+ ...demoOwnPost,
+ caption,
+ timestampMs: Date.now(),
+ });
+ return Promise.resolve();
+ }}
/>
)}
</Box>
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index f9947011b1..3cdad21d83 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -3,7 +3,6 @@ import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
import { SpaceActionFeedbackIcon } from "components/ActionFeedback";
import { SpaceActionToast } from "components/ActionToast";
-import { SpaceAddFriendButton } from "components/AddFriendButton";
import { SpaceAddFriendTile } from "components/AddFriendTile";
import { SpaceAvatarImage } from "components/AvatarImage";
import {
@@ -14,7 +13,7 @@ import {
} from "components/FileViewer";
import { FriendQuickActionsDialog } from "components/FriendQuickActionsDialog";
import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";
-import { SpaceNewPostButton } from "components/NewPostButton";
+import { SpaceOwnPostTile } from "components/OwnPostTile";
import {
SpacePostBadge,
SpacePostUnreadBadge,
@@ -76,6 +75,9 @@ const tileBadgeText = "rgba(255, 255, 255, 0.9)";
const homeHorizontalPadding = "16px";
const postTileMediaLoadRootMargin = "640px 0px";
interface HomeScreenProps {
+ ownLatestPost?: SpacePost;
+ isOwnLatestPostLoading?: boolean;
+ isOwnLatestPostUnavailable?: boolean;
latestPosts: SpacePost[];
unreadPosts: SpacePost[];
friendRequestSentToastName?: string;
@@ -106,6 +108,7 @@ interface HomeScreenProps {
onOpenMessages?: () => void;
onMessageFriend: (friend: FriendProfile) => void;
onPokeFriend: (friend: FriendProfile) => Promise<void>;
+ onOpenOwnPost?: () => void;
onOpenProfile?: () => void;
onReplyToPost?: (
postSpaceId: string,
@@ -984,6 +987,9 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({
);
export const HomeScreen: React.FC<HomeScreenProps> = ({
+ ownLatestPost,
+ isOwnLatestPostLoading = false,
+ isOwnLatestPostUnavailable = false,
latestPosts,
unreadPosts,
friendRequestSentToastName,
@@ -1007,6 +1013,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onOpenMessages,
onMessageFriend,
onPokeFriend,
+ onOpenOwnPost,
onOpenProfile,
onReplyToPost,
onSetPostLiked,
@@ -1663,12 +1670,12 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
boxSizing: "border-box",
display: "flex",
flexDirection: "column",
- gap: `${homeTileGap}px`,
+ gap: `${homeTileGap * 2.5}px`,
minHeight: `calc(100svh - ${spaceHomeHeaderHeight}px)`,
minWidth: 0,
pb: "calc(env(safe-area-inset-bottom) + 16px)",
px: homeHorizontalPadding,
- pt: "4px",
+ pt: "22px",
width: "100%",
}}
>
@@ -1733,23 +1740,15 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
)
)}
</Box>
- <Box
- sx={{
- alignItems: "center",
- display: "flex",
- gap: `${homeTileGap}px`,
- justifyContent: "flex-end",
- }}
- >
- {!isHomeItemsLoading &&
- [1, 2, 4, 6, 8].includes(
- orderedHomeItems.length,
- ) && <SpaceAddFriendButton onClick={onAddFriend} />}
- <SpaceNewPostButton
- isDisabled={isPostPhotoButtonDisabled}
- onClick={openPostPhotoPicker}
- />
- </Box>
+ <SpaceOwnPostTile
+ post={ownLatestPost}
+ isLoading={isOwnLatestPostLoading}
+ isUnavailable={isOwnLatestPostUnavailable}
+ isNewPostDisabled={isPostPhotoButtonDisabled}
+ onLoadPostImage={onLoadPostImage}
+ onNewPost={openPostPhotoPicker}
+ onOpenPost={onOpenOwnPost}
+ />
</Box>
{selectedContact && (
<FriendQuickActionsDialog
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 9728978053..27025a2e8c 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -503,6 +503,7 @@ interface ProfileScreenProps {
isStatsLoading?: boolean;
showPostLoadingIndicator?: boolean;
onBack?: () => void;
+ onPostSubmitted?: () => void;
onAddFriend?: () => void;
onAddFriendForPostAction?: (intent: SpaceInviteIntent) => void;
onCreateSpace?: () => void;
@@ -544,6 +545,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
isPostsLoading = false,
isStatsLoading = false,
onBack,
+ onPostSubmitted,
onAddFriend,
onAddFriendForPostAction,
onCreateSpace,
@@ -2159,7 +2161,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
}}
onDraftPostExitStart={() => setIsDraftPostExiting(true)}
onDraftPostPublished={() => {
- void clearSelectedPostHistory("back");
+ void clearSelectedPostHistory("back").then(() =>
+ onPostSubmitted?.(),
+ );
}}
onDeletePost={
isOwnerProfile ? deleteSelectedPost : undefined
diff --git a/web/apps/space/src/services/post-cache.ts b/web/apps/space/src/services/post-cache.ts
index 423f0187df..f20b9f64a8 100644
--- a/web/apps/space/src/services/post-cache.ts
+++ b/web/apps/space/src/services/post-cache.ts
@@ -1,3 +1,8 @@
+import { savedPartialLocalUser } from "ente-accounts/services/accounts-db";
+import { getKV, removeKV, setKV } from "ente-base/kv";
+import log from "ente-base/log";
+import { apiOrigin } from "ente-base/origins";
+import type { SpacePost } from "services/space";
import { z } from "zod";
const CachedSpacePostAsset = z.object({
@@ -28,3 +33,55 @@ export const CachedSpacePost = z.object({
viewerLiked: z.boolean(),
width: z.number().optional(),
});
+
+const ownLatestPostKey = async (spaceId: string) => {
+ const userID = savedPartialLocalUser()?.id;
+ if (!userID) return undefined;
+ return [
+ "space-own-latest-post",
+ "v1",
+ await apiOrigin(),
+ userID,
+ spaceId,
+ ].join(":");
+};
+
+export const loadCachedOwnLatestPost = async (spaceId: string) => {
+ try {
+ const key = await ownLatestPostKey(spaceId);
+ if (!key) return undefined;
+ const parsed = CachedSpacePost.safeParse(await getKV(key));
+ return parsed.success ? parsed.data : undefined;
+ } catch (error) {
+ log.warn("Failed to read own latest Space post cache", error);
+ return undefined;
+ }
+};
+
+export const cacheOwnLatestPost = async (
+ spaceId: string,
+ post: SpacePost | undefined,
+) => {
+ try {
+ const key = await ownLatestPostKey(spaceId);
+ if (!key) return;
+ if (post) await setKV(key, CachedSpacePost.parse(post));
+ else await removeKV(key);
+ } catch (error) {
+ log.warn("Failed to persist own latest Space post cache", error);
+ }
+};
+
+export const patchCachedOwnLatestPost = async (
+ spaceId: string,
+ postId: number,
+ patch: Partial<SpacePost> | undefined,
+) => {
+ const post = await loadCachedOwnLatestPost(spaceId);
+ if (post?.postId == postId) {
+ await cacheOwnLatestPost(
+ spaceId,
+ patch ? { ...post, ...patch } : undefined,
+ );
+ }
+};
diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.ts
index 6bebe3bd9d..f55a0b211a 100644
--- a/web/apps/space/src/services/space.ts
+++ b/web/apps/space/src/services/space.ts
@@ -18,6 +18,10 @@ import {
spacePostMediaCacheKey,
spaceProfileMediaCacheKey,
} from "services/media-cache";
+import {
+ cacheOwnLatestPost,
+ patchCachedOwnLatestPost,
+} from "services/post-cache";
import {
ensureCurrentSpaceContext,
loadExistingSpaceProfile,
@@ -1219,7 +1223,7 @@ export const loadCurrentSpaceProfilePostsPage = async (
): Promise<SpaceProfilePostPage> => {
const ctx = await ensureCurrentSpaceContext();
try {
- return profilePostPageFromPage(
+ const page = profilePostPageFromPage(
(await ctx.listPosts(
spaceId,
viewerSpaceId ?? null,
@@ -1227,6 +1231,10 @@ export const loadCurrentSpaceProfilePostsPage = async (
60,
)) as SpacePostPageResponse,
);
+ if (!cursor && spaceId == viewerSpaceId) {
+ await cacheOwnLatestPost(spaceId, page.items[0]);
+ }
+ return page;
} finally {
releaseCurrentSpaceContext(ctx);
}
@@ -1366,7 +1374,9 @@ export const createCurrentPhotoPost = async ({
)) as SpacePostResponse;
const object = firstObject(created);
if (object) await cacheAccountPostAssetURL(created, object, file);
- return await postFromAccountPost(ctx, created, true, spaceId);
+ const post = await postFromAccountPost(ctx, created, true, spaceId);
+ await cacheOwnLatestPost(spaceId, post);
+ return post;
} finally {
releaseCurrentSpaceContext(ctx);
}
@@ -1716,6 +1726,7 @@ export const deleteCurrentPost = async (spaceId: string, postId: number) => {
const ctx = await ensureCurrentSpaceContext();
try {
await ctx.deletePost(spaceId, BigInt(postId));
+ await patchCachedOwnLatestPost(spaceId, postId, undefined);
} finally {
releaseCurrentSpaceContext(ctx);
}
@@ -1733,6 +1744,9 @@ export const updateCurrentPostCaption = async (
BigInt(postId),
caption.trim() || null,
);
+ await patchCachedOwnLatestPost(spaceId, postId, {
+ caption: caption.trim() || undefined,
+ });
} finally {
releaseCurrentSpaceContext(ctx);
}
diff --git a/web/apps/space/src/state/AppStateProvider.tsx b/web/apps/space/src/state/AppStateProvider.tsx
index 9c338951e8..fdffc096e6 100644
--- a/web/apps/space/src/state/AppStateProvider.tsx
+++ b/web/apps/space/src/state/AppStateProvider.tsx
@@ -36,6 +36,8 @@ import {
} from "state/app-state";
import { prepareSpacePostImageFromEdit } from "utils/post-image";
+const postStatusDurationMs = 2000;
+
export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
children,
}) => {
@@ -79,6 +81,17 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
[postPreviewUrl],
);
+ useEffect(() => {
+ if (postPublication?.phase != "failed") return;
+
+ const timeoutID = window.setTimeout(() => {
+ setPostPublication((current) =>
+ current == postPublication ? null : current,
+ );
+ }, 2500);
+ return () => window.clearTimeout(timeoutID);
+ }, [postPublication]);
+
const publishPost = useCallback(
async (
image: Parameters<SpaceAppState["publishPost"]>[0],
@@ -139,6 +152,7 @@ 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 9aa7dd61f3..f01b80bfc9 100644
--- a/web/apps/space/src/state/app-state.tsx
+++ b/web/apps/space/src/state/app-state.tsx
@@ -17,6 +17,7 @@ export interface SpacePostPublication {
phase: SpacePostPublishPhase;
post: SpacePost;
previewUrl: string;
+ statusExpiresAtMs?: number;
}
export type PendingCreateProfile = SetupProfileDetails & {
source: CreateProfileSource;
diff --git a/web/apps/space/tests/post-cache.test.ts b/web/apps/space/tests/post-cache.test.ts
new file mode 100644
index 0000000000..18eaecf3c4
--- /dev/null
+++ b/web/apps/space/tests/post-cache.test.ts
@@ -0,0 +1,103 @@
+import { savedPartialLocalUser } from "ente-accounts/services/accounts-db";
+import { getKV, removeKV, setKV } from "ente-base/kv";
+import { apiOrigin } from "ente-base/origins";
+import { beforeEach, expect, test, vi } from "vitest";
+import {
+ cacheOwnLatestPost,
+ loadCachedOwnLatestPost,
+ patchCachedOwnLatestPost,
+} from "../src/services/post-cache";
+import type { SpacePost } from "../src/services/space";
+
+vi.mock("ente-accounts/services/accounts-db", () => ({
+ savedPartialLocalUser: vi.fn(),
+}));
+vi.mock("ente-base/kv", () => ({
+ getKV: vi.fn(),
+ setKV: vi.fn(),
+ removeKV: vi.fn(),
+}));
+vi.mock("ente-base/log", () => ({ default: { warn: vi.fn() } }));
+vi.mock("ente-base/origins", () => ({ apiOrigin: vi.fn() }));
+
+const storage = new Map<string, unknown>();
+const post: SpacePost = {
+ avatarUrl: "blob:avatar",
+ caption: "A photo",
+ friendID: "self",
+ imageAsset: {
+ encryptedPostKey: "encrypted-key",
+ keyVersion: 1,
+ objectKey: "photo",
+ postId: 1,
+ spaceId: "self",
+ },
+ imageUrl: "blob:photo",
+ name: "Me",
+ postId: 1,
+ spaceId: "self",
+ thumbHash: "3OcRJYB4d3h/iIeHeEh3eIhw+j3A",
+ timestampMs: 1,
+ viewerLiked: false,
+};
+
+beforeEach(() => {
+ vi.resetAllMocks();
+ storage.clear();
+ vi.mocked(savedPartialLocalUser).mockReturnValue({ id: 1 });
+ vi.mocked(apiOrigin).mockResolvedValue("https://api.example.com");
+ vi.mocked(getKV).mockImplementation((key) =>
+ Promise.resolve(storage.get(key)),
+ );
+ vi.mocked(setKV).mockImplementation((key, value) => {
+ storage.set(key, structuredClone(value));
+ return Promise.resolve();
+ });
+ vi.mocked(removeKV).mockImplementation((key) => {
+ storage.delete(key);
+ return Promise.resolve();
+ });
+});
+
+test("restores the hash and image asset without expired blob URLs", async () => {
+ await cacheOwnLatestPost("self", post);
+ const restored = await loadCachedOwnLatestPost("self");
+ expect(restored?.thumbHash).toBe(post.thumbHash);
+ expect(restored?.imageAsset).toEqual(post.imageAsset);
+ expect(restored).not.toHaveProperty("imageUrl");
+ expect(restored).not.toHaveProperty("avatarUrl");
+});
+
+test("keeps previews separate across spaces, accounts, and servers", async () => {
+ await cacheOwnLatestPost("self", post);
+ expect(await loadCachedOwnLatestPost("another-space")).toBeUndefined();
+ vi.mocked(savedPartialLocalUser).mockReturnValue({ id: 2 });
+ expect(await loadCachedOwnLatestPost("self")).toBeUndefined();
+ vi.mocked(savedPartialLocalUser).mockReturnValue({ id: 1 });
+ vi.mocked(apiOrigin).mockResolvedValue("https://other.example.com");
+ expect(await loadCachedOwnLatestPost("self")).toBeUndefined();
+});
+
+test("updates captions and removes deleted posts without clearing newer posts", async () => {
+ await cacheOwnLatestPost("self", post);
+ await patchCachedOwnLatestPost("self", 1, { caption: "Edited" });
+ expect((await loadCachedOwnLatestPost("self"))?.caption).toBe("Edited");
+ await cacheOwnLatestPost("self", { ...post, postId: 2 });
+ await patchCachedOwnLatestPost("self", 1, undefined);
+ expect((await loadCachedOwnLatestPost("self"))?.postId).toBe(2);
+ await patchCachedOwnLatestPost("self", 2, undefined);
+ expect(await loadCachedOwnLatestPost("self")).toBeUndefined();
+});
+
+test("clears the preview when the refreshed profile has no posts", async () => {
+ await cacheOwnLatestPost("self", post);
+ await cacheOwnLatestPost("self", undefined);
+ expect(await loadCachedOwnLatestPost("self")).toBeUndefined();
+});
+
+test("a cache failure does not fail the post operation", async () => {
+ vi.mocked(setKV).mockRejectedValue(new Error("Storage unavailable"));
+ await expect(cacheOwnLatestPost("self", post)).resolves.toBeUndefined();
+ vi.mocked(getKV).mockRejectedValue(new Error("Storage unavailable"));
+ await expect(loadCachedOwnLatestPost("self")).resolves.toBeUndefined();
+});