Skip to content

armgit / ente

Public Imported from GitHub
0

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

Clean up Space photo viewer actions

Anand Baburajan9f45753dc9e8
diff --git a/web/apps/space/src/components/SpaceFileViewer.tsx b/web/apps/space/src/components/SpaceFileViewer.tsx
index 183b8234bf..9f929e8cdb 100644
--- a/web/apps/space/src/components/SpaceFileViewer.tsx
+++ b/web/apps/space/src/components/SpaceFileViewer.tsx
@@ -149,7 +149,6 @@ interface SpaceFileViewerProps {
onClose: () => void;
onDeletePost?: () => Promise<void> | void;
onDraftPostPublished?: () => void;
- onAddFriendForPostAction?: () => void;
onOpenProfile?: () => void;
onPublishDraftPost?: (
caption: string,
@@ -175,8 +174,6 @@ interface ViewerSwipeGesture {
startY: number;
}
-type AddFriendPostAction = "like" | "reply";
-
const viewerSwipePointFromEvent = (event: Event) => {
if (event.type.startsWith("mouse")) return undefined;
if (
@@ -295,7 +292,6 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
onClose,
onDeletePost,
onDraftPostPublished,
- onAddFriendForPostAction,
onOpenProfile,
onPublishDraftPost,
onReplyToPost,
@@ -384,17 +380,11 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
const [actionsAnchor, setActionsAnchor] =
React.useState<HTMLElement | null>(null);
const [deleteSheetOpen, setDeleteSheetOpen] = React.useState(false);
- const [addFriendSheetOpen, setAddFriendSheetOpen] = React.useState(false);
- const [addFriendPostAction, setAddFriendPostAction] =
- React.useState<AddFriendPostAction>("like");
const actionsMenuID = "space-viewer-actions-menu";
const actionsButtonID = "space-viewer-actions-button";
const isActionsOpen = Boolean(actionsAnchor);
const isDeleteActionRunning = deleteActionPhase != null;
const isDraftPostActionRunning = draftPostActionPhase != null;
- const canAddFriendForPostAction = Boolean(
- !isDraftPost && onAddFriendForPostAction,
- );
const hasDraftPostPreparationError = Boolean(draftPostPreparationError);
const canQueueDraftPostPublish =
isDraftPostPreparing &&
@@ -406,9 +396,9 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
hasDraftPostPreparationError ||
(!onPublishDraftPost && !canQueueDraftPostPublish);
const isReplyActionRunning = replyActionPhase != null;
- const canReplyToPost =
- canAddFriendForPostAction ||
- Boolean(!isDraftPost && activePhoto.postId && onReplyToPost);
+ const canReplyToPost = Boolean(
+ !isDraftPost && activePhoto.postId && onReplyToPost,
+ );
const isReplyMode =
canReplyToPost &&
(isReplyFocused || replyText.trim().length > 0 || isReplyActionRunning);
@@ -416,18 +406,13 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
!isReplyMode && isPhotoLiked && photoLikePopID > 0;
const usePhotoSwipeViewer = !isDraftPost || isDesktopViewer;
const canSendReply =
- canReplyToPost &&
- !isReplyActionRunning &&
- (canAddFriendForPostAction ||
- Boolean(activePhoto.postId && replyText.trim().length > 0));
- const addFriendSheetTitle = `Add ${displayName || "them"} as a friend to ${addFriendPostAction}?`;
+ canReplyToPost && !isReplyActionRunning && replyText.trim().length > 0;
const swipeGestureRef = React.useRef<ViewerSwipeGesture | null>(null);
const swipeActionsRef = React.useRef({ onSwipeLeft, onSwipeRight });
swipeActionsRef.current = { onSwipeLeft, onSwipeRight };
const isSwipeBlockedRef = React.useRef(false);
isSwipeBlockedRef.current =
isActionsOpen ||
- addFriendSheetOpen ||
(canDeletePost && deleteSheetOpen) ||
isDeleteExit ||
isDraftPost ||
@@ -449,25 +434,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
return nextSize;
}, []);
- const requestAddFriendForPostAction = (action: AddFriendPostAction) => {
- if (!canAddFriendForPostAction) return;
- setAddFriendPostAction(action);
- setAddFriendSheetOpen(true);
- };
-
- const closeAddFriendSheet = () => setAddFriendSheetOpen(false);
-
- const confirmAddFriendForPostAction = () => {
- setAddFriendSheetOpen(false);
- onAddFriendForPostAction?.();
- };
-
const handlePhotoLikeClick = () => {
- if (canAddFriendForPostAction) {
- requestAddFriendForPostAction("like");
- return;
- }
-
const nextLiked = !isPhotoLiked;
if (!activePhoto.postId || !onSetPostLiked) {
setIsPhotoLiked(nextLiked);
@@ -580,11 +547,6 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
};
const sendReply = () => {
- if (canAddFriendForPostAction) {
- requestAddFriendForPostAction("reply");
- return;
- }
-
const text = replyText.trim();
if (!canSendReply || !activePhoto.postId || !onReplyToPost) return;
@@ -602,27 +564,12 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
};
const handleReplyKeyDown = (event: React.KeyboardEvent) => {
- if (canAddFriendForPostAction) {
- if (event.key == "Enter" || event.key == " ") {
- event.preventDefault();
- requestAddFriendForPostAction("reply");
- }
- return;
- }
-
if (event.key != "Enter" || event.shiftKey) return;
event.preventDefault();
sendReply();
};
- const handleReplyInputPointerDown = (event: React.PointerEvent) => {
- if (!canAddFriendForPostAction) return;
-
- event.preventDefault();
- requestAddFriendForPostAction("reply");
- };
-
const handleReplyActionPointerDown = (event: React.PointerEvent) => {
event.preventDefault();
};
@@ -685,7 +632,6 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
setReplyText("");
setIsReplyFocused(focusReplyOnOpen && canReplyToPost);
setReplyActionPhase(null);
- setAddFriendSheetOpen(false);
}, [
activePhoto.caption,
activePhoto.imageUrl,
@@ -748,6 +694,36 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
onClose();
}, [isDeleteExit, onClose]);
+ React.useEffect(() => {
+ const root = viewerRootRef.current;
+ if (!root || !canReplyToPost) return;
+
+ const blurReplyInputOnOutsidePointerDown = (event: PointerEvent) => {
+ const input = replyInputRef.current;
+ if (!input || document.activeElement != input) return;
+ if (
+ event.target instanceof Element &&
+ event.target.closest("[data-space-viewer-bottom='true']")
+ ) {
+ return;
+ }
+
+ input.blur();
+ };
+
+ root.addEventListener(
+ "pointerdown",
+ blurReplyInputOnOutsidePointerDown,
+ true,
+ );
+ return () =>
+ root.removeEventListener(
+ "pointerdown",
+ blurReplyInputOnOutsidePointerDown,
+ true,
+ );
+ }, [canReplyToPost]);
+
React.useEffect(() => {
const root = viewerRootRef.current;
if (!root) return;
@@ -1552,9 +1528,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
}}
onFocus={() => setIsReplyFocused(true)}
onKeyDown={handleReplyKeyDown}
- onPointerDown={handleReplyInputPointerDown}
placeholder={`Reply privately to ${displayName}...`}
- readOnly={canAddFriendForPostAction}
rows={1}
value={replyText}
sx={{
@@ -1738,17 +1712,6 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
onExited={handleDeleteSheetExited}
/>
)}
- {canAddFriendForPostAction && (
- <ConfirmationActionSheet
- appearance="dark"
- open={addFriendSheetOpen}
- title={addFriendSheetTitle}
- confirmLabel="Add friend"
- confirmBackgroundColor={green}
- onCancel={closeAddFriendSheet}
- onConfirm={confirmAddFriendForPostAction}
- />
- )}
</Box>
);
};
diff --git a/web/apps/space/src/components/SpaceSharedInviteDialog.tsx b/web/apps/space/src/components/SpaceSharedInviteDialog.tsx
deleted file mode 100644
index a5d87533cf..0000000000
--- a/web/apps/space/src/components/SpaceSharedInviteDialog.tsx
+++ /dev/null
@@ -1,169 +0,0 @@
-import { Cancel01Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import {
- Box,
- Button,
- Dialog,
- IconButton,
- styled,
- Typography,
-} from "@mui/material";
-import { SpaceAvatarImage } from "components/SpaceAvatarImage";
-import React from "react";
-
-interface SpaceSharedInviteDialogProps {
- avatarUrl?: string | null;
- name: string;
- open: boolean;
- onAddFriend: () => void;
- onClose: () => void;
-}
-
-export const SpaceSharedInviteDialog: React.FC<
- SpaceSharedInviteDialogProps
-> = ({ avatarUrl, name, open, onAddFriend, onClose }) => {
- const titleID = React.useId();
- const subtitleID = React.useId();
-
- return (
- <StyledDialog
- open={open}
- onClose={onClose}
- aria-labelledby={titleID}
- aria-describedby={subtitleID}
- >
- <DialogWrapper>
- <CloseButton aria-label="Close" onClick={onClose}>
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={20}
- strokeWidth={1.8}
- />
- </CloseButton>
-
- <ContentContainer>
- <AvatarWrapper>
- <SpaceAvatarImage
- aria-hidden
- borderRadius="50%"
- src={avatarUrl}
- />
- </AvatarWrapper>
-
- <TitleSection>
- <Title id={titleID}>{name} invited you!</Title>
- <Subtitle id={subtitleID}>
- Add {name} as a friend to get their latest posts on
- Ente Space.
- </Subtitle>
- </TitleSection>
-
- <ButtonsSection>
- <SignInButton
- variant="contained"
- fullWidth
- onClick={onAddFriend}
- >
- Add friend
- </SignInButton>
- </ButtonsSection>
- </ContentContainer>
- </DialogWrapper>
- </StyledDialog>
- );
-};
-
-const StyledDialog = styled(Dialog)(() => ({
- "& .MuiDialog-paper": {
- width: 381,
- maxWidth: "calc(100% - 32px)",
- borderRadius: 28,
- backgroundColor: "#fff",
- padding: 0,
- margin: 16,
- overflow: "visible",
- boxShadow: "none",
- border: "1px solid #E0E0E0",
- },
- "& .MuiBackdrop-root": { backgroundColor: "rgba(0, 0, 0, 0.5)" },
-}));
-
-const DialogWrapper = styled(Box)(() => ({
- position: "relative",
- padding: "48px 16px 16px 16px",
-}));
-
-const CloseButton = styled(IconButton)(() => ({
- position: "absolute",
- top: 11,
- right: 12,
- backgroundColor: "#FAFAFA",
- color: "#000",
- padding: 10,
- "&:hover": { backgroundColor: "#F0F0F0" },
-}));
-
-const ContentContainer = styled(Box)(() => ({
- display: "flex",
- flexDirection: "column",
- alignItems: "center",
- gap: 16,
-}));
-
-const AvatarWrapper = styled(Box)(() => ({
- backgroundColor: "#FAFAFA",
- border: "1px solid #E0E0E0",
- borderRadius: "50%",
- height: 112,
- marginBottom: 8,
- overflow: "hidden",
- width: 112,
-}));
-
-const TitleSection = styled(Box)(() => ({
- display: "flex",
- flexDirection: "column",
- alignItems: "center",
- gap: 9,
- textAlign: "center",
- marginBottom: 16,
-}));
-
-const Title = styled(Typography)(() => ({
- fontWeight: 600,
- fontSize: 24,
- lineHeight: "28px",
- letterSpacing: 0,
- color: "#000",
-}));
-
-const Subtitle = styled(Typography)(() => ({
- fontWeight: 500,
- fontSize: 14,
- lineHeight: "20px",
- color: "#666666",
- maxWidth: 295,
-}));
-
-const ButtonsSection = styled(Box)(() => ({
- width: "100%",
- display: "flex",
- flexDirection: "column",
- gap: 12,
-}));
-
-const SignInButton = styled(Button)(() => ({
- display: "flex",
- padding: "20px 16px",
- justifyContent: "center",
- alignItems: "center",
- gap: 8,
- flex: "1 0 0",
- borderRadius: 20,
- backgroundColor: "#08C225",
- fontSize: 16,
- fontWeight: 500,
- textTransform: "none",
- color: "#fff",
- "&:hover": { backgroundColor: "#07A820" },
-}));