Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add Space post caption editing

Anand Baburajanba5f921bc696
diff --git a/web/apps/space/src/components/SpaceFileViewer.tsx b/web/apps/space/src/components/SpaceFileViewer.tsx
index 719f3b8c78..29f12e234d 100644
--- a/web/apps/space/src/components/SpaceFileViewer.tsx
+++ b/web/apps/space/src/components/SpaceFileViewer.tsx
@@ -1,6 +1,7 @@
import {
Cancel01Icon,
Delete02Icon,
+ Edit01Icon,
FavouriteIcon,
Loading03Icon,
MoreHorizontalIcon,
@@ -48,7 +49,7 @@ const captionInputMinHeight = 40;
const replyInputMinHeight = 48;
const replyInputPadding = 14;
const replyInputPaddingLeft = 18;
-const replyActionDoneDurationMs = 1000;
+const viewerActionDoneDurationMs = 1000;
const captionInputMaxHeight = 112;
const defaultPhotoWidth = 900;
const defaultPhotoHeight = 680;
@@ -161,6 +162,7 @@ interface SpaceFileViewerProps {
text: string,
) => Promise<void>;
onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;
+ onUpdatePostCaption?: (postId: number, caption: string) => Promise<void>;
onSwipeLeft?: () => void;
onSwipeRight?: () => void;
onPhotoIndexChange?: (index: number) => void;
@@ -301,6 +303,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
onPublishDraftPost,
onReplyToPost,
onSetPostLiked,
+ onUpdatePostCaption,
onSwipeLeft,
onSwipeRight,
onPhotoIndexChange,
@@ -335,6 +338,11 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
viewerPhotos.length - 1,
);
const activePhoto = viewerPhotos[activePhotoIndex] ?? photo;
+ const canUpdatePostCaption =
+ !isDraftPost &&
+ Boolean(activePhoto.postId) &&
+ Boolean(onUpdatePostCaption);
+ const canManagePost = canDeletePost || canUpdatePostCaption;
const viewerPhotosRef = React.useRef(viewerPhotos);
const onCloseRef = React.useRef(onClose);
const onPhotoIndexChangeRef = React.useRef(onPhotoIndexChange);
@@ -356,6 +364,16 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
);
const [photoLikePopID, setPhotoLikePopID] = React.useState(0);
const [caption, setCaption] = React.useState(activePhoto.caption ?? "");
+ const [captionEditValue, setCaptionEditValue] = React.useState(
+ activePhoto.caption ?? "",
+ );
+ const [isCaptionEditing, setIsCaptionEditing] = React.useState(false);
+ const [captionUpdateActionPhase, setCaptionUpdateActionPhase] =
+ React.useState<SpaceActionPhase | null>(null);
+ const [hasCaptionUpdateError, setHasCaptionUpdateError] =
+ React.useState(false);
+ const isCaptionEditingRef = React.useRef(isCaptionEditing);
+ isCaptionEditingRef.current = isCaptionEditing;
const [replyText, setReplyText] = React.useState("");
const [isReplyFocused, setIsReplyFocused] =
React.useState(focusReplyOnOpen);
@@ -389,6 +407,13 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
const actionsButtonID = "space-viewer-actions-button";
const isActionsOpen = Boolean(actionsAnchor);
const isDeleteActionRunning = deleteActionPhase != null;
+ const normalizedCaptionEditValue = captionEditValue.trim();
+ const isCaptionUpdateActionRunning = captionUpdateActionPhase != null;
+ const isCaptionUpdateDisabled =
+ isCaptionUpdateActionRunning ||
+ normalizedCaptionEditValue == caption.trim() ||
+ !activePhoto.postId ||
+ !onUpdatePostCaption;
const isDraftPostActionRunning = draftPostActionPhase != null;
const hasDraftPostPreparationError = Boolean(draftPostPreparationError);
const canQueueDraftPostPublish =
@@ -423,6 +448,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
isActionsOpen ||
(canDeletePost && deleteSheetOpen) ||
isDeleteExit ||
+ isCaptionEditing ||
isDraftPost ||
isDraftPostPreviewPending;
const viewerViewportSize = React.useCallback(() => {
@@ -462,6 +488,50 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
const closeActions = () => setActionsAnchor(null);
+ const requestCaptionEdit = () => {
+ if (!canUpdatePostCaption || isCaptionUpdateActionRunning) return;
+
+ closeActions();
+ setCaptionEditValue(caption);
+ setCaptionUpdateActionPhase(null);
+ setHasCaptionUpdateError(false);
+ setIsCaptionEditing(true);
+ };
+
+ const cancelCaptionEdit = React.useCallback(() => {
+ setCaptionEditValue(caption);
+ setHasCaptionUpdateError(false);
+ setIsCaptionEditing(false);
+ }, [caption]);
+
+ const closeViewer = () => {
+ if (isCaptionEditing && !isCaptionUpdateActionRunning) {
+ cancelCaptionEdit();
+ return;
+ }
+ onClose();
+ };
+
+ const updateCaption = () => {
+ if (isCaptionUpdateDisabled || !activePhoto.postId) {
+ return;
+ }
+
+ setHasCaptionUpdateError(false);
+ setCaptionUpdateActionPhase("busy");
+ void onUpdatePostCaption(activePhoto.postId, normalizedCaptionEditValue)
+ .then(() => {
+ setCaption(normalizedCaptionEditValue);
+ setCaptionEditValue(normalizedCaptionEditValue);
+ setCaptionUpdateActionPhase("done");
+ })
+ .catch((error: unknown) => {
+ console.error("Failed to update post caption", error);
+ setCaptionUpdateActionPhase(null);
+ setHasCaptionUpdateError(true);
+ });
+ };
+
const requestDeletePost = () => {
if (!canDeletePost || isDeleteActionRunning || isDeleteExit) return;
closeActions();
@@ -595,7 +665,16 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
React.useLayoutEffect(() => {
resizeCaptionInput(captionInputRef.current, replyInputMinHeight);
- }, [caption]);
+ }, [caption, captionEditValue, isCaptionEditing]);
+
+ React.useEffect(() => {
+ if (!isCaptionEditing) return;
+
+ const input = captionInputRef.current;
+ if (!input) return;
+ input.focus();
+ input.setSelectionRange(input.value.length, input.value.length);
+ }, [isCaptionEditing]);
React.useLayoutEffect(() => {
resizeCaptionInput(replyInputRef.current, replyInputMinHeight);
@@ -634,25 +713,44 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
publishDraftPostWithCaption(draftPost.caption, draftPost.edit);
}, [onPublishDraftPost, publishDraftPostWithCaption, queuedDraftPost]);
+ React.useEffect(() => {
+ if (captionUpdateActionPhase != "done") return;
+
+ const timeoutID = window.setTimeout(() => {
+ setCaptionUpdateActionPhase(null);
+ setIsCaptionEditing(false);
+ }, viewerActionDoneDurationMs);
+
+ return () => window.clearTimeout(timeoutID);
+ }, [captionUpdateActionPhase]);
+
React.useEffect(() => {
if (replyActionPhase != "done") return;
const timeoutID = window.setTimeout(() => {
setReplyActionPhase(null);
setIsReplyFocused(false);
- }, replyActionDoneDurationMs);
+ }, viewerActionDoneDurationMs);
return () => window.clearTimeout(timeoutID);
}, [replyActionPhase]);
React.useEffect(() => {
- setIsPhotoLiked(activePhoto.viewerLiked ?? false);
+ if (isCaptionEditingRef.current) return;
+
setCaption(activePhoto.caption ?? "");
+ setCaptionEditValue(activePhoto.caption ?? "");
+ }, [activePhoto.caption]);
+
+ React.useEffect(() => {
+ setIsPhotoLiked(activePhoto.viewerLiked ?? false);
+ setCaptionUpdateActionPhase(null);
+ setHasCaptionUpdateError(false);
+ setIsCaptionEditing(false);
setReplyText("");
setIsReplyFocused(focusReplyOnOpen && canReplyToPost);
setReplyActionPhase(null);
}, [
- activePhoto.caption,
activePhoto.imageUrl,
activePhoto.postId,
activePhoto.timestampMs,
@@ -743,6 +841,20 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
);
}, [canReplyToPost]);
+ React.useEffect(() => {
+ const root = viewerRootRef.current;
+ if (!root || !isCaptionEditing) return;
+
+ const blockPhotoGesture = (event: PointerEvent) => {
+ if (viewerSwipeStartsOnInteractiveTarget(event.target)) return;
+ event.stopPropagation();
+ };
+
+ root.addEventListener("pointerdown", blockPhotoGesture, true);
+ return () =>
+ root.removeEventListener("pointerdown", blockPhotoGesture, true);
+ }, [isCaptionEditing]);
+
React.useEffect(() => {
const root = viewerRootRef.current;
if (!root) return;
@@ -916,12 +1028,21 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
if (deleteSheetOpen) return;
if (event.key != "Escape") return;
+ if (isCaptionEditing && !isCaptionUpdateActionRunning) {
+ cancelCaptionEdit();
+ return;
+ }
onCloseRef.current();
};
window.addEventListener("keydown", closeOnEscape);
return () => window.removeEventListener("keydown", closeOnEscape);
- }, [deleteSheetOpen]);
+ }, [
+ cancelCaptionEdit,
+ deleteSheetOpen,
+ isCaptionEditing,
+ isCaptionUpdateActionRunning,
+ ]);
return (
<Box
@@ -1096,7 +1217,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
justifySelf: "flex-end",
}}
>
- {canDeletePost && (
+ {canManagePost && !isCaptionEditing && (
<Box
component="button"
id={actionsButtonID}
@@ -1139,8 +1260,12 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
<Box
component="button"
type="button"
- aria-label="Close viewer"
- onClick={onClose}
+ aria-label={
+ isCaptionEditing && !isCaptionUpdateActionRunning
+ ? "Cancel caption edit"
+ : "Close viewer"
+ }
+ onClick={closeViewer}
sx={viewerHeaderButtonSx}
>
<Box
@@ -1156,7 +1281,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
</Box>
</Box>
</Box>
- {canDeletePost && (
+ {canManagePost && (
<Menu
id={actionsMenuID}
anchorEl={actionsAnchor}
@@ -1189,48 +1314,94 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
},
}}
>
- <MenuItem
- disableRipple
- onClick={requestDeletePost}
- sx={{
- alignItems: "center",
- borderRadius: "10px",
- color: dangerColor,
- display: "flex",
- gap: "8px",
- minHeight: spaceTouchTargetSize,
- px: "8px",
- py: "7px",
- whiteSpace: "nowrap",
- "&.Mui-focusVisible": {
- bgcolor: "rgba(246, 58, 58, 0.14)",
- },
- "&:active": {
- bgcolor: "rgba(246, 58, 58, 0.14)",
- },
- "&:hover": {
- bgcolor: "rgba(246, 58, 58, 0.14)",
- },
- }}
- >
- <HugeiconsIcon
- icon={Delete02Icon}
- size={18}
- strokeWidth={1.8}
- style={{ flexShrink: 0 }}
- />
- <Box
+ {canUpdatePostCaption && (
+ <MenuItem
+ disableRipple
+ onClick={requestCaptionEdit}
sx={{
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 650,
- lineHeight: "18px",
+ alignItems: "center",
+ borderRadius: "10px",
+ color: textBase,
+ display: "flex",
+ gap: "8px",
+ minHeight: 0,
+ px: "8px",
+ py: "7px",
+ whiteSpace: "nowrap",
+ "&.Mui-focusVisible": {
+ bgcolor: "rgba(255, 255, 255, 0.1)",
+ },
+ "&:active": {
+ bgcolor: "rgba(255, 255, 255, 0.1)",
+ },
+ "&:hover": {
+ bgcolor: "rgba(255, 255, 255, 0.1)",
+ },
}}
>
- Delete post
- </Box>
- </MenuItem>
+ <HugeiconsIcon
+ icon={Edit01Icon}
+ size={18}
+ strokeWidth={1.8}
+ style={{ flexShrink: 0 }}
+ />
+ <Box
+ sx={{
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 650,
+ lineHeight: "18px",
+ }}
+ >
+ Edit caption
+ </Box>
+ </MenuItem>
+ )}
+ {canDeletePost && (
+ <MenuItem
+ disableRipple
+ onClick={requestDeletePost}
+ sx={{
+ alignItems: "center",
+ borderRadius: "10px",
+ color: dangerColor,
+ display: "flex",
+ gap: "8px",
+ minHeight: 0,
+ px: "8px",
+ py: "7px",
+ whiteSpace: "nowrap",
+ "&.Mui-focusVisible": {
+ bgcolor: "rgba(246, 58, 58, 0.14)",
+ },
+ "&:active": {
+ bgcolor: "rgba(246, 58, 58, 0.14)",
+ },
+ "&:hover": {
+ bgcolor: "rgba(246, 58, 58, 0.14)",
+ },
+ }}
+ >
+ <HugeiconsIcon
+ icon={Delete02Icon}
+ size={18}
+ strokeWidth={1.8}
+ style={{ flexShrink: 0 }}
+ />
+ <Box
+ sx={{
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 650,
+ lineHeight: "18px",
+ }}
+ >
+ Delete post
+ </Box>
+ </MenuItem>
+ )}
</Menu>
)}
</Box>
@@ -1456,7 +1627,207 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
</Box>
</Box>
) : null}
- {hasDisplayCaption && (
+ {isCaptionEditing && (
+ <Box
+ data-space-viewer-bottom="true"
+ sx={{
+ alignItems: "stretch",
+ bottom: "max(24px, calc(env(safe-area-inset-bottom) + 16px))",
+ boxSizing: "border-box",
+ display: "flex",
+ flexDirection: "column",
+ gap: "8px",
+ left: { xs: "16px", sm: "auto" },
+ maxWidth: { sm: 390 },
+ position: "fixed",
+ right: "16px",
+ width: { sm: "calc(100% - 32px)" },
+ zIndex: 2,
+ }}
+ >
+ {hasCaptionUpdateError && (
+ <Box
+ role="alert"
+ sx={{
+ bgcolor: "rgba(246, 58, 58, 0.16)",
+ borderRadius: "12px",
+ color: "#FF8A8A",
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 650,
+ lineHeight: "18px",
+ px: "12px",
+ py: "8px",
+ }}
+ >
+ Couldn&apos;t save caption. Try again.
+ </Box>
+ )}
+ <Box
+ sx={{
+ alignItems: "flex-end",
+ display: "flex",
+ gap: "8px",
+ }}
+ >
+ <Box
+ ref={captionInputRef}
+ component="textarea"
+ aria-label="Edit caption"
+ disabled={isCaptionUpdateActionRunning}
+ onChange={(event) => {
+ setCaptionEditValue(event.target.value);
+ setHasCaptionUpdateError(false);
+ resizeCaptionInput(
+ event.currentTarget,
+ replyInputMinHeight,
+ );
+ }}
+ placeholder="Add a caption..."
+ rows={1}
+ value={captionEditValue}
+ sx={{
+ bgcolor: inputBackground,
+ border: 0,
+ borderRadius: "24px",
+ boxSizing: "border-box",
+ color: textBase,
+ flex: "1 1 auto",
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ maxHeight: captionInputMaxHeight,
+ minHeight: replyInputMinHeight,
+ minWidth: 0,
+ outline: 0,
+ overflow: "hidden",
+ pb: `${replyInputPadding}px`,
+ pl: `${replyInputPaddingLeft}px`,
+ pr: `${replyInputPadding}px`,
+ pt: `${replyInputPadding}px`,
+ resize: "none",
+ "&::placeholder": { color: textSecondary },
+ "&:disabled": { opacity: 0.74 },
+ "&:focus": { bgcolor: inputBackgroundActive },
+ }}
+ />
+ <Box
+ component="button"
+ type="button"
+ aria-label={
+ captionUpdateActionPhase == "busy"
+ ? "Saving caption"
+ : captionUpdateActionPhase == "done"
+ ? "Caption saved"
+ : "Save caption"
+ }
+ disabled={isCaptionUpdateDisabled}
+ onClick={updateCaption}
+ sx={{
+ alignItems: "center",
+ bgcolor: "#FFFFFF",
+ border: 0,
+ borderRadius: "24px",
+ boxSizing: "border-box",
+ boxShadow: "0 10px 28px rgba(0, 0, 0, 0.28)",
+ color: "#111111",
+ cursor: isCaptionUpdateDisabled
+ ? "default"
+ : "pointer",
+ display: "flex",
+ flexShrink: 0,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 750,
+ height: replyInputMinHeight,
+ justifyContent: "center",
+ lineHeight: "20px",
+ minWidth: 70,
+ px: "20px",
+ py: "10px",
+ "&:disabled": {
+ opacity: captionUpdateActionPhase
+ ? 1
+ : 0.62,
+ },
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ "&:hover": {
+ bgcolor: isCaptionUpdateDisabled
+ ? "#FFFFFF"
+ : "#F0F0F0",
+ },
+ }}
+ >
+ <Box
+ component="span"
+ sx={{ display: "grid", placeItems: "center" }}
+ >
+ <Box
+ component="span"
+ sx={{
+ gridArea: "1 / 1",
+ visibility:
+ captionUpdateActionPhase == null
+ ? "visible"
+ : "hidden",
+ }}
+ >
+ Save
+ </Box>
+ <Box
+ component="span"
+ sx={{
+ animation:
+ captionUpdateActionPhase == "busy"
+ ? `${postButtonSpin} 2.4s linear infinite`
+ : "none",
+ display: "flex",
+ gridArea: "1 / 1",
+ lineHeight: 0,
+ visibility:
+ captionUpdateActionPhase == "busy"
+ ? "visible"
+ : "hidden",
+ }}
+ >
+ <HugeiconsIcon
+ icon={Loading03Icon}
+ size={22}
+ strokeWidth={1.8}
+ />
+ </Box>
+ <Box
+ component="span"
+ sx={{
+ display: "flex",
+ gridArea: "1 / 1",
+ lineHeight: 0,
+ visibility:
+ captionUpdateActionPhase == "done"
+ ? "visible"
+ : "hidden",
+ }}
+ >
+ <HugeiconsIcon
+ icon={Tick02Icon}
+ primaryColor={green}
+ size={22}
+ strokeWidth={1.8}
+ />
+ </Box>
+ </Box>
+ </Box>
+ </Box>
+ </Box>
+ )}
+ {hasDisplayCaption && !isCaptionEditing && (
<Box
component="p"
data-space-viewer-chrome="true"
@@ -1498,7 +1869,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
</Box>
</Box>
)}
- {showPhotoLikeButton && (
+ {showPhotoLikeButton && !isCaptionEditing && (
<Box
data-space-viewer-bottom="true"
sx={{
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 655c8ed2c1..ef50ef9535 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -13,6 +13,7 @@ import {
loadCurrentUnreadStatus,
replyToCurrentPost,
setCurrentPostLiked,
+ updateCurrentPostCaption,
type SpacePost,
} from "services/space";
import {
@@ -309,6 +310,35 @@ const Page: React.FC = () => {
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;
+ 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) =>
void router.push(spaceRoutes.friend(friendID))
}
diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index 462fc14d40..40bb3f482f 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -10,6 +10,7 @@ import {
loadCurrentSpacePostAssetURL,
loadCurrentSpaceProfilePostsPage,
setCurrentPostLiked,
+ updateCurrentPostCaption,
type SpaceProfilePost,
} from "services/space";
import { spaceInviteURL } from "services/spaceInvite";
@@ -202,6 +203,35 @@ const Page: React.FC = () => {
currentPosts.filter((post) => post.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;
+ setLocalFeedPosts((currentPosts) =>
+ currentPosts.map((item) =>
+ (item.status == "posted" ||
+ item.status == "ready") &&
+ item.post.postId == postId
+ ? {
+ ...item,
+ post: {
+ ...item.post,
+ caption: normalizedCaption,
+ },
+ }
+ : item,
+ ),
+ );
+ setPosts((currentPosts) =>
+ currentPosts.map((post) =>
+ post.postId == postId
+ ? { ...post, caption: normalizedCaption }
+ : post,
+ ),
+ );
+ }}
onOpenFriends={() => void router.push(spaceRoutes.friends)}
onOpenProfileCover={() =>
void router.push(spaceRoutes.profileCover)
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 4f359c9057..923019c8e7 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -133,6 +133,7 @@ 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;
}
@@ -1376,6 +1377,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onOpenProfile,
onReplyToPost,
onSetPostLiked,
+ onUpdatePostCaption,
profile,
profileLink,
}) => {
@@ -2300,6 +2302,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
setFeedScrollRequest((request) => request + 1)
}
onSetPostLiked={onSetPostLiked}
+ onUpdatePostCaption={
+ selectedPhotoIsOwn ? onUpdatePostCaption : undefined
+ }
/>
)}
{friendRequestSentToastName ? (
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 08d9f5d554..c9251b21cb 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -540,6 +540,7 @@ interface ProfileScreenProps {
text: string,
) => Promise<void>;
onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;
+ onUpdatePostCaption?: (postId: number, caption: string) => Promise<void>;
postGroups?: ProfilePostGroup[];
profile: SetupProfile;
profileLink?: string;
@@ -562,6 +563,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
onLoadPostImage,
onReplyToPost,
onSetPostLiked,
+ onUpdatePostCaption,
postGroups = [],
profile,
profileLink,
@@ -1805,6 +1807,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
: undefined
}
onSetPostLiked={onSetPostLiked}
+ onUpdatePostCaption={
+ isOwnerProfile ? onUpdatePostCaption : undefined
+ }
/>
)}
</Box>
diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.ts
index 7a2d241c69..486c8a8d6d 100644
--- a/web/apps/space/src/services/space.ts
+++ b/web/apps/space/src/services/space.ts
@@ -1361,3 +1361,20 @@ export const deleteCurrentPost = async (spaceId: string, postId: number) => {
releaseCurrentSpaceContext(ctx);
}
};
+
+export const updateCurrentPostCaption = async (
+ spaceId: string,
+ postId: number,
+ caption: string,
+) => {
+ const ctx = await ensureCurrentSpaceContext();
+ try {
+ await ctx.updatePostCaption(
+ spaceId,
+ BigInt(postId),
+ caption.trim() || null,
+ );
+ } finally {
+ releaseCurrentSpaceContext(ctx);
+ }
+};