Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Refine social post creation flow

Anand Baburajan56f70118413f
diff --git a/web/apps/social/src/components/SocialFileViewer.tsx b/web/apps/social/src/components/SocialFileViewer.tsx
index 07442645b3..5accda1ccf 100644
--- a/web/apps/social/src/components/SocialFileViewer.tsx
+++ b/web/apps/social/src/components/SocialFileViewer.tsx
@@ -2,10 +2,13 @@ import {
Cancel01Icon,
Delete02Icon,
FavouriteIcon,
+ Loading03Icon,
MoreHorizontalIcon,
+ Tick02Icon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Menu, MenuItem } from "@mui/material";
+import { keyframes } from "@mui/material/styles";
import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";
import {
socialActionBusyDurationMs,
@@ -27,18 +30,29 @@ const textSecondary = "#A6A6A6";
const textTertiary = "rgba(244, 244, 244, 0.52)";
const viewerBackground = "#000000";
const controlBackground = "rgba(36, 36, 36, 0.72)";
+const controlBackgroundActive = "rgba(58, 58, 58, 0.86)";
const controlBackgroundHover = "rgba(48, 48, 48, 0.86)";
const controlIcon = "#D8D8D8";
const dangerColor = "#F63A3A";
const viewerHeaderHeight = 56;
const viewerBottomPadding = 72;
+const captionInputMinHeight = 40;
+const captionInputMaxHeight = 112;
const defaultPhotoWidth = 900;
const defaultPhotoHeight = 680;
-const viewerExitDurationMs = 200;
-const viewerExitTransition = `${viewerExitDurationMs}ms cubic-bezier(0.4, 0, 0.2, 1)`;
const viewerPanelBackground = "#202020";
const viewerPanelMuted = "rgba(244, 244, 244, 0.54)";
+const postButtonSpin = keyframes`
+ from {
+ transform: rotate(0deg);
+ }
+
+ to {
+ transform: rotate(360deg);
+ }
+`;
+
interface SocialViewerUser {
avatarUrl?: string | null;
name: string;
@@ -47,6 +61,7 @@ interface SocialViewerUser {
export type SocialViewerInitialScreen = "photo" | "likes";
export type SocialViewerPostActionMode =
+ | "draft-post"
| "hidden"
| "like-only"
| "like-with-count";
@@ -60,6 +75,7 @@ const socialViewerPostActionConfigs: Record<
SocialViewerPostActionMode,
SocialViewerPostActionConfig
> = {
+ "draft-post": { showLikeButton: false, showLikeCount: false },
hidden: { showLikeButton: false, showLikeCount: false },
"like-only": { showLikeButton: true, showLikeCount: false },
"like-with-count": { showLikeButton: true, showLikeCount: true },
@@ -152,9 +168,8 @@ const viewerActionButtonSx = {
height: 48,
justifyContent: "center",
p: 0,
- transition: "background-color 120ms ease, transform 120ms ease",
width: 48,
- "&:active": { bgcolor: "#3A3A3A", transform: "scale(0.96)" },
+ "&:active": { bgcolor: "#3A3A3A" },
"&:focus-visible": { outline: `2px solid ${green}`, outlineOffset: 2 },
"&:hover": { bgcolor: controlBackgroundHover },
};
@@ -245,6 +260,16 @@ const HeartFilledIcon: React.FC = () => (
</svg>
);
+const resizeCaptionInput = (input: HTMLTextAreaElement | null) => {
+ if (!input) return;
+
+ input.style.height = `${captionInputMinHeight}px`;
+ const nextHeight = Math.min(input.scrollHeight, captionInputMaxHeight);
+ input.style.height = `${Math.max(captionInputMinHeight, nextHeight)}px`;
+ input.style.overflowY =
+ input.scrollHeight > captionInputMaxHeight ? "auto" : "hidden";
+};
+
export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
currentUser,
initialScreen = "photo",
@@ -255,10 +280,13 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
photo,
postActionMode = "like-with-count",
}) => {
+ const [activePostActionMode, setActivePostActionMode] =
+ React.useState(postActionMode);
+ const isDraftPost = activePostActionMode == "draft-post";
const {
showLikeButton: showPhotoLikeButton,
showLikeCount: showPhotoLikeCount,
- } = socialViewerPostActionConfigs[postActionMode];
+ } = socialViewerPostActionConfigs[activePostActionMode];
const canOpenLikes = showPhotoLikeCount;
const resolvedInitialScreen: SocialViewerInitialScreen =
initialScreen == "likes" && !canOpenLikes ? "photo" : initialScreen;
@@ -266,10 +294,14 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
resolvedInitialScreen,
);
const [isPhotoLiked, setIsPhotoLiked] = React.useState(false);
+ const [caption, setCaption] = React.useState("");
+ const [draftPostActionPhase, setDraftPostActionPhase] =
+ React.useState<SocialActionPhase | null>(null);
const displayName = firstNameFrom(photo.name);
const dateLabel = formatSocialDate(photo.timestampMs);
const initials = initialsFor(photo.name);
const viewerRootRef = React.useRef<HTMLDivElement | null>(null);
+ const captionInputRef = React.useRef<HTMLTextAreaElement | null>(null);
const likeHoldTimeoutRef = React.useRef<number | null>(null);
const likeHoldStartPointRef = React.useRef<{ x: number; y: number } | null>(
null,
@@ -301,6 +333,7 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
const actionsButtonID = "social-viewer-actions-button";
const isActionsOpen = Boolean(actionsAnchor);
const isDeleteActionRunning = deleteActionPhase != null;
+ const isDraftPostActionRunning = draftPostActionPhase != null;
const clearLikeHoldTimeout = () => {
if (likeHoldTimeoutRef.current != null) {
@@ -412,6 +445,12 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
setDeleteActionPhase("busy");
};
+ const publishDraftPost = () => {
+ if (!isDraftPost || isDraftPostActionRunning || isDeleteExit) return;
+
+ setDraftPostActionPhase("busy");
+ };
+
const openFriendProfile = (friendID: string) => {
onOpenFriend?.(friendID);
};
@@ -426,6 +465,10 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
[],
);
+ React.useLayoutEffect(() => {
+ resizeCaptionInput(captionInputRef.current);
+ }, [caption]);
+
React.useEffect(() => {
const suppressDelayedContextMenu = (event: MouseEvent) => {
if (!suppressNextLikeContextMenuRef.current) return;
@@ -472,6 +515,27 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
return () => window.clearTimeout(timeoutID);
}, [deleteActionPhase, onDeletePost]);
+ React.useEffect(() => {
+ if (!draftPostActionPhase) return;
+
+ const timeoutID = window.setTimeout(
+ () => {
+ if (draftPostActionPhase == "busy") {
+ setDraftPostActionPhase("done");
+ return;
+ }
+
+ setActivePostActionMode("like-with-count");
+ setDraftPostActionPhase(null);
+ },
+ draftPostActionPhase == "busy"
+ ? socialActionBusyDurationMs
+ : socialActionDoneDurationMs,
+ );
+
+ return () => window.clearTimeout(timeoutID);
+ }, [draftPostActionPhase]);
+
const handleDeleteSheetExited = () => {
if (!isDeleteExit) return;
@@ -481,8 +545,7 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
React.useEffect(() => {
if (!isDeleteExit) return;
- const timeoutID = window.setTimeout(onClose, viewerExitDurationMs);
- return () => window.clearTimeout(timeoutID);
+ onClose();
}, [isDeleteExit, onClose]);
React.useEffect(() => {
@@ -603,14 +666,9 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
isolation: "isolate",
maxWidth: "100vw",
minHeight: "100svh",
- opacity: isDeleteExit ? 0 : 1,
overflow: "hidden",
overflowX: "hidden",
- pointerEvents: isDeleteExit ? "none" : "auto",
position: "fixed",
- transition: isDeleteExit
- ? `opacity ${viewerExitTransition}`
- : undefined,
width: "100%",
zIndex: 1300,
}}
@@ -635,7 +693,7 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
sx={{
alignItems: "center",
display: "flex",
- gap: "10px",
+ gap: "8px",
minWidth: 0,
}}
>
@@ -745,29 +803,35 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
>
{displayName}
</Box>
- <Box
- component="span"
- aria-hidden
- sx={{
- color: textSecondary,
- flexShrink: 0,
- fontWeight: 500,
- }}
- >
- ·
- </Box>
- <Box
- component="time"
- dateTime={new Date(photo.timestampMs).toISOString()}
- sx={{
- color: textTertiary,
- flexShrink: 0,
- fontSize: 12,
- fontWeight: 500,
- }}
- >
- {dateLabel}
- </Box>
+ {!isDraftPost && (
+ <>
+ <Box
+ component="span"
+ aria-hidden
+ sx={{
+ color: textSecondary,
+ flexShrink: 0,
+ fontWeight: 500,
+ }}
+ >
+ ·
+ </Box>
+ <Box
+ component="time"
+ dateTime={new Date(
+ photo.timestampMs,
+ ).toISOString()}
+ sx={{
+ color: textTertiary,
+ flexShrink: 0,
+ fontSize: 12,
+ fontWeight: 500,
+ }}
+ >
+ {dateLabel}
+ </Box>
+ </>
+ )}
</Box>
</Box>
<Box
@@ -965,6 +1029,133 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
zIndex: 1,
}}
/>
+ {isDraftPost ? (
+ <Box
+ data-social-viewer-bottom="true"
+ sx={{
+ alignItems: "flex-end",
+ bottom: "16px",
+ boxSizing: "border-box",
+ display: "flex",
+ gap: "8px",
+ left: "16px",
+ position: "fixed",
+ right: "16px",
+ zIndex: 2,
+ }}
+ >
+ <Box
+ ref={captionInputRef}
+ component="textarea"
+ aria-label="Add a caption"
+ disabled={isDraftPostActionRunning}
+ onChange={(event) => {
+ setCaption(event.target.value);
+ resizeCaptionInput(event.currentTarget);
+ }}
+ placeholder="Add a caption..."
+ rows={1}
+ value={caption}
+ sx={{
+ bgcolor: controlBackground,
+ border: 0,
+ borderRadius: "20px",
+ boxSizing: "border-box",
+ color: textBase,
+ flex: "1 1 auto",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ maxHeight: captionInputMaxHeight,
+ minHeight: captionInputMinHeight,
+ minWidth: 0,
+ outline: 0,
+ overflow: "hidden",
+ px: "14px",
+ py: "10px",
+ resize: "none",
+ "&::placeholder": { color: textSecondary },
+ "&:disabled": { opacity: 0.74 },
+ "&:focus": { bgcolor: controlBackgroundActive },
+ }}
+ />
+ <Box
+ component="button"
+ type="button"
+ aria-label={
+ draftPostActionPhase == "busy"
+ ? "Posting"
+ : draftPostActionPhase == "done"
+ ? "Posted"
+ : "Post photo"
+ }
+ disabled={isDraftPostActionRunning}
+ onClick={publishDraftPost}
+ sx={{
+ alignItems: "center",
+ bgcolor: "#FFFFFF",
+ border: 0,
+ borderRadius: "20px",
+ boxSizing: "border-box",
+ boxShadow: "0 10px 28px rgba(0, 0, 0, 0.28)",
+ color:
+ draftPostActionPhase == "done"
+ ? green
+ : "#111111",
+ cursor: isDraftPostActionRunning
+ ? "default"
+ : "pointer",
+ display: "flex",
+ flexShrink: 0,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 750,
+ height: 40,
+ justifyContent: "center",
+ lineHeight: "20px",
+ minWidth: 70,
+ px: "20px",
+ py: "10px",
+ "&:disabled": { opacity: 1 },
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ "&:hover": {
+ bgcolor: isDraftPostActionRunning
+ ? "#FFFFFF"
+ : "#F0F0F0",
+ },
+ }}
+ >
+ {draftPostActionPhase == "busy" ? (
+ <Box
+ component="span"
+ sx={{
+ animation: `${postButtonSpin} 2.4s linear infinite`,
+ display: "flex",
+ lineHeight: 0,
+ }}
+ >
+ <HugeiconsIcon
+ icon={Loading03Icon}
+ size={22}
+ strokeWidth={1.8}
+ />
+ </Box>
+ ) : draftPostActionPhase == "done" ? (
+ <HugeiconsIcon
+ icon={Tick02Icon}
+ size={22}
+ strokeWidth={1.8}
+ />
+ ) : (
+ "Post"
+ )}
+ </Box>
+ </Box>
+ ) : null}
{showPhotoLikeButton && (
<Box
data-social-viewer-bottom="true"
diff --git a/web/apps/social/src/screens/CreateAccountScreen.tsx b/web/apps/social/src/screens/CreateAccountScreen.tsx
index 9a2dccac48..6ab2c23a81 100644
--- a/web/apps/social/src/screens/CreateAccountScreen.tsx
+++ b/web/apps/social/src/screens/CreateAccountScreen.tsx
@@ -315,7 +315,7 @@ export const CreateAccountScreen: React.FC<CreateAccountScreenProps> = ({
<TextInput
label="Email"
onChange={setEmail}
- placeholder="Enter your email id"
+ placeholder="Enter your email"
required
type="email"
value={email}
diff --git a/web/apps/social/src/screens/HomeScreen.tsx b/web/apps/social/src/screens/HomeScreen.tsx
index 9cf056ae1f..780cbdacb7 100644
--- a/web/apps/social/src/screens/HomeScreen.tsx
+++ b/web/apps/social/src/screens/HomeScreen.tsx
@@ -5,13 +5,6 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
-import {
- SocialActionFeedbackIcon,
- socialActionBusyDurationMs,
- socialActionDoneDurationMs,
- socialActionTransition,
- type SocialActionPhase,
-} from "components/SocialActionFeedback";
import {
SocialFileViewer,
type SocialViewerInitialScreen,
@@ -53,7 +46,6 @@ const sampleFeedLandscapePhotoAspectRatio = 900 / 680;
const sampleFeedPortraitPhotoAspectRatio = 680 / 1020;
const showMockFeedData =
process.env.NEXT_PUBLIC_HIDE_SOCIAL_MOCK_FEED != "true";
-type PostActionPhase = "posting" | "posted";
const sampleFeedItems = [
{
@@ -505,11 +497,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
}) => {
const [selectedViewer, setSelectedViewer] =
useState<SelectedHomeViewer | null>(null);
- const [postActionPhase, setPostActionPhase] =
- useState<PostActionPhase | null>(null);
const postInputRef = React.useRef<HTMLInputElement | null>(null);
const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());
- const pendingPostViewerRef = React.useRef<SelectedHomeViewer | null>(null);
const selectedPhotoFriendID = selectedViewer?.photo.friendID;
const feedItems = showMockFeedData ? sampleFeedItems : [];
const hasFeedItems = feedItems.length > 0;
@@ -518,14 +507,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
? "When you add friends, their posts will appear here."
: "When your friends share posts, they'll appear here.";
const profileLink = profileLinkForUsername(profile.username.trim());
- const isPostActionPosting = postActionPhase == "posting";
- const isPostActionPosted = postActionPhase == "posted";
- const postActionFeedbackPhase: SocialActionPhase | null =
- postActionPhase == "posting"
- ? "busy"
- : postActionPhase == "posted"
- ? "done"
- : null;
const initialsSource = profile.fullName.trim() || profile.username.trim();
const initials = initialsSource
.split(/\s+/)
@@ -541,14 +522,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
}, []);
const applyLocalPostDimensions = React.useCallback(
(objectUrl: string, dimensions: LocalPostPhotoDimensions) => {
- const pendingViewer = pendingPostViewerRef.current;
- if (pendingViewer?.localObjectUrl == objectUrl) {
- pendingPostViewerRef.current = {
- ...pendingViewer,
- photo: { ...pendingViewer.photo, ...dimensions },
- };
- }
-
setSelectedViewer((currentViewer) =>
currentViewer?.localObjectUrl == objectUrl
? {
@@ -598,9 +571,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
event.target.value = "";
if (!file) return;
- revokeLocalPostObjectUrl(pendingPostViewerRef.current?.localObjectUrl);
- pendingPostViewerRef.current = null;
-
const localPost = createLocalPostPhoto({
avatarUrl: profile.avatarUrl,
file,
@@ -608,38 +578,14 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onDimensionsLoaded: applyLocalPostDimensions,
});
localPostObjectUrlsRef.current.add(localPost.objectUrl);
- pendingPostViewerRef.current = {
+ setSelectedViewer({
initialScreen: "photo",
localObjectUrl: localPost.objectUrl,
photo: localPost.photo,
- postActionMode: "like-with-count",
- };
-
- setPostActionPhase("posting");
+ postActionMode: "draft-post",
+ });
};
- React.useEffect(() => {
- if (!postActionPhase) return;
-
- const timeoutID = window.setTimeout(
- () => {
- if (postActionPhase == "posting") {
- setPostActionPhase("posted");
- return;
- }
-
- const postedViewer = pendingPostViewerRef.current;
- pendingPostViewerRef.current = null;
- if (postedViewer) setSelectedViewer(postedViewer);
- setPostActionPhase(null);
- },
- postActionPhase == "posting"
- ? socialActionBusyDurationMs
- : socialActionDoneDurationMs,
- );
- return () => window.clearTimeout(timeoutID);
- }, [postActionPhase]);
-
React.useEffect(
() => () => {
localPostObjectUrlsRef.current.forEach((objectUrl) =>
@@ -697,14 +643,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
<Box
component="button"
type="button"
- aria-label={
- isPostActionPosting
- ? "Posting photo"
- : isPostActionPosted
- ? "Photo posted"
- : "Post photo"
- }
- disabled={postActionPhase != null}
+ aria-label="Post photo"
onClick={openPostPhotoPicker}
sx={{
appearance: "none",
@@ -712,9 +651,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
bgcolor: "transparent",
border: 0,
boxSizing: "border-box",
- color: isPostActionPosted ? green : textBase,
- cursor:
- postActionPhase == null ? "pointer" : "default",
+ color: textBase,
+ cursor: "pointer",
display: "flex",
fontSize: 0,
height: headerActionSize,
@@ -725,7 +663,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
p: 0,
placeSelf: "center start",
width: headerActionSize,
- transition: `color ${socialActionTransition}`,
"& svg": { display: "block" },
"&:focus-visible": {
borderRadius: "50%",
@@ -734,16 +671,10 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
},
}}
>
- <SocialActionFeedbackIcon
- idleIcon={
- <HugeiconsIcon
- icon={AddSquareIcon}
- size={headerAddIconSize}
- strokeWidth={1.8}
- />
- }
- phase={postActionFeedbackPhase}
+ <HugeiconsIcon
+ icon={AddSquareIcon}
size={headerAddIconSize}
+ strokeWidth={1.8}
/>
</Box>
<Box
@@ -892,7 +823,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
justifyContent: hasFeedItems ? "flex-start" : "center",
minHeight: "calc(100svh - 64px)",
pb: hasFeedItems ? "16px" : "56px",
- pt: hasFeedItems ? "22px" : 0,
+ pt: hasFeedItems ? "12px" : 0,
width: "100%",
}}
>
diff --git a/web/apps/social/src/screens/LoginScreen.tsx b/web/apps/social/src/screens/LoginScreen.tsx
index b5e8b6e0e8..91e4c2f5e4 100644
--- a/web/apps/social/src/screens/LoginScreen.tsx
+++ b/web/apps/social/src/screens/LoginScreen.tsx
@@ -288,7 +288,7 @@ export const LoginScreen: React.FC<LoginScreenProps> = ({
<TextInput
label="Email"
onChange={setEmail}
- placeholder="Enter your email id"
+ placeholder="Enter your email"
required
type="email"
value={email}
diff --git a/web/apps/social/src/screens/ProfileScreen.tsx b/web/apps/social/src/screens/ProfileScreen.tsx
index eadbe66596..cae029544c 100644
--- a/web/apps/social/src/screens/ProfileScreen.tsx
+++ b/web/apps/social/src/screens/ProfileScreen.tsx
@@ -6,13 +6,6 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Menu, MenuItem } from "@mui/material";
-import {
- SocialActionFeedbackIcon,
- socialActionBusyDurationMs,
- socialActionDoneDurationMs,
- socialActionTransition,
- type SocialActionPhase,
-} from "components/SocialActionFeedback";
import {
SocialFileViewer,
type SocialViewerPhoto,
@@ -46,7 +39,6 @@ const photoMasonryGap = "3px";
const photoMasonryRadius = "12px";
const showMockProfilePosts =
process.env.NEXT_PUBLIC_HIDE_SOCIAL_MOCK_PROFILE_POSTS != "true";
-type PostActionPhase = "posting" | "posted";
interface ProfilePhotoDimensions {
height: number;
@@ -149,6 +141,7 @@ interface SelectedProfilePost {
id: string;
localObjectUrl?: string;
photo: SocialViewerPhoto;
+ postActionMode?: SocialViewerPostActionMode;
}
interface PostMasonryTile {
@@ -228,8 +221,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
useState<HTMLElement | null>(null);
const [selectedPost, setSelectedPost] =
useState<SelectedProfilePost | null>(null);
- const [postActionPhase, setPostActionPhase] =
- useState<PostActionPhase | null>(null);
const [deletedPostIDs, setDeletedPostIDs] = useState<Set<string>>(
() => new Set(),
);
@@ -237,7 +228,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
useState<Record<string, ProfilePhotoDimensions>>({});
const postInputRef = React.useRef<HTMLInputElement | null>(null);
const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());
- const pendingPostRef = React.useRef<SelectedProfilePost | null>(null);
const isPublicProfile = headerVariant == "public";
const isOwnerProfile = headerVariant == "owner";
const isFriendProfile = headerVariant == "friend";
@@ -260,14 +250,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const canOpenFriends =
isOwnerProfile && friendsCount > 0 && Boolean(onOpenFriends);
const hasProfilePosts = postsSharedCount > 0;
- const isPostActionPosting = postActionPhase == "posting";
- const isPostActionPosted = postActionPhase == "posted";
- const postActionFeedbackPhase: SocialActionPhase | null =
- postActionPhase == "posting"
- ? "busy"
- : postActionPhase == "posted"
- ? "done"
- : null;
const selectedPostActionMode: SocialViewerPostActionMode = isPublicProfile
? "hidden"
: isOwnerProfile
@@ -284,14 +266,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
}, []);
const applyLocalPostDimensions = React.useCallback(
(objectUrl: string, dimensions: LocalPostPhotoDimensions) => {
- const pendingPost = pendingPostRef.current;
- if (pendingPost?.localObjectUrl == objectUrl) {
- pendingPostRef.current = {
- ...pendingPost,
- photo: { ...pendingPost.photo, ...dimensions },
- };
- }
-
setSelectedPost((currentPost) =>
currentPost?.localObjectUrl == objectUrl
? {
@@ -338,9 +312,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
event.target.value = "";
if (!file) return;
- revokeLocalPostObjectUrl(pendingPostRef.current?.localObjectUrl);
- pendingPostRef.current = null;
-
const localPost = createLocalPostPhoto({
avatarUrl: profile.avatarUrl,
file,
@@ -348,13 +319,12 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
onDimensionsLoaded: applyLocalPostDimensions,
});
localPostObjectUrlsRef.current.add(localPost.objectUrl);
- pendingPostRef.current = {
+ setSelectedPost({
id: `local-${localPost.photo.timestampMs}`,
localObjectUrl: localPost.objectUrl,
photo: localPost.photo,
- };
-
- setPostActionPhase("posting");
+ postActionMode: "draft-post",
+ });
};
const copyProfileURL = async () => {
@@ -388,28 +358,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
});
};
- React.useEffect(() => {
- if (!postActionPhase) return;
-
- const timeoutID = window.setTimeout(
- () => {
- if (postActionPhase == "posting") {
- setPostActionPhase("posted");
- return;
- }
-
- const postedPost = pendingPostRef.current;
- pendingPostRef.current = null;
- if (postedPost) setSelectedPost(postedPost);
- setPostActionPhase(null);
- },
- postActionPhase == "posting"
- ? socialActionBusyDurationMs
- : socialActionDoneDurationMs,
- );
- return () => window.clearTimeout(timeoutID);
- }, [postActionPhase]);
-
React.useEffect(
() => () => {
localPostObjectUrlsRef.current.forEach((objectUrl) =>
@@ -1207,14 +1155,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
<Box
component="button"
type="button"
- aria-label={
- isPostActionPosting
- ? "Posting photo"
- : isPostActionPosted
- ? "Photo posted"
- : "Post photo"
- }
- disabled={postActionPhase != null}
+ aria-label="Post photo"
onClick={openPostPhotoPicker}
sx={{
appearance: "none",
@@ -1222,13 +1163,8 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
bgcolor: "transparent",
border: 0,
boxSizing: "border-box",
- color: isPostActionPosted
- ? green
- : textBase,
- cursor:
- postActionPhase == null
- ? "pointer"
- : "default",
+ color: textBase,
+ cursor: "pointer",
display: "flex",
fontSize: 0,
height: 32,
@@ -1238,7 +1174,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
p: 0,
placeSelf: "center",
placeItems: "center",
- transition: `color ${socialActionTransition}`,
width: 32,
"& svg": { display: "block" },
"&:focus-visible": {
@@ -1248,16 +1183,10 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
},
}}
>
- <SocialActionFeedbackIcon
- idleIcon={
- <HugeiconsIcon
- icon={AddSquareIcon}
- size={28}
- strokeWidth={1.8}
- />
- }
- phase={postActionFeedbackPhase}
+ <HugeiconsIcon
+ icon={AddSquareIcon}
size={28}
+ strokeWidth={1.8}
/>
</Box>
)}
@@ -1271,7 +1200,10 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
name: displayName,
}}
photo={selectedPost.photo}
- postActionMode={selectedPostActionMode}
+ postActionMode={
+ selectedPost.postActionMode ??
+ selectedPostActionMode
+ }
onClose={closeSelectedPost}
onDeletePost={
isOwnerProfile ? deleteSelectedPost : undefined