Skip to content

armgit / ente

Public Imported from GitHub
0

đź’š End-to-end encrypted cloud for everything.

Refine Friends orbit and request actions

Anand Baburajan2854066891a8
diff --git a/web/apps/space/src/components/FriendOrbit.tsx b/web/apps/space/src/components/FriendOrbit.tsx
index d4db862c73..adbf101b04 100644
--- a/web/apps/space/src/components/FriendOrbit.tsx
+++ b/web/apps/space/src/components/FriendOrbit.tsx
@@ -1,5 +1,4 @@
import { Box, useMediaQuery } from "@mui/material";
-import type { FriendProfile } from "data/friends";
import React from "react";
import {
arrangeFriendOrbit,
@@ -11,8 +10,13 @@ import {
} from "utils/friend-orbit";
interface FriendOrbitProps {
- friends: FriendProfile[];
- renderFriend: (friend: FriendProfile) => React.ReactNode;
+ initialOuterID?: string;
+ items: {
+ id: string;
+ size?: number;
+ fixedSize?: number;
+ content: React.ReactNode;
+ }[];
}
interface OrbitDrag {
@@ -26,8 +30,8 @@ interface OrbitDrag {
}
export const FriendOrbit: React.FC<FriendOrbitProps> = ({
- friends,
- renderFriend,
+ initialOuterID,
+ items,
}) => {
const fieldRef = React.useRef<HTMLUListElement>(null);
const elements = React.useRef(new Map<string, HTMLLIElement>());
@@ -59,13 +63,9 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
const current = new Map(
circles.current.map((circle) => [circle.id, circle]),
);
- let friendsChanged =
- friends.length != current.size ||
- friends.some((friend) => !current.has(friend.id));
- circles.current = friends.map(
- (friend, index) =>
- current.get(friend.id) ??
- createFriendOrbitCircle(friend.id, index),
+ circles.current = items.map(
+ (item, index) =>
+ current.get(item.id) ?? createFriendOrbitCircle(item.id, index),
);
const field = fieldRef.current!;
const resize = () => {
@@ -85,11 +85,15 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
scale,
};
circles.current.forEach((circle, index) => {
- circle.size = friendOrbitCircleSize(
- index,
- friends.length,
- availableBounds,
- );
+ const item = items[index]!;
+ circle.size = item.fixedSize
+ ? item.fixedSize / scale
+ : (item.size ??
+ friendOrbitCircleSize(
+ index,
+ items.length,
+ availableBounds,
+ ));
});
const area = circles.current.reduce(
(total, circle) =>
@@ -99,7 +103,6 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
field.style.minHeight = `${Math.ceil(area / (width * 0.52))}px`;
const height = field.clientHeight;
const layoutChanged =
- friendsChanged ||
width != bounds.current.width ||
height != bounds.current.height;
bounds.current = { width, height, scale };
@@ -113,8 +116,15 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
circles.current,
bounds.current,
elapsed.current,
+ initialOuterID,
+ );
+ else
+ stepFriendOrbit(
+ circles.current,
+ bounds.current,
+ elapsed.current,
+ 0,
);
- friendsChanged = false;
paint();
field.style.opacity = "1";
};
@@ -122,7 +132,7 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
observer.observe(field);
resize();
return () => observer.disconnect();
- }, [friends, paint]);
+ }, [initialOuterID, items, paint]);
React.useEffect(() => {
if (reducedMotion) return;
@@ -153,8 +163,9 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
if (event.button != 0 || !event.isPrimary) return;
event.stopPropagation();
const circle = circles.current.find((circle) => circle.id == friendID)!;
- const button = event.currentTarget.querySelector("button")!;
- button.setPointerCapture(event.pointerId);
+ const target =
+ (event.target as Element).closest("button") ?? event.currentTarget;
+ target.setPointerCapture(event.pointerId);
drag.current = {
pointerID: event.pointerId,
circle,
@@ -207,7 +218,7 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
<Box
component="ul"
ref={fieldRef}
- aria-label="Your friends"
+ aria-label="Friends and friend requests"
onDragStart={(event) => event.preventDefault()}
onClickCapture={(event) => {
if (!suppressClick.current) return;
@@ -227,15 +238,15 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
width: "100%",
}}
>
- {friends.map((friend) => (
+ {items.map((item) => (
<Box
component="li"
- key={friend.id}
+ key={item.id}
ref={(element: HTMLLIElement | null) => {
- if (element) elements.current.set(friend.id, element);
- else elements.current.delete(friend.id);
+ if (element) elements.current.set(item.id, element);
+ else elements.current.delete(item.id);
}}
- onPointerDown={(event) => startDrag(event, friend.id)}
+ onPointerDown={(event) => startDrag(event, item.id)}
onPointerMove={moveDrag}
onPointerUp={endDrag}
onPointerCancel={endDrag}
@@ -243,23 +254,24 @@ export const FriendOrbit: React.FC<FriendOrbitProps> = ({
onContextMenu={(event) => event.preventDefault()}
sx={{
borderRadius: "50%",
+ cursor: heldFriendID == item.id ? "grabbing" : "grab",
left: 0,
position: "absolute",
top: 0,
touchAction: "none",
WebkitTouchCallout: "none",
willChange: "transform",
- zIndex: heldFriendID == friend.id ? 2 : undefined,
+ zIndex: heldFriendID == item.id ? 2 : undefined,
"&:hover, &:focus-within": { zIndex: 1 },
- "& button": {
+ "& > button": {
cursor:
- heldFriendID == friend.id ? "grabbing" : "grab",
- ...(heldFriendID == friend.id && { scale: "1.06" }),
+ heldFriendID == item.id ? "grabbing" : "grab",
+ ...(heldFriendID == item.id && { scale: "1.06" }),
},
"& img": { pointerEvents: "none" },
}}
>
- {renderFriend(friend)}
+ {item.content}
</Box>
))}
</Box>
diff --git a/web/apps/space/src/components/FriendQuickActionsDialog.tsx b/web/apps/space/src/components/FriendQuickActionsDialog.tsx
index 5378b15c01..9f82d18881 100644
--- a/web/apps/space/src/components/FriendQuickActionsDialog.tsx
+++ b/web/apps/space/src/components/FriendQuickActionsDialog.tsx
@@ -1,11 +1,18 @@
import {
BubbleChatIcon,
+ Cancel01Icon,
HandPointingRightIcon,
+ Tick02Icon,
UserIcon,
UserRemove01Icon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Dialog, useMediaQuery } from "@mui/material";
+import {
+ spaceActionDoneDurationMs,
+ SpaceActionFeedbackIcon,
+ type SpaceActionPhase,
+} from "components/ActionFeedback";
import { SpaceAvatarImage } from "components/AvatarImage";
import type { FriendProfile } from "data/friends";
import log from "ente-base/log";
@@ -33,6 +40,10 @@ interface FriendQuickActionsDialogProps {
onPoke?: () => Promise<void>;
onProfile?: () => void;
onUnfriend?: () => void;
+ requestActions?: {
+ onAccept?: () => Promise<boolean>;
+ onCancel: () => Promise<void>;
+ };
}
export const FriendQuickActionsDialog: React.FC<
@@ -46,18 +57,26 @@ export const FriendQuickActionsDialog: React.FC<
onPoke,
onProfile,
onUnfriend,
+ requestActions,
}) => {
const [open, setOpen] = React.useState(true);
const [pokePhase, setPokePhase] = React.useState<"busy" | "done" | null>(
null,
);
const [pokeFailed, setPokeFailed] = React.useState(false);
+ const [requestAction, setRequestAction] = React.useState<{
+ type: "accept" | "cancel";
+ phase: SpaceActionPhase;
+ } | null>(null);
+ const [requestFailed, setRequestFailed] = 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 displayName = requestActions
+ ? `@${friend.username}`
+ : friend.fullName.trim() || friend.username;
const { clearBrowserBackState } = useBrowserBackClose({
open,
onClose: () => setOpen(false),
@@ -70,6 +89,15 @@ export const FriendQuickActionsDialog: React.FC<
return () => window.clearTimeout(timeout);
}, [pokePhase]);
+ React.useEffect(() => {
+ if (requestAction?.phase != "done") return;
+ const timeout = window.setTimeout(
+ () => setOpen(false),
+ spaceActionDoneDurationMs,
+ );
+ return () => window.clearTimeout(timeout);
+ }, [requestAction?.phase]);
+
const navigate = async (action: () => void) => {
await clearBrowserBackState("back");
setOpen(false);
@@ -90,13 +118,63 @@ export const FriendQuickActionsDialog: React.FC<
}
};
+ const updateRequest = async (
+ action: "accept" | "cancel",
+ handler: () => Promise<void> | Promise<boolean>,
+ ) => {
+ if (requestAction) return;
+ setRequestAction({ type: action, phase: "busy" });
+ setRequestFailed(false);
+ try {
+ const accepted = await handler();
+ if (action == "accept" && accepted)
+ setRequestAction({ type: action, phase: "done" });
+ else setOpen(false);
+ } catch (error) {
+ log.error("Failed to update friend request", error);
+ setRequestAction(null);
+ setRequestFailed(true);
+ }
+ };
+
const actions = [
+ {
+ label: "Accept request",
+ text: "Accept",
+ available: Boolean(requestActions?.onAccept),
+ icon: Tick02Icon,
+ disabled: requestAction !== null,
+ busy:
+ requestAction?.type == "accept" &&
+ requestAction.phase == "busy",
+ done:
+ requestAction?.type == "accept" &&
+ requestAction.phase == "done",
+ doneLabel: "Request accepted",
+ phase: requestAction?.type == "accept" ? requestAction.phase : null,
+ onClick: () =>
+ requestActions?.onAccept &&
+ void updateRequest("accept", requestActions.onAccept),
+ },
+ {
+ label: "Cancel request",
+ text: requestActions?.onAccept ? "Cancel" : "Cancel request",
+ busyText: "Canceling…",
+ available: Boolean(requestActions),
+ icon: Cancel01Icon,
+ disabled: requestAction !== null,
+ busy: requestAction?.type == "cancel",
+ onClick: () =>
+ requestActions &&
+ void updateRequest("cancel", requestActions.onCancel),
+ },
{
label: "Poke",
available: Boolean(onPoke),
icon: HandPointingRightIcon,
active: pokePhase !== null,
done: pokePhase == "done",
+ doneLabel: "Poke sent",
disabled: pokePhase !== null,
busy: pokePhase == "busy",
onClick: () => void poke(),
@@ -124,7 +202,7 @@ export const FriendQuickActionsDialog: React.FC<
return (
<Dialog
open={open}
- onClose={() => setOpen(false)}
+ onClose={requestAction ? undefined : () => setOpen(false)}
aria-labelledby={nameID}
maxWidth={false}
transitionDuration={prefersReducedMotion ? 0 : 220}
@@ -197,12 +275,14 @@ export const FriendQuickActionsDialog: React.FC<
width: `min(calc(100% - ${dialogPadding * 2}px), calc(100svh - ${dialogPadding * 3 + actionHeight + 32}px))`,
}}
>
- <SpaceAvatarImage src={avatarUrl} />
+ <SpaceAvatarImage
+ src={requestActions ? undefined : avatarUrl}
+ />
<Box
aria-hidden
sx={{
background:
- "linear-gradient(rgba(0, 0, 0, 0.52), transparent 55%)",
+ "linear-gradient(rgba(0, 0, 0, 0.28), transparent 40%)",
inset: 0,
pointerEvents: "none",
position: "absolute",
@@ -232,7 +312,7 @@ export const FriendQuickActionsDialog: React.FC<
>
{displayName}
</Box>
- {pokeFailed && (
+ {(pokeFailed || requestFailed) && (
<Box
role="alert"
sx={{
@@ -249,7 +329,9 @@ export const FriendQuickActionsDialog: React.FC<
textAlign: "center",
}}
>
- Couldn’t send your poke. Tap Poke to retry.
+ {requestFailed
+ ? "Couldn’t update the request. Please try again."
+ : "Couldn’t send your poke. Tap Poke to retry."}
</Box>
)}
</Box>
@@ -264,12 +346,17 @@ export const FriendQuickActionsDialog: React.FC<
{actions.map((action, index) => (
<Box
key={index}
+ className={
+ action.icon == Tick02Icon ? "green-bg" : undefined
+ }
component="button"
type="button"
disabled={action.disabled}
aria-busy={action.busy}
- aria-label={action.done ? "Poke sent" : action.label}
- title={action.done ? "Poke sent" : action.label}
+ aria-label={
+ action.done ? action.doneLabel : action.label
+ }
+ title={action.done ? action.doneLabel : action.label}
aria-live={
action.done !== undefined ? "polite" : undefined
}
@@ -277,14 +364,23 @@ export const FriendQuickActionsDialog: React.FC<
sx={{
alignItems: "center",
appearance: "none",
- bgcolor: spaceDialogBackground,
+ bgcolor:
+ action.icon == Tick02Icon
+ ? "#08C225"
+ : spaceDialogBackground,
border: 0,
borderRadius: `${innerRadius}px`,
- color: action.active
- ? "color(display-p3 0.0314 0.7608 0.1451)"
- : "#D8D8D8",
+ color:
+ action.icon == Tick02Icon
+ ? "#FFFFFF"
+ : action.active
+ ? "color(display-p3 0.0314 0.7608 0.1451)"
+ : "#D8D8D8",
cursor: action.disabled ? "default" : "pointer",
display: "grid",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 600,
justifyItems: "center",
height: actionHeight,
minWidth: 0,
@@ -292,10 +388,16 @@ export const FriendQuickActionsDialog: React.FC<
...(action.label != "Poke" && {
transition: "background-color 120ms ease",
"&:hover:not(:disabled)": {
- bgcolor: spaceSurfaceHover,
+ bgcolor:
+ action.icon == Tick02Icon
+ ? "#07A820"
+ : spaceSurfaceHover,
},
"&:active:not(:disabled)": {
- bgcolor: spaceAppBackgroundColor,
+ bgcolor:
+ action.icon == Tick02Icon
+ ? "#078D1C"
+ : spaceAppBackgroundColor,
},
}),
"&:focus-visible": {
@@ -304,48 +406,58 @@ export const FriendQuickActionsDialog: React.FC<
},
}}
>
- <Box
- component="span"
- aria-hidden
- sx={{
- alignItems: "center",
- display: "flex",
- height: 24,
- justifyContent: "center",
- width: 24,
- animation: action.active
- ? "spacePokeJab 2000ms ease-in-out"
- : "none",
- "@keyframes spacePokeJab": {
- "0%, 100%": {
- transform:
- "translate(0, 0) rotate(0deg) scale(1)",
- },
- "27.5%, 52%, 73.75%": {
- transform:
- "translate(20px, -80px) rotate(-40deg) scale(3)",
- },
- "41%, 63%": {
- transform:
- "translate(36px, -94px) rotate(-40deg) scale(3)",
+ {action.phase ? (
+ <SpaceActionFeedbackIcon phase={action.phase} />
+ ) : action.text ? (
+ action.busy ? (
+ action.busyText
+ ) : (
+ action.text
+ )
+ ) : (
+ <Box
+ component="span"
+ aria-hidden
+ sx={{
+ alignItems: "center",
+ display: "flex",
+ height: 24,
+ justifyContent: "center",
+ width: 24,
+ animation: action.active
+ ? "spacePokeJab 2000ms ease-in-out"
+ : "none",
+ "@keyframes spacePokeJab": {
+ "0%, 100%": {
+ transform:
+ "translate(0, 0) rotate(0deg) scale(1)",
+ },
+ "27.5%, 52%, 73.75%": {
+ transform:
+ "translate(20px, -80px) rotate(-40deg) scale(3)",
+ },
+ "41%, 63%": {
+ transform:
+ "translate(36px, -94px) rotate(-40deg) scale(3)",
+ },
},
- },
- "@media (prefers-reduced-motion: reduce)": {
- animation: "none",
- },
- ...(action.icon == BubbleChatIcon && {
- "& svg path:last-of-type": {
- display: "none",
+ "@media (prefers-reduced-motion: reduce)": {
+ animation: "none",
},
- }),
- }}
- >
- <HugeiconsIcon
- icon={action.icon}
- size={24}
- strokeWidth={2.2}
- />
- </Box>
+ ...(action.icon == BubbleChatIcon && {
+ "& svg path:last-of-type": {
+ display: "none",
+ },
+ }),
+ }}
+ >
+ <HugeiconsIcon
+ icon={action.icon}
+ size={24}
+ strokeWidth={2.2}
+ />
+ </Box>
+ )}
</Box>
))}
</Box>
diff --git a/web/apps/space/src/components/FriendStarField.tsx b/web/apps/space/src/components/FriendStarField.tsx
new file mode 100644
index 0000000000..667a0353d6
--- /dev/null
+++ b/web/apps/space/src/components/FriendStarField.tsx
@@ -0,0 +1,71 @@
+import { Box } from "@mui/material";
+import type { CSSProperties } from "react";
+
+const stars = (() => {
+ let seed = 7319;
+ const random = () => {
+ seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
+ return seed / 4294967296;
+ };
+ return Array.from({ length: 64 }, () => {
+ const brightness = random() ** 2;
+ return {
+ x: 2 + random() * 96,
+ y: 2 + random() * 96,
+ size: 1.2 + brightness * 1.6,
+ low: 0.12 + brightness * 0.16,
+ high: 0.35 + brightness * 0.65,
+ duration: 4 + random() * 7,
+ delay: -random() * 20,
+ };
+ });
+})();
+
+export const FriendStarField = () => (
+ <Box
+ aria-hidden
+ sx={{
+ inset: 0,
+ overflow: "hidden",
+ pointerEvents: "none",
+ position: "absolute",
+ zIndex: -1,
+ "& > span": {
+ animation: "spaceStarTwinkle ease-in-out infinite",
+ bgcolor: "#FFFFFF",
+ borderRadius: "50%",
+ opacity: "var(--star-high)",
+ position: "absolute",
+ },
+ "@keyframes spaceStarTwinkle": {
+ "0%, 100%": { opacity: "var(--star-low)" },
+ "40%": { opacity: "var(--star-high)" },
+ },
+ "@media (prefers-reduced-motion: reduce)": {
+ "& > span": { animation: "none" },
+ },
+ }}
+ >
+ {stars.map((star, index) => (
+ <span
+ key={index}
+ style={
+ {
+ "--star-low": star.low,
+ "--star-high": star.high,
+ animationDelay: `${star.delay}s`,
+ animationDuration: `${star.duration}s`,
+ boxShadow:
+ star.high > 0.8
+ ? "0 0 4px 1px #ffffff30"
+ : undefined,
+ height: star.size,
+ left: `${star.x}%`,
+ top: `${star.y}%`,
+ width: star.size,
+ } as CSSProperties
+ }
+ />
+ ))}
+ </Box>
+);
diff --git a/web/apps/space/src/pages/app/friends/index.tsx b/web/apps/space/src/pages/app/friends/index.tsx
index f9df09d8a6..02f158e258 100644
--- a/web/apps/space/src/pages/app/friends/index.tsx
+++ b/web/apps/space/src/pages/app/friends/index.tsx
@@ -157,7 +157,7 @@ const Page: React.FC = () => {
username={profile.username}
onAcceptFriendRequest={async (requestID) => {
const actorSpaceId = profile.spaceId;
- if (!actorSpaceId) return;
+ if (!actorSpaceId) return false;
try {
await confirmCurrentFriendRequest(
actorSpaceId,
@@ -171,7 +171,7 @@ const Page: React.FC = () => {
),
);
setShowFriendRequestCanceledToast(true);
- return;
+ return false;
}
const loadedFriends =
await loadCurrentSpaceFriends(actorSpaceId);
@@ -181,6 +181,7 @@ const Page: React.FC = () => {
),
);
setFriends(loadedFriends);
+ return true;
}}
onDeleteFriendRequest={async (requestID) => {
const actorSpaceId = profile.spaceId;
diff --git a/web/apps/space/src/screens/FriendsScreen.tsx b/web/apps/space/src/screens/FriendsScreen.tsx
index b52923da2c..96660722b9 100644
--- a/web/apps/space/src/screens/FriendsScreen.tsx
+++ b/web/apps/space/src/screens/FriendsScreen.tsx
@@ -1,13 +1,12 @@
import {
+ Add01Icon,
ArrowLeft02Icon,
- Cancel01Icon,
UserAdd02Icon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Skeleton } from "@mui/material";
import {
spaceActionDoneDurationMs,
- SpaceActionFeedbackIcon,
type SpaceActionPhase,
} from "components/ActionFeedback";
import { SpaceAddFriendDialog } from "components/AddFriendDialog";
@@ -15,8 +14,8 @@ import { SpaceAvatarImage } from "components/AvatarImage";
import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";
import { FriendOrbit } from "components/FriendOrbit";
import { FriendQuickActionsDialog } from "components/FriendQuickActionsDialog";
+import { FriendStarField } from "components/FriendStarField";
import { SpaceLoadingSpinner } from "components/RouteFallback";
-import { SpaceShareInviteButton } from "components/ShareInviteButton";
import { SpaceSkipLink } from "components/SkipLink";
import type { FriendProfile } from "data/friends";
import log from "ente-base/log";
@@ -24,19 +23,15 @@ import React, { useState } from "react";
import type { SpaceFriendRequest } from "services/space";
import {
spaceAppBackground,
- spaceOnAccent,
spaceSurface,
spaceSurfaceHover,
spaceText,
- spaceTextMuted,
} from "styles/colors";
import { spaceTouchTargetSize } from "styles/touch-targets";
const green = "#08C225";
const avatarSkeletonBackground = spaceSurface;
const textBase = spaceText;
-const textStrong = spaceText;
-const textSoft = spaceTextMuted;
const friendAvatarLoadRootMargin = "800px 0px";
const friendAvatarCacheKey = (friend: FriendProfile) =>
@@ -53,7 +48,7 @@ interface FriendsScreenProps {
friends: FriendProfile[];
isLoading: boolean;
onBack: () => void;
- onAcceptFriendRequest: (requestID: number) => Promise<void>;
+ onAcceptFriendRequest: (requestID: number) => Promise<boolean>;
onDeleteFriendRequest: (requestID: number) => Promise<void>;
onLoadFriendAvatar?: (friend: FriendProfile) => Promise<string | null>;
onAddFriend: (username: string) => Promise<"friend" | "requested">;
@@ -70,19 +65,13 @@ interface FriendIdentityProps {
friend: FriendProfile;
onLoadAvatar?: () => Promise<string | null | undefined>;
onOpen?: (event: React.MouseEvent<HTMLButtonElement>) => void;
- floating?: boolean;
- primaryText?: string;
- secondaryText?: string;
}
const FriendIdentity: React.FC<FriendIdentityProps> = ({
avatarUrl,
friend,
- floating = false,
onLoadAvatar,
onOpen,
- primaryText,
- secondaryText = `@${friend.username}`,
}) => {
const displayName = friend.fullName.trim() || friend.username.trim();
const avatarRef = React.useRef<HTMLDivElement | null>(null);
@@ -128,28 +117,27 @@ const FriendIdentity: React.FC<FriendIdentityProps> = ({
return (
<Box
- component={onOpen ? "button" : "div"}
- type={onOpen ? "button" : undefined}
+ component="button"
+ type="button"
onClick={onOpen}
- aria-label={floating ? `Actions for ${displayName}` : undefined}
- aria-haspopup={floating ? "dialog" : undefined}
+ aria-label={`Actions for ${displayName}`}
+ aria-haspopup="dialog"
sx={{
alignItems: "center",
bgcolor: "transparent",
border: 0,
- borderRadius: floating ? "50%" : "12px",
- cursor: onOpen ? "pointer" : "default",
+ borderRadius: "50%",
+ cursor: "pointer",
display: "flex",
- flexDirection: floating ? "column" : "row",
- gap: floating ? "10px" : "12px",
+ flexDirection: "column",
maxWidth: "100%",
minWidth: 0,
p: 0,
- textAlign: floating ? "center" : "left",
- width: floating ? "100%" : "fit-content",
+ textAlign: "center",
+ width: "100%",
position: "relative",
transition: "scale 180ms ease",
- "&:hover": floating ? { scale: "1.06" } : undefined,
+ "&:hover": { scale: "1.06" },
"@media (prefers-reduced-motion: reduce)": {
transition: "none",
},
@@ -164,18 +152,16 @@ const FriendIdentity: React.FC<FriendIdentityProps> = ({
sx={{
alignItems: "center",
bgcolor: avatarSkeletonBackground,
- border: floating ? "1px solid #454545" : undefined,
+ border: "1px solid #454545",
borderRadius: "50%",
display: "flex",
flexShrink: 0,
- height: floating ? "auto" : 44,
+ height: "auto",
aspectRatio: "1",
justifyContent: "center",
overflow: "hidden",
- width: floating ? "100%" : 44,
- boxShadow: floating
- ? "0 8px 28px rgba(0, 0, 0, 0.2)"
- : undefined,
+ width: "100%",
+ boxShadow: "0 8px 28px rgba(0, 0, 0, 0.2)",
}}
>
{avatarUrl || !friend.avatarObjectID ? (
@@ -192,241 +178,79 @@ const FriendIdentity: React.FC<FriendIdentityProps> = ({
/>
)}
</Box>
- {!floating && (
- <Box
- sx={{
- display: "flex",
- flex: "0 1 auto",
- flexDirection: "column",
- justifyContent: "center",
- minWidth: 0,
- }}
- >
- <Box
- sx={{
- color: textStrong,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 700,
- lineHeight: "20px",
- minWidth: 0,
- overflow: "hidden",
- textOverflow: "ellipsis",
- whiteSpace: "nowrap",
- }}
- >
- {primaryText ?? displayName}
- </Box>
- <Box
- sx={{
- color: textSoft,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 500,
- lineHeight: "18px",
- minWidth: 0,
- overflow: "hidden",
- textOverflow: "ellipsis",
- whiteSpace: "nowrap",
- }}
- >
- {secondaryText}
- </Box>
- </Box>
- )}
</Box>
);
};
-interface FriendRequestRowProps {
- onAccept: (requestID: number) => Promise<void>;
- onDelete: (requestID: number) => Promise<void>;
+const orbitCircleSx = {
+ alignItems: "center",
+ bgcolor: spaceSurface,
+ border: "1px solid #454545",
+ borderRadius: "50%",
+ boxSizing: "border-box",
+ boxShadow: "0 8px 28px rgba(0, 0, 0, 0.2)",
+ color: textBase,
+ display: "flex",
+ flexDirection: "column",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ gap: "6px",
+ height: "100%",
+ justifyContent: "center",
+ p: "12px",
+ textAlign: "center",
+ width: "100%",
+ "&:focus-visible": { outline: `2px solid ${green}`, outlineOffset: 4 },
+} as const;
+
+interface FriendRequestCircleProps {
+ onOpen: (event: React.MouseEvent<HTMLButtonElement>) => void;
request: SpaceFriendRequest;
}
-const FriendRequestRow: React.FC<FriendRequestRowProps> = ({
- onAccept,
- onDelete,
+const FriendRequestCircle: React.FC<FriendRequestCircleProps> = ({
+ onOpen,
request,
-}) => {
- const [action, setAction] = React.useState<"accept" | "delete" | null>(
- null,
- );
- const isReceived = request.direction == "received";
- const isBusy = action != null;
- const displayName =
- request.friend.fullName.trim() || request.friend.username.trim();
- const runAction = (
- nextAction: "accept" | "delete",
- handler: (requestID: number) => Promise<void>,
- ) => {
- if (isBusy) return;
- setAction(nextAction);
- void handler(request.requestId)
- .catch((error: unknown) =>
- log.error("Failed to update friend request", error),
- )
- .finally(() => setAction(null));
- };
-
- return (
+}) => (
+ <Box
+ className={request.direction == "received" ? "green-bg" : undefined}
+ component="button"
+ type="button"
+ aria-label={`${request.direction == "received" ? "Friend request from" : "Pending friend request to"} @${request.friend.username}`}
+ aria-haspopup="dialog"
+ onClick={onOpen}
+ sx={{
+ ...orbitCircleSx,
+ bgcolor: request.direction == "received" ? green : "#444444",
+ borderColor:
+ request.direction == "received"
+ ? "color(display-p3 0.32 0.88 0.4)"
+ : "#737373",
+ boxShadow:
+ request.direction == "received"
+ ? "0 0 18px rgba(8, 194, 37, 0.18)"
+ : orbitCircleSx.boxShadow,
+ transition: "scale 180ms ease",
+ "&:hover": { scale: "1.06" },
+ "@media (prefers-reduced-motion: reduce)": { transition: "none" },
+ }}
+ >
<Box
- component="li"
+ component="span"
+ title={`@${request.friend.username}`}
sx={{
- alignItems: "center",
- display: "grid",
- gap: "8px",
- gridTemplateColumns: "minmax(0, 1fr) auto",
- listStyle: "none",
- minHeight: 72,
- px: "18px",
- py: "12px",
- width: "100%",
+ fontSize: 14,
+ fontWeight: 600,
+ lineHeight: "18px",
+ maxWidth: "100%",
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
}}
>
- <FriendIdentity
- friend={request.friend}
- primaryText={`@${request.friend.username}`}
- secondaryText={
- isReceived ? "Sent you a friend request" : "Request sent"
- }
- />
- <Box
- sx={{
- alignItems: "center",
- display: "flex",
- flexShrink: 0,
- gap: "6px",
- }}
- >
- {isReceived ? (
- <>
- <Box
- className="green-bg"
- component="button"
- type="button"
- disabled={isBusy}
- onClick={() => runAction("accept", onAccept)}
- sx={{
- alignItems: "center",
- bgcolor: green,
- border: 0,
- borderRadius: "12px",
- color: spaceOnAccent,
- cursor: isBusy ? "default" : "pointer",
- display: "flex",
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 12,
- fontWeight: 700,
- height: 34,
- justifyContent: "center",
- minWidth: 64,
- px: "12px",
- "&:disabled": { opacity: 0.6 },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": isBusy
- ? undefined
- : { bgcolor: "#07A820" },
- }}
- >
- {action == "accept" ? (
- <SpaceActionFeedbackIcon
- phase="busy"
- size={16}
- />
- ) : (
- "Accept"
- )}
- </Box>
- <Box
- component="button"
- type="button"
- aria-label={`Decline friend request from ${displayName}`}
- disabled={isBusy}
- onClick={() => runAction("delete", onDelete)}
- sx={{
- alignItems: "center",
- bgcolor: "transparent",
- border: 0,
- borderRadius: "50%",
- color: textBase,
- cursor: isBusy ? "default" : "pointer",
- display: "flex",
- height: 34,
- justifyContent: "center",
- p: 0,
- width: 34,
- "&:disabled": { opacity: 0.45 },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": isBusy
- ? undefined
- : { bgcolor: spaceSurfaceHover },
- }}
- >
- {action == "delete" ? (
- <SpaceActionFeedbackIcon
- phase="busy"
- size={18}
- />
- ) : (
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={18}
- strokeWidth={2}
- />
- )}
- </Box>
- </>
- ) : (
- <Box
- component="button"
- type="button"
- aria-label={`Cancel friend request to ${displayName}`}
- disabled={isBusy}
- onClick={() => runAction("delete", onDelete)}
- sx={{
- alignItems: "center",
- bgcolor: spaceSurface,
- border: 0,
- borderRadius: "12px",
- color: textBase,
- cursor: isBusy ? "default" : "pointer",
- display: "flex",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 12,
- fontWeight: 700,
- height: 34,
- justifyContent: "center",
- minWidth: 64,
- px: "12px",
- "&:disabled": { opacity: 0.6 },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": isBusy
- ? undefined
- : { bgcolor: spaceSurfaceHover },
- }}
- >
- {action == "delete" ? (
- <SpaceActionFeedbackIcon phase="busy" size={16} />
- ) : (
- "Cancel"
- )}
- </Box>
- )}
- </Box>
+ @{request.friend.username}
</Box>
- );
-};
+ </Box>
+);
export const FriendsScreen: React.FC<FriendsScreenProps> = ({
friendRequests,
@@ -449,6 +273,10 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
friend: FriendProfile;
anchorRect: DOMRect;
} | null>(null);
+ const [selectedRequest, setSelectedRequest] = React.useState<{
+ request: SpaceFriendRequest;
+ anchorRect: DOMRect;
+ } | null>(null);
const pokeRequestIDs = React.useRef(new Map<string, string>());
const [friendToUnfriend, setFriendToUnfriend] =
React.useState<FriendProfile | null>(null);
@@ -461,7 +289,6 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
const [loadedAvatarURLsByKey, setLoadedAvatarURLsByKey] = React.useState<
Record<string, string>
>({});
- const [isInviteSharing, setIsInviteSharing] = React.useState(false);
const avatarLoadsInFlightRef = React.useRef<
Map<string, Promise<string | null | undefined>>
>(new Map());
@@ -555,11 +382,14 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
color: textBase,
display: "grid",
boxSizing: "border-box",
+ isolation: "isolate",
minHeight: "var(--space-page-height, 100svh)",
overflowX: "hidden",
placeItems: { xs: "stretch", sm: "start center" },
+ position: "relative",
}}
>
+ <FriendStarField />
<SpaceSkipLink />
<Box
sx={{
@@ -617,6 +447,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
<Box
component="h1"
sx={{
+ bgcolor: spaceAppBackground,
color: textBase,
fontFamily: '"Inter Variable", Inter, sans-serif',
fontSize: 18,
@@ -624,6 +455,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
justifySelf: "center",
lineHeight: "24px",
m: 0,
+ px: "4px",
}}
>
Friends
@@ -690,14 +522,14 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
>
<SpaceLoadingSpinner ariaLabel="Loading friends" />
</Box>
- ) : friends.length > 0 || friendRequests.length > 0 ? (
- <>
- {friends.length > 0 && (
- <FriendOrbit
- friends={friends}
- renderFriend={(friend) => (
+ ) : (
+ <FriendOrbit
+ initialOuterID="add-friend"
+ items={[
+ ...friends.map((friend) => ({
+ id: friend.id,
+ content: (
<FriendIdentity
- floating
avatarUrl={loadedAvatarURLFor(
friend,
)}
@@ -713,82 +545,81 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
})
}
/>
- )}
- />
- )}
- {friendRequests.length > 0 && (
- <Box
- sx={{
- maxWidth: 390,
- mx: "auto",
- py: "24px",
- }}
- >
- <Box
- component="h2"
- sx={{
- fontSize: 14,
- fontWeight: 600,
- m: 0,
- px: "18px",
- pb: "8px",
- }}
- >
- Friend requests
- </Box>
- <Box component="ul" sx={{ m: 0, p: 0 }}>
- {friendRequests.map((request) => (
- <FriendRequestRow
- key={request.requestId}
- request={request}
- onAccept={onAcceptFriendRequest}
- onDelete={onDeleteFriendRequest}
+ ),
+ })),
+ ...friendRequests.map((request) => ({
+ id: request.friend.id,
+ fixedSize: 120,
+ content: (
+ <FriendRequestCircle
+ request={request}
+ onOpen={(event) =>
+ setSelectedRequest({
+ request,
+ anchorRect:
+ event.currentTarget.getBoundingClientRect(),
+ })
+ }
+ />
+ ),
+ })),
+ {
+ id: "add-friend",
+ fixedSize: 64,
+ content: (
+ <Box
+ component="button"
+ type="button"
+ aria-label="Add friend"
+ aria-haspopup="dialog"
+ aria-expanded={isAddFriendOpen}
+ onClick={() =>
+ setIsAddFriendOpen(true)
+ }
+ sx={{
+ ...orbitCircleSx,
+ transition: "scale 180ms ease",
+ "&:hover": {
+ bgcolor: spaceSurfaceHover,
+ scale: "1.06",
+ },
+ "@media (prefers-reduced-motion: reduce)":
+ { transition: "none" },
+ }}
+ >
+ <HugeiconsIcon
+ icon={Add01Icon}
+ size={28}
+ strokeWidth={1.8}
/>
- ))}
- </Box>
- </Box>
- )}
- </>
- ) : (
- <Box
- sx={{
- alignItems: "center",
- color: textSoft,
- display: "flex",
- flexDirection: "column",
- gap: "22px",
- inset: 0,
- justifyContent: "center",
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
- lineHeight: "20px",
- pointerEvents: "none",
- position: "absolute",
- px: "24px",
- textAlign: "center",
- }}
- >
- <Box component="p" sx={{ m: 0, maxWidth: 260 }}>
- Invite your friends and family. Share everyday
- photos and keep up with each other.
- </Box>
- <SpaceShareInviteButton
- profileLink={profileLink}
- sharing={isInviteSharing}
- onShareError={(error) =>
- log.error(
- "Failed to share Space invite link",
- error,
- )
- }
- onSharingChange={setIsInviteSharing}
- />
- </Box>
+ </Box>
+ ),
+ },
+ ]}
+ />
)}
</Box>
</Box>
+ {selectedRequest && (
+ <FriendQuickActionsDialog
+ anchorRect={selectedRequest.anchorRect}
+ friend={selectedRequest.request.friend}
+ onClose={() => setSelectedRequest(null)}
+ requestActions={{
+ onAccept:
+ selectedRequest.request.direction == "received"
+ ? () =>
+ onAcceptFriendRequest(
+ selectedRequest.request.requestId,
+ )
+ : undefined,
+ onCancel: () =>
+ onDeleteFriendRequest(
+ selectedRequest.request.requestId,
+ ),
+ }}
+ />
+ )}
{selectedFriend && (
<FriendQuickActionsDialog
anchorRect={selectedFriend.anchorRect}
diff --git a/web/apps/space/src/utils/friend-orbit.ts b/web/apps/space/src/utils/friend-orbit.ts
index 0f4717c395..deefe67df9 100644
--- a/web/apps/space/src/utils/friend-orbit.ts
+++ b/web/apps/space/src/utils/friend-orbit.ts
@@ -85,11 +85,7 @@ export const stepFriendOrbit = (
circle.y += circle.vy * frame;
});
- for (
- let pass = 0;
- pass < Math.max(7, Math.ceil(circles.length / 2));
- pass++
- ) {
+ for (let pass = 0; pass < 7; pass++) {
for (let i = 0; i < circles.length; i++) {
const first = circles[i]!;
for (let j = i + 1; j < circles.length; j++) {
@@ -143,13 +139,23 @@ export const arrangeFriendOrbit = (
circles: FriendOrbitCircle[],
bounds: FriendOrbitBounds,
elapsed: number,
+ initialOuterID?: string,
) => {
circles.forEach((circle, index) => {
const initial = createFriendOrbitCircle(circle.id, index);
Object.assign(circle, initial, { size: circle.size });
});
+ const group = circles.filter((circle) => circle.id != initialOuterID);
for (let frame = 0; frame < 90; frame++) {
- stepFriendOrbit(circles, bounds, 0, 16.667, undefined, true);
+ stepFriendOrbit(group, bounds, 0, 16.667, undefined, true);
+ }
+ const outer = circles.find((circle) => circle.id == initialOuterID);
+ if (outer && group.length) {
+ const neighbor = group.reduce((top, circle) =>
+ circle.y - circle.size / 2 < top.y - top.size / 2 ? circle : top,
+ );
+ outer.x = neighbor.x;
+ outer.y = neighbor.y - (neighbor.size + outer.size) / 2 - 10;
}
const angle = friendOrbitAngle(elapsed);
circles.forEach((circle) => {
diff --git a/web/apps/space/tests/friend-orbit.test.ts b/web/apps/space/tests/friend-orbit.test.ts
index fe0027ba74..5f3f88fcac 100644
--- a/web/apps/space/tests/friend-orbit.test.ts
+++ b/web/apps/space/tests/friend-orbit.test.ts
@@ -30,6 +30,7 @@ describe("friend orbit", () => {
[390, 728, 0.84, 3],
[390, 728, 0.84, 9],
[320, 452, 0.84, 9],
+ [390, 728, 0.84, 30],
[390, 728, 0.84, 36],
] as const) {
it(`keeps ${count} friends separated and in bounds at ${width}px`, () => {