Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine Space home circle labels

Anand Baburajan5c48140eae4b
diff --git a/web/apps/space/src/components/CircleNameArc.tsx b/web/apps/space/src/components/CircleNameArc.tsx
new file mode 100644
index 0000000000..273b8cc8d6
--- /dev/null
+++ b/web/apps/space/src/components/CircleNameArc.tsx
@@ -0,0 +1,110 @@
+import React from "react";
+
+export type SpaceCircleNameArcPosition = "upper-left" | "top" | "upper-right";
+
+interface SpaceCircleNameArcProps {
+ id: string;
+ name: string;
+ position: SpaceCircleNameArcPosition;
+ ringColor: string;
+ ringWidth: number;
+ size: number;
+}
+
+export const SpaceCircleNameArc: React.FC<SpaceCircleNameArcProps> = ({
+ id,
+ name,
+ position,
+ ringColor,
+ ringWidth,
+ size,
+}) => {
+ const center = size / 2;
+ const fontSize = Math.max(8, Math.min(11, size * 0.065));
+ const radius = center - fontSize * 0.2;
+ const arcCenterAngle =
+ position == "upper-left"
+ ? (Math.PI * 5) / 4
+ : position == "upper-right"
+ ? (Math.PI * 7) / 4
+ : (Math.PI * 3) / 2;
+ const arcStartAngle = arcCenterAngle - Math.PI / 4;
+ const arcEndAngle = arcCenterAngle + Math.PI / 4;
+ const path = `M ${center + radius * Math.cos(arcStartAngle)} ${center + radius * Math.sin(arcStartAngle)} A ${radius} ${radius} 0 0 1 ${center + radius * Math.cos(arcEndAngle)} ${center + radius * Math.sin(arcEndAngle)}`;
+ const uppercaseName = name.toLocaleUpperCase();
+ const arcLength = (Math.PI * radius) / 2;
+ const labelWidth = Math.min(
+ arcLength - fontSize,
+ uppercaseName.length * fontSize * 0.68 + fontSize * 0.4,
+ );
+ const halfGapAngle = labelWidth / (2 * radius);
+ const gapStartAngle = arcCenterAngle - halfGapAngle;
+ const gapEndAngle = arcCenterAngle + halfGapAngle;
+ const gapPath = `M ${center + radius * Math.cos(gapStartAngle)} ${center + radius * Math.sin(gapStartAngle)} A ${radius} ${radius} 0 0 1 ${center + radius * Math.cos(gapEndAngle)} ${center + radius * Math.sin(gapEndAngle)}`;
+ const ringMaskID = `${id}-ring-mask`;
+
+ return (
+ <svg
+ aria-hidden
+ focusable="false"
+ viewBox={`0 0 ${size} ${size}`}
+ style={{
+ height: "100%",
+ inset: 0,
+ overflow: "visible",
+ pointerEvents: "none",
+ position: "absolute",
+ width: "100%",
+ zIndex: 2,
+ }}
+ >
+ <defs>
+ <path id={id} d={path} />
+ <mask
+ id={ringMaskID}
+ maskContentUnits="userSpaceOnUse"
+ maskUnits="userSpaceOnUse"
+ x={-size}
+ y={-size}
+ width={size * 3}
+ height={size * 3}
+ >
+ <rect
+ x={-size}
+ y={-size}
+ width={size * 3}
+ height={size * 3}
+ fill="#FFF"
+ />
+ <path
+ d={gapPath}
+ fill="none"
+ stroke="#000"
+ strokeLinecap="round"
+ strokeWidth={fontSize + 4}
+ />
+ </mask>
+ </defs>
+ <circle
+ cx={center}
+ cy={center}
+ r={center - ringWidth / 2}
+ fill="none"
+ mask={`url(#${ringMaskID})`}
+ stroke={ringColor}
+ strokeWidth={ringWidth}
+ />
+ <text
+ fill="rgba(255, 255, 255, 0.86)"
+ fontFamily='"Nunito", sans-serif'
+ fontSize={fontSize}
+ fontWeight={800}
+ letterSpacing="0.04em"
+ >
+ <textPath href={`#${id}`} startOffset="50%" textAnchor="middle">
+ {uppercaseName}
+ </textPath>
+ </text>
+ </svg>
+ );
+};
diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsx
index 12c27360d3..3b23b49825 100644
--- a/web/apps/space/src/pages/layout-demo.tsx
+++ b/web/apps/space/src/pages/layout-demo.tsx
@@ -1,6 +1,7 @@
import { ArrowLeft02Icon, ArrowRight01Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
+import { SpaceCircleNameArc } from "components/CircleNameArc";
import { SpacePostFloatingActionButton } from "components/PostFloatingActionButton";
import React from "react";
import { homeCirclePlacements } from "utils/home-circle-layout";
@@ -11,6 +12,23 @@ const headerHeight = 64;
const layoutVerticalInset =
"calc(112px + max(env(safe-area-inset-top, 0px), env(safe-area-inset-bottom, 0px)))";
const maximumFriendCount = 15;
+const sampleNames = [
+ "Maya",
+ "Noah",
+ "Ari",
+ "Zoya",
+ "Leo",
+ "Mina",
+ "Ira",
+ "Omar",
+ "Nina",
+ "Theo",
+ "Rhea",
+ "Eli",
+ "Lina",
+ "Jai",
+ "Ada",
+];
interface CanvasSize {
height: number;
@@ -59,9 +77,7 @@ const LayoutDemoPage: React.FC = () => {
canvasSize.height,
);
const circleSize = placements[0]?.size ?? 0;
- const avatarSize = Math.min(32, circleSize * 0.2);
const ringWidth = Math.max(1, Math.min(3, circleSize * 0.018));
- const avatarSeparation = Math.max(1, Math.min(4, circleSize * 0.025));
return (
<Box
@@ -202,10 +218,6 @@ const LayoutDemoPage: React.FC = () => {
<Box
key={index}
sx={{
- bgcolor: "#1A211F",
- border: `${ringWidth}px solid #2A3430`,
- borderRadius: "50%",
- boxSizing: "border-box",
height: size,
left: x,
position: "absolute",
@@ -215,17 +227,35 @@ const LayoutDemoPage: React.FC = () => {
>
<Box
sx={{
- bgcolor: "#39433F",
+ bgcolor: "#1A211F",
+ border: 0,
borderRadius: "50%",
- boxShadow: `0 0 0 ${avatarSeparation}px ${background}`,
- height: avatarSize,
- left: "14.645%",
- position: "absolute",
- top: "14.645%",
- transform: "translate(-50%, -50%)",
- width: avatarSize,
+ boxSizing: "border-box",
+ height: "100%",
+ position: "relative",
+ width: "100%",
+ zIndex: 1,
}}
/>
+ <SpaceCircleNameArc
+ id={`layout-name-arc-${index}`}
+ name={sampleNames[index]!}
+ position={
+ Math.abs(
+ x +
+ size / 2 -
+ canvasSize.width / 2,
+ ) < 1
+ ? "top"
+ : x + size / 2 <
+ canvasSize.width / 2
+ ? "upper-left"
+ : "upper-right"
+ }
+ ringColor="#2A3430"
+ ringWidth={ringWidth}
+ size={size}
+ />
</Box>
))}
</Box>
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 4fd82c4416..06aef87ae0 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -6,6 +6,10 @@ import {
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Skeleton } from "@mui/material";
import { SpaceAvatarImage } from "components/AvatarImage";
+import {
+ SpaceCircleNameArc,
+ type SpaceCircleNameArcPosition,
+} from "components/CircleNameArc";
import {
SpaceFileViewer,
SpaceViewerFeedBackdrop,
@@ -219,6 +223,7 @@ interface FriendPostCircleProps {
isUnavailable: boolean;
onLoadAvatar?: () => Promise<string | null | undefined>;
onLoadImage?: () => Promise<string | undefined>;
+ nameArcPosition: SpaceCircleNameArcPosition;
onOpenFriend?: (friendID: string, username?: string) => void;
onOpenPhoto: (photo: SpaceViewerPhoto) => void;
placement: HomeCirclePlacement;
@@ -232,6 +237,7 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
isAvatarPending,
isLoading,
isUnavailable,
+ nameArcPosition,
onLoadAvatar,
onLoadImage,
onOpenFriend,
@@ -239,6 +245,7 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
placement,
post,
}) => {
+ const nameArcID = React.useId();
const rootRef = React.useRef<HTMLLIElement | null>(null);
const [shouldLoadMedia, setShouldLoadMedia] = useState(Boolean(imageUrl));
const decodedPhoto = useDecodedImage(imageUrl, true);
@@ -270,12 +277,8 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
const canOpenPost = Boolean(post) && !postUnavailable && isPhotoReady;
const isCircleDisabled =
isLoading || Boolean(post && !postUnavailable && !isPhotoReady);
- const avatarSize = Math.min(32, placement.size * 0.2);
- const cutoutGap = Math.max(1, Math.min(3, placement.size * 0.02));
- const cutoutRadius = avatarSize / 2 + cutoutGap;
const circleBorderWidth = Math.max(1, Math.min(3, placement.size * 0.018));
const circlePadding = Math.max(1.5, Math.min(4, placement.size * 0.025));
- const avatarCutoutMask = `radial-gradient(circle at 14.645% 14.645%, transparent ${cutoutRadius}px, #000 ${cutoutRadius + 0.5}px)`;
React.useEffect(() => {
if (isLoading || !post || postUnavailable || shouldLoadMedia) return;
@@ -361,15 +364,14 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
<Box
sx={{
aspectRatio: "1",
- border: `${circleBorderWidth}px solid ${inactivePostCircleBorderColor}`,
+ border: 0,
borderRadius: "50%",
boxSizing: "border-box",
height: "100%",
- maskImage: avatarCutoutMask,
- p: `${circlePadding}px`,
+ p: `${circleBorderWidth + circlePadding}px`,
position: "relative",
- WebkitMaskImage: avatarCutoutMask,
width: "100%",
+ zIndex: 1,
}}
>
<Box
@@ -401,10 +403,6 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
p: 0,
position: "relative",
width: "100%",
- "&:focus-visible": {
- outline: `3px solid ${green}`,
- outlineOffset: 3,
- },
}}
>
{isLoading ? (
@@ -482,29 +480,14 @@ const FriendPostCircle: React.FC<FriendPostCircleProps> = ({
)}
</Box>
</Box>
- <Box
- aria-hidden
- sx={{
- aspectRatio: "1",
- border: 0,
- borderRadius: "50%",
- boxSizing: "border-box",
- left: "14.645%",
- overflow: "hidden",
- pointerEvents: "none",
- position: "absolute",
- top: "14.645%",
- transform: "translate(-50%, -50%)",
- width: avatarSize,
- zIndex: 2,
- }}
- >
- <SpaceAvatarImage
- aria-hidden
- borderRadius="50%"
- src={displayAvatarUrl}
- />
- </Box>
+ <SpaceCircleNameArc
+ id={nameArcID}
+ name={firstName}
+ position={nameArcPosition}
+ ringColor={inactivePostCircleBorderColor}
+ ringWidth={circleBorderWidth}
+ size={placement.size}
+ />
</Box>
);
};
@@ -837,6 +820,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
[loadedPostAvatarURLFor, onLoadPostAvatar],
);
const friendPostCircleFor = (friend: FriendProfile, index: number) => {
+ const placement = postCirclePlacements[index]!;
const item = latestPostByFriendID.get(friend.spaceId ?? friend.id);
const imageUrl = item ? loadedPostImageURLFor(item) : undefined;
const avatarUrl = item ? loadedPostAvatarURLFor(item) : null;
@@ -857,6 +841,18 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
isAvatarPending={isAvatarPending}
isLoading={isFriendsLoading || isLatestPostsLoading}
isUnavailable={isUnavailable}
+ nameArcPosition={
+ Math.abs(
+ placement.x +
+ placement.size / 2 -
+ postCircleCanvasSize.width / 2,
+ ) < 1
+ ? "top"
+ : placement.x + placement.size / 2 <
+ postCircleCanvasSize.width / 2
+ ? "upper-left"
+ : "upper-right"
+ }
onLoadAvatar={
item && isAvatarPending
? () => loadPostAvatar(item)
@@ -869,7 +865,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
}
onOpenFriend={onOpenFriend}
onOpenPhoto={openPostPhoto}
- placement={postCirclePlacements[index]!}
+ placement={placement}
post={item}
/>
);