Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add delete post action to social viewer

Anand Baburajan8f5752f83086
diff --git a/web/apps/social/src/components/ConfirmationActionSheet.tsx b/web/apps/social/src/components/ConfirmationActionSheet.tsx
index ff60e08bd6..57d6ecc92c 100644
--- a/web/apps/social/src/components/ConfirmationActionSheet.tsx
+++ b/web/apps/social/src/components/ConfirmationActionSheet.tsx
@@ -6,6 +6,7 @@ const dangerColor = "#F63A3A";
const textBase = "#000";
interface ConfirmationActionSheetProps {
+ appearance?: "light" | "dark";
open: boolean;
title: string;
confirmLabel: string;
@@ -17,6 +18,7 @@ interface ConfirmationActionSheetProps {
export const ConfirmationActionSheet: React.FC<
ConfirmationActionSheetProps
> = ({
+ appearance = "light",
open,
title,
confirmLabel,
@@ -25,6 +27,7 @@ export const ConfirmationActionSheet: React.FC<
onConfirm,
}) => {
const titleID = React.useId();
+ const isDark = appearance == "dark";
return (
<Dialog
@@ -32,13 +35,28 @@ export const ConfirmationActionSheet: React.FC<
onClose={onCancel}
maxWidth={false}
aria-labelledby={titleID}
+ sx={
+ isDark
+ ? {
+ zIndex: 1500,
+ "& .MuiBackdrop-root": {
+ backgroundColor:
+ "rgba(0, 0, 0, 0.86) !important",
+ },
+ }
+ : undefined
+ }
slotProps={{
backdrop: {
- sx: { backgroundColor: "rgba(0, 0, 0, 0.48)" },
+ sx: {
+ backgroundColor: isDark
+ ? "rgba(0, 0, 0, 0.86)"
+ : "rgba(0, 0, 0, 0.48)",
+ },
},
paper: {
sx: {
- bgcolor: "#FAFAFA",
+ bgcolor: isDark ? "#1E1E1E" : "#FAFAFA",
borderRadius: "20px 20px 0 0",
bottom: 0,
boxShadow: "none",
@@ -58,7 +76,7 @@ export const ConfirmationActionSheet: React.FC<
component="h2"
id={titleID}
sx={{
- color: textBase,
+ color: isDark ? "#F4F4F4" : textBase,
fontFamily: '"Inter Variable", Inter, sans-serif',
fontSize: 15,
fontWeight: 600,
@@ -86,8 +104,8 @@ export const ConfirmationActionSheet: React.FC<
/>
<SheetButton
label={cancelLabel}
- backgroundColor="#F2F2F2"
- color="#666666"
+ backgroundColor={isDark ? "#333333" : "#F2F2F2"}
+ color={isDark ? "#D8D8D8" : "#666666"}
onClick={onCancel}
/>
</Box>
diff --git a/web/apps/social/src/components/SocialFileViewer.tsx b/web/apps/social/src/components/SocialFileViewer.tsx
index 9b23f334ff..2db3d7bc65 100644
--- a/web/apps/social/src/components/SocialFileViewer.tsx
+++ b/web/apps/social/src/components/SocialFileViewer.tsx
@@ -1,6 +1,11 @@
-import { Cancel01Icon } from "@hugeicons/core-free-icons";
+import {
+ Cancel01Icon,
+ Delete02Icon,
+ MoreHorizontalIcon,
+} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
-import { Box } from "@mui/material";
+import { Box, Menu, MenuItem } from "@mui/material";
+import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";
import type PhotoSwipe from "photoswipe";
import React from "react";
import {
@@ -18,6 +23,7 @@ const viewerBackground = "#000000";
const controlBackground = "rgba(36, 36, 36, 0.72)";
const controlBackgroundHover = "rgba(48, 48, 48, 0.86)";
const controlIcon = "#D8D8D8";
+const dangerColor = "#F63A3A";
const viewerHeaderHeight = 56;
const viewerBottomPadding = 0;
const defaultPhotoWidth = 900;
@@ -36,12 +42,14 @@ export interface SocialViewerPhoto {
interface SocialFileViewerProps {
onClose: () => void;
+ onDeletePost?: () => void;
onOpenProfile?: () => void;
photo: SocialViewerPhoto;
}
export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
onClose,
+ onDeletePost,
onOpenProfile,
photo,
}) => {
@@ -49,6 +57,24 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
const dateLabel = formatSocialDate(photo.timestampMs);
const initials = initialsFor(photo.name);
const viewerRootRef = React.useRef<HTMLDivElement | null>(null);
+ const [actionsAnchor, setActionsAnchor] =
+ React.useState<HTMLElement | null>(null);
+ const [deleteSheetOpen, setDeleteSheetOpen] = React.useState(false);
+ const actionsMenuID = "social-viewer-actions-menu";
+ const actionsButtonID = "social-viewer-actions-button";
+ const isActionsOpen = Boolean(actionsAnchor);
+
+ const closeActions = () => setActionsAnchor(null);
+
+ const requestDeletePost = () => {
+ closeActions();
+ setDeleteSheetOpen(true);
+ };
+
+ const confirmDeletePost = () => {
+ setDeleteSheetOpen(false);
+ onDeletePost?.();
+ };
React.useEffect(() => {
const root = viewerRootRef.current;
@@ -137,12 +163,13 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
React.useEffect(() => {
const closeOnEscape = (event: KeyboardEvent) => {
+ if (deleteSheetOpen) return;
if (event.key == "Escape") onClose();
};
window.addEventListener("keydown", closeOnEscape);
return () => window.removeEventListener("keydown", closeOnEscape);
- }, [onClose]);
+ }, [deleteSheetOpen, onClose]);
return (
<Box
@@ -171,7 +198,7 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
display: "grid",
flexShrink: 0,
gap: "12px",
- gridTemplateColumns: "minmax(0, 1fr) 40px",
+ gridTemplateColumns: "minmax(0, 1fr) auto",
minHeight: viewerHeaderHeight,
position: "relative",
px: "16px",
@@ -319,36 +346,161 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
</Box>
</Box>
<Box
- component="button"
- type="button"
- aria-label="Close viewer"
- onClick={onClose}
sx={{
alignItems: "center",
- bgcolor: controlBackground,
- border: 0,
- borderRadius: "50%",
- color: controlIcon,
- cursor: "pointer",
display: "flex",
- height: 28,
- justifyContent: "center",
+ gap: "16px",
justifySelf: "flex-end",
- p: 0,
- width: 28,
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": { bgcolor: controlBackgroundHover },
}}
>
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={18}
- strokeWidth={1.8}
- />
+ {onDeletePost && (
+ <Box
+ component="button"
+ id={actionsButtonID}
+ type="button"
+ aria-label="Post actions"
+ aria-controls={
+ isActionsOpen ? actionsMenuID : undefined
+ }
+ aria-expanded={isActionsOpen ? "true" : undefined}
+ aria-haspopup="menu"
+ onClick={(event) =>
+ setActionsAnchor(event.currentTarget)
+ }
+ sx={{
+ alignItems: "center",
+ bgcolor: "transparent",
+ border: 0,
+ color: controlIcon,
+ cursor: "pointer",
+ display: "flex",
+ height: 32,
+ justifyContent: "center",
+ p: 0,
+ width: 32,
+ "&:focus-visible": {
+ borderRadius: "50%",
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ "&:hover": { color: textBase },
+ }}
+ >
+ <HugeiconsIcon
+ icon={MoreHorizontalIcon}
+ size={26}
+ strokeWidth={2}
+ />
+ </Box>
+ )}
+ <Box
+ component="button"
+ type="button"
+ aria-label="Close viewer"
+ onClick={onClose}
+ sx={{
+ alignItems: "center",
+ bgcolor: controlBackground,
+ border: 0,
+ borderRadius: "50%",
+ color: controlIcon,
+ cursor: "pointer",
+ display: "flex",
+ height: 28,
+ justifyContent: "center",
+ p: 0,
+ width: 28,
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ "&:hover": { bgcolor: controlBackgroundHover },
+ }}
+ >
+ <HugeiconsIcon
+ icon={Cancel01Icon}
+ size={18}
+ strokeWidth={1.8}
+ />
+ </Box>
</Box>
+ {onDeletePost && (
+ <Menu
+ id={actionsMenuID}
+ anchorEl={actionsAnchor}
+ open={isActionsOpen}
+ onClose={closeActions}
+ anchorOrigin={{
+ horizontal: "right",
+ vertical: "bottom",
+ }}
+ transformOrigin={{
+ horizontal: "right",
+ vertical: "top",
+ }}
+ slotProps={{
+ paper: {
+ sx: {
+ bgcolor: "#1E1E1E",
+ borderRadius: "16px",
+ boxShadow:
+ "0 14px 40px rgba(0, 0, 0, 0.16)",
+ mt: "6px",
+ minWidth: 0,
+ p: "4px",
+ width: "max-content",
+ },
+ },
+ list: {
+ "aria-labelledby": actionsButtonID,
+ sx: { p: 0 },
+ },
+ }}
+ >
+ <MenuItem
+ disableRipple
+ onClick={requestDeletePost}
+ sx={{
+ alignItems: "center",
+ borderRadius: "10px",
+ color: dangerColor,
+ display: "flex",
+ gap: "8px",
+ minHeight: 38,
+ 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>
<Box
sx={{
@@ -386,6 +538,16 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
zIndex: 1,
}}
/>
+ {onDeletePost && (
+ <ConfirmationActionSheet
+ appearance="dark"
+ open={deleteSheetOpen}
+ title="Are you sure you want to delete this?"
+ confirmLabel="Yes, delete"
+ onCancel={() => setDeleteSheetOpen(false)}
+ onConfirm={confirmDeletePost}
+ />
+ )}
</Box>
);
};
diff --git a/web/apps/social/src/screens/ProfileScreen.tsx b/web/apps/social/src/screens/ProfileScreen.tsx
index eaf8886d4c..ac6c0e7963 100644
--- a/web/apps/social/src/screens/ProfileScreen.tsx
+++ b/web/apps/social/src/screens/ProfileScreen.tsx
@@ -78,6 +78,7 @@ const samplePostGroups = samplePostDateLabels.map((label, groupIndex) => ({
items: Array.from(
{ length: samplePostPhotoCounts[groupIndex] ?? 1 },
(_, itemIndex) => ({
+ id: `${groupIndex}-${itemIndex}`,
imageUrl: samplePhotoUrlAt(groupIndex + itemIndex),
aspectRatio: samplePhotoAspectRatioAt(groupIndex + itemIndex),
timestampMs: samplePostTimestampAt(groupIndex, itemIndex),
@@ -87,6 +88,11 @@ const samplePostGroups = samplePostDateLabels.map((label, groupIndex) => ({
type SamplePostItem = (typeof samplePostGroups)[number]["items"][number];
+interface SelectedProfilePost {
+ id: string;
+ photo: SocialViewerPhoto;
+}
+
interface PostMasonryRow {
height: number;
compactHeight: number;
@@ -169,8 +175,11 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
}) => {
const [profileActionsAnchor, setProfileActionsAnchor] =
useState<HTMLElement | null>(null);
- const [selectedPhoto, setSelectedPhoto] =
- useState<SocialViewerPhoto | null>(null);
+ const [selectedPost, setSelectedPost] =
+ useState<SelectedProfilePost | null>(null);
+ const [deletedPostIDs, setDeletedPostIDs] = useState<Set<string>>(
+ () => new Set(),
+ );
const isPublicProfile = headerVariant == "public";
const isOwnerProfile = headerVariant == "owner";
const isFriendProfile = headerVariant == "friend";
@@ -178,7 +187,13 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const profileLink = profileLinkForUsername(profile.username.trim());
const initialsSource = displayName || profile.username.trim();
const initials = initialsFor(initialsSource);
- const postsSharedCount = samplePostGroups.reduce(
+ const visiblePostGroups = samplePostGroups
+ .map((group) => ({
+ ...group,
+ items: group.items.filter((item) => !deletedPostIDs.has(item.id)),
+ }))
+ .filter((group) => group.items.length > 0);
+ const postsSharedCount = visiblePostGroups.reduce(
(count, group) => count + group.items.length,
0,
);
@@ -208,6 +223,17 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
await navigator.clipboard.writeText(profileLink);
};
+ const deleteSelectedPost = () => {
+ if (!selectedPost) return;
+
+ setDeletedPostIDs((currentPostIDs) => {
+ const nextPostIDs = new Set(currentPostIDs);
+ nextPostIDs.add(selectedPost.id);
+ return nextPostIDs;
+ });
+ setSelectedPost(null);
+ };
+
return (
<Box
component="main"
@@ -763,7 +789,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
width: "100%",
}}
>
- {samplePostGroups.map((group) => (
+ {visiblePostGroups.map((group) => (
<Box
component="section"
key={group.label}
@@ -820,17 +846,21 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
index + 1
}`}
onClick={() =>
- setSelectedPhoto({
- alt: `${displayName} post ${
- index + 1
- }`,
- avatarUrl:
- profile.avatarUrl,
- imageUrl:
- item.imageUrl,
- name: displayName,
- timestampMs:
- item.timestampMs,
+ setSelectedPost({
+ id: item.id,
+ photo: {
+ alt: `${displayName} post ${
+ index +
+ 1
+ }`,
+ avatarUrl:
+ profile.avatarUrl,
+ imageUrl:
+ item.imageUrl,
+ name: displayName,
+ timestampMs:
+ item.timestampMs,
+ },
})
}
key={`${group.label}-${item.imageUrl}-${index}`}
@@ -878,11 +908,14 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
</Box>
))}
</Box>
- {selectedPhoto && (
+ {selectedPost && (
<SocialFileViewer
- photo={selectedPhoto}
- onClose={() => setSelectedPhoto(null)}
- onOpenProfile={() => setSelectedPhoto(null)}
+ photo={selectedPost.photo}
+ onClose={() => setSelectedPost(null)}
+ onDeletePost={
+ isOwnerProfile ? deleteSelectedPost : undefined
+ }
+ onOpenProfile={() => setSelectedPost(null)}
/>
)}
</Box>