💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add avatar quick actions with an animated poke
Anand Baburajanff8a60255dba
diff --git a/web/apps/space/src/components/FriendQuickActionsDialog.tsx b/web/apps/space/src/components/FriendQuickActionsDialog.tsxnew file mode 100644index 0000000000..57ecacf178--- /dev/null+++ b/web/apps/space/src/components/FriendQuickActionsDialog.tsx@@ -0,0 +1,327 @@+import {+ BubbleChatIcon,+ HandPointingRightIcon,+ UserIcon,+} from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { Box, Dialog, useMediaQuery } from "@mui/material";+import { SpaceAvatarImage } from "components/AvatarImage";+import type { FriendProfile } from "data/friends";+import log from "ente-base/log";+import { useBrowserBackClose } from "hooks/use-browser-back-close";+import React from "react";+import { spaceDialogBackground, spaceSurface, spaceText } from "styles/colors";++const actionHeight = 40;+const actionRowPadding = 12;+const photoBorder = 2;+const innerRadius = actionHeight / 2;+const dialogRadius = innerRadius + actionRowPadding;++interface FriendQuickActionsDialogProps {+ anchorRect: DOMRect;+ avatarUrl?: string | null;+ friend: FriendProfile;+ onClose: () => void;+ onMessage: () => void;+ onPoke: () => Promise<void>;+ onProfile: () => void;+}++export const FriendQuickActionsDialog: React.FC<+ FriendQuickActionsDialogProps+> = ({+ anchorRect,+ avatarUrl,+ friend,+ onClose,+ onMessage,+ onPoke,+ onProfile,+}) => {+ const [open, setOpen] = React.useState(true);+ const [pokePhase, setPokePhase] = React.useState<"busy" | "done" | null>(+ null,+ );+ const [pokeFailed, setPokeFailed] = React.useState(false);+ const paperRef = React.useRef<HTMLDivElement>(null);+ const nameID = React.useId();+ const prefersReducedMotion = useMediaQuery(+ "(prefers-reduced-motion: reduce)",+ );+ const displayName = friend.fullName.trim() || friend.username;+ const { clearBrowserBackState } = useBrowserBackClose({+ open,+ onClose: () => setOpen(false),+ stateKey: "space-friend-quick-actions",+ });++ React.useEffect(() => {+ if (pokePhase != "done") return;+ const timeout = window.setTimeout(() => setPokePhase(null), 650);+ return () => window.clearTimeout(timeout);+ }, [pokePhase]);++ const navigate = async (action: () => void) => {+ await clearBrowserBackState("back");+ setOpen(false);+ action();+ };++ const poke = async () => {+ if (pokePhase) return;+ setPokePhase("busy");+ setPokeFailed(false);+ try {+ await onPoke();+ setPokePhase("done");+ } catch (error) {+ log.error("Failed to send poke", error);+ setPokePhase(null);+ setPokeFailed(true);+ }+ };++ const actions = [+ {+ label: "Poke",+ icon: HandPointingRightIcon,+ active: pokePhase !== null,+ done: pokePhase == "done",+ disabled: pokePhase !== null,+ busy: pokePhase == "busy",+ onClick: () => void poke(),+ },+ {+ label: "Message",+ icon: BubbleChatIcon,+ onClick: () => void navigate(onMessage),+ },+ {+ label: "Profile",+ icon: UserIcon,+ onClick: () => void navigate(onProfile),+ },+ ];++ return (+ <Dialog+ open={open}+ onClose={() => setOpen(false)}+ aria-labelledby={nameID}+ maxWidth={false}+ transitionDuration={prefersReducedMotion ? 0 : 220}+ slotProps={{+ paper: {+ ref: paperRef,+ sx: {+ bgcolor: spaceDialogBackground,+ boxShadow: "none",+ borderRadius: `${dialogRadius}px`,+ boxSizing: "border-box",+ display: "flex",+ flexDirection: "column",+ m: "16px",+ maxHeight: "calc(100% - 32px)",+ maxWidth: "calc(100vw - 32px)",+ overflow: "hidden",+ position: "relative",+ pt: `${photoBorder}px`,+ top: -160,+ width: "288px",+ "@media (max-height: 720px)": { top: 0 },+ },+ },+ transition: {+ onEnter: () => {+ const paper = paperRef.current;+ if (!paper || prefersReducedMotion) return;+ const rect = paper.getBoundingClientRect();+ const x =+ anchorRect.x ++ anchorRect.width / 2 -+ (rect.x + rect.width / 2);+ const y =+ anchorRect.y ++ anchorRect.height / 2 -+ (rect.y + rect.height / 2);+ paper.animate(+ [+ {+ transform: `translate(${x}px, ${y}px) scale(${anchorRect.width / rect.width})`,+ borderRadius: "50%",+ },+ {+ transform: "none",+ borderRadius: `${dialogRadius}px`,+ },+ ],+ {+ duration: 220,+ easing: "cubic-bezier(0.2, 0.8, 0.2, 1)",+ },+ );+ },+ onExited: onClose,+ },+ }}+ >+ <Box+ sx={{+ alignSelf: "center",+ aspectRatio: "1",+ bgcolor: spaceSurface,+ borderRadius: `${dialogRadius - photoBorder}px`,+ flexShrink: 0,+ overflow: "hidden",+ position: "relative",+ width: `min(calc(100% - ${photoBorder * 2}px), calc(100svh - ${photoBorder + actionRowPadding * 2 + actionHeight + 32}px))`,+ }}+ >+ <SpaceAvatarImage src={avatarUrl} />+ <Box+ aria-hidden+ sx={{+ background:+ "linear-gradient(rgba(0, 0, 0, 0.28), transparent 45%)",+ inset: 0,+ pointerEvents: "none",+ position: "absolute",+ }}+ />+ <Box+ component="h2"+ id={nameID}+ sx={{+ color: "#FFFFFF",+ display: "-webkit-box",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 16,+ fontWeight: 700,+ left: 24,+ lineHeight: "22px",+ m: 0,+ overflow: "hidden",+ overflowWrap: "anywhere",+ position: "absolute",+ right: 24,+ textShadow: "0 1px 6px rgba(0, 0, 0, 0.35)",+ top: 24,+ WebkitBoxOrient: "vertical",+ WebkitLineClamp: 2,+ }}+ >+ {displayName}+ </Box>+ {pokeFailed && (+ <Box+ role="alert"+ sx={{+ bgcolor: "rgba(0, 0, 0, 0.7)",+ borderRadius: "12px",+ bottom: actionRowPadding,+ color: "#FFFFFF",+ fontSize: 12,+ left: actionRowPadding,+ lineHeight: "16px",+ p: "8px 12px",+ position: "absolute",+ right: actionRowPadding,+ textAlign: "center",+ }}+ >+ Couldn’t send your poke. Tap Poke to retry.+ </Box>+ )}+ </Box>+ <Box+ sx={{+ display: "grid",+ gap: "6px",+ gridTemplateColumns: "repeat(3, minmax(0, 1fr))",+ p: `${actionRowPadding}px`,+ }}+ >+ {actions.map((action, index) => (+ <Box+ key={index}+ component="button"+ type="button"+ disabled={action.disabled}+ aria-busy={action.busy}+ aria-label={action.done ? "Poke sent" : action.label}+ aria-live={+ action.done !== undefined ? "polite" : undefined+ }+ onClick={action.onClick}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: spaceSurface,+ border: 0,+ borderRadius: `${innerRadius}px`,+ color: spaceText,+ cursor: action.disabled ? "default" : "pointer",+ display: "grid",+ justifyItems: "center",+ height: actionHeight,+ minWidth: 0,+ p: "0 8px",+ transition: "filter 120ms ease",+ "&:hover:not(:disabled)": {+ filter: "brightness(0.96)",+ },+ "&:active:not(:disabled)": {+ filter: "brightness(0.92)",+ },+ "&:focus-visible": {+ outline: `2px solid ${spaceText}`,+ outlineOffset: 2,+ },+ }}+ >+ <Box+ component="span"+ aria-hidden+ sx={{+ alignItems: "center",+ color: action.active ? "#08C225" : spaceText,+ display: "flex",+ height: 24,+ justifyContent: "center",+ width: 24,+ animation: action.active+ ? "spacePokeJab 550ms ease-in-out"+ : "none",+ "@keyframes spacePokeJab": {+ "0%, 100%": {+ transform:+ "translate(0, 0) rotate(0deg) scale(1)",+ },+ "50%": {+ transform:+ "translate(28px, -36px) rotate(-40deg) scale(2.25)",+ },+ },+ "@media (prefers-reduced-motion: reduce)": {+ animation: "none",+ },+ ...(action.icon == BubbleChatIcon && {+ "& svg path:first-of-type": {+ display: "none",+ },+ }),+ }}+ >+ <HugeiconsIcon+ icon={action.icon}+ size={24}+ strokeWidth={2.2}+ />+ </Box>+ </Box>+ ))}+ </Box>+ </Dialog>+ );+};diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsxindex b92325b0cc..e6e2f3db68 100644--- a/web/apps/space/src/pages/app/index.tsx+++ b/web/apps/space/src/pages/app/index.tsx@@ -29,6 +29,7 @@ import {loadCurrentSpaceProfilePostsPage,loadCurrentUnreadStatus,replyToCurrentPost,+ sendCurrentPoke,setCurrentPostLiked,type SpaceFriendRequest,type SpacePost,@@ -351,6 +352,27 @@ const Page: React.FC = () => {onLoadFriendPosts={loadCurrentSpaceProfilePostsPage}onLoadPostImage={loadCurrentSpacePostAssetURL}onOpenMessages={() => void router.push(spaceRoutes.messages)}+ onMessageFriend={(friend) =>+ void router.push(+ spaceRoutes.message(friend.spaceId ?? friend.id),+ )+ }+ onPokeFriend={async (friend) => {+ if (!profile?.spaceId) throw new Error("Missing space.");+ await sendCurrentPoke(+ profile.spaceId,+ friend.spaceId ?? friend.id,+ {+ id: profile.spaceId,+ spaceId: profile.spaceId,+ fullName: profile.fullName,+ username: profile.username,+ avatarUrl: profile.avatarUrl,+ friendsCount: 0,+ },+ friend,+ );+ }}onOpenFriendRequests={() =>void router.push(spaceRoutes.friends)}diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex 1ec4a1a8b0..01e2d0afac 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -13,6 +13,7 @@ import {type SpaceViewerPhoto,type SpaceViewerPostActionMode,} from "components/FileViewer";+import { FriendQuickActionsDialog } from "components/FriendQuickActionsDialog";import {SpaceHomeHeader,spaceHomeHeaderChromeColor,@@ -95,6 +96,8 @@ interface HomeScreenProps {onOpenFriend?: (friendID: string, username?: string) => void;onOpenFriendRequests?: () => void;onOpenMessages?: () => void;+ onMessageFriend: (friend: FriendProfile) => void;+ onPokeFriend: (friend: FriendProfile) => Promise<void>;onOpenProfile?: () => void;onReplyToPost?: (postSpaceId: string,@@ -258,6 +261,7 @@ interface FriendPostTileProps {onAcceptFriendRequest?: () => Promise<void>;onDiscardFriendRequest?: () => Promise<void>;onOpenFriend?: (friendID: string, username?: string) => void;+ onOpenAvatar?: (anchorRect: DOMRect) => void;onOpenFriendRequest?: () => void;onOpenPosts: (friend: FriendProfile,@@ -284,6 +288,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({onLoadAvatar,onLoadImage,onOpenFriend,+ onOpenAvatar,onOpenFriendRequest,onOpenPosts,isTwoTileLayout = false,@@ -461,16 +466,16 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({});};- const openFriend = () => {+ const openAvatar = (event: React.MouseEvent<HTMLButtonElement>) => {if (isRequestPending) {onOpenFriendRequest?.();return;}- onOpenFriend?.(friend.id, friend.username);+ onOpenAvatar?.(event.currentTarget.getBoundingClientRect());};- const canOpenFriend = isRequestPending+ const canOpenAvatar = isRequestPending? canOpenFriendRequest- : Boolean(onOpenFriend);+ : Boolean(onOpenAvatar);return (<Box@@ -687,10 +692,11 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({aria-label={friendRequestDirection == "sent"? `Manage friend request sent to ${firstName}`- : `Open ${firstName}'s profile`+ : `Open actions for ${displayName}`}- disabled={!canOpenFriend || isFriendRequestActionBusy}- onClick={openFriend}+ aria-haspopup={isRequestPending ? undefined : "dialog"}+ disabled={!canOpenAvatar || isFriendRequestActionBusy}+ onClick={openAvatar}sx={{appearance: "none",bgcolor: "transparent",@@ -700,7 +706,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({borderRadius: "50%",bottom: "10%",boxSizing: "border-box",- cursor: canOpenFriend ? "pointer" : "default",+ cursor: canOpenAvatar ? "pointer" : "default",height: avatarSize,left: "10%",maxHeight: 36,@@ -1022,6 +1028,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({onOpenFriend,onOpenFriendRequests,onOpenMessages,+ onMessageFriend,+ onPokeFriend,onOpenProfile,onReplyToPost,onSetPostLiked,@@ -1031,6 +1039,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({}) => {const [selectedViewer, setSelectedViewer] =useState<SelectedHomeViewer | null>(null);+ const [selectedContact, setSelectedContact] = useState<{+ anchorRect: DOMRect;+ friend: FriendProfile;+ avatarUrl?: string | null;+ } | null>(null);const [openedPostIds, setOpenedPostIds] = useState<Set<number>>(new Set());const [postTileCanvasSize, setPostTileCanvasSize] =useState<PostTileCanvasSize>({ height: 0, width: 0 });@@ -1515,6 +1528,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({: undefined}onOpenFriend={onOpenFriend}+ onOpenAvatar={(anchorRect) =>+ setSelectedContact({ anchorRect, friend, avatarUrl })+ }onOpenPosts={(friend, posts, photo) =>openPostPhotos(friend, posts, photo, isRead)}@@ -1939,6 +1955,22 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({disabled={isPostPhotoButtonDisabled}onClick={openPostPhotoPicker}/>+ {selectedContact && (+ <FriendQuickActionsDialog+ {...selectedContact}+ onClose={() => setSelectedContact(null)}+ onMessage={() =>+ onMessageFriend(selectedContact.friend)+ }+ onPoke={() => onPokeFriend(selectedContact.friend)}+ onProfile={() =>+ onOpenFriend?.(+ selectedContact.friend.id,+ selectedContact.friend.username,+ )+ }+ />+ )}{selectedViewer && (<SpaceFileViewerfocusReplyOnOpen={selectedViewer.focusReplyOnOpen}