Skip to content

armgit / ente

Public Imported from GitHub
0

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

Improve Space friend invitations and avatar contrast

Anand Baburajan528bf032f714
diff --git a/web/apps/space/src/components/AddFriendDialog.tsx b/web/apps/space/src/components/AddFriendDialog.tsx
new file mode 100644
index 0000000000..72d9a88649
--- /dev/null
+++ b/web/apps/space/src/components/AddFriendDialog.tsx
@@ -0,0 +1,391 @@
+import { Box, Dialog, useMediaQuery } from "@mui/material";
+import {
+ SpaceActionFeedbackIcon,
+ spaceActionDoneDurationMs,
+} from "components/ActionFeedback";
+import { SpaceBottomSheetTransition } from "components/BottomSheetTransition";
+import { SpaceShareInviteButton } from "components/ShareInviteButton";
+import type { FriendProfile } from "data/friends";
+import log from "ente-base/log";
+import React from "react";
+import {
+ normalizeSpaceUsername,
+ spaceUsernameValidationError,
+} from "services/profile";
+import type { SpaceFriendRequest } from "services/space";
+import {
+ spaceOnAccent,
+ spaceSurface,
+ spaceText,
+ spaceTextMuted,
+} from "styles/colors";
+import {
+ friendRequestErrorMessage,
+ isSpaceFriendLimitError,
+} from "utils/friend-errors";
+import {
+ maximumSpaceFriendCount,
+ spaceFriendLimitMessage,
+} from "utils/friend-limits";
+
+const green = "#08C225";
+const dangerColor = "#F63A3A";
+
+interface SpaceAddFriendDialogProps {
+ friendRequests: SpaceFriendRequest[];
+ friends: FriendProfile[];
+ onAddFriend: (username: string) => Promise<"friend" | "requested">;
+ onClose: () => void;
+ open: boolean;
+ profileLink?: string;
+ username: string;
+}
+
+export const SpaceAddFriendDialog: React.FC<SpaceAddFriendDialogProps> = ({
+ friendRequests,
+ friends,
+ onAddFriend,
+ onClose,
+ open,
+ profileLink,
+ username: currentUsername,
+}) => {
+ const titleID = React.useId();
+ const isBottomSheet = useMediaQuery("(max-width: 599px)");
+ const [username, setUsername] = React.useState("");
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
+ const [isSent, setIsSent] = React.useState(false);
+ const [errorMessage, setErrorMessage] = React.useState<string>();
+ const [isSharing, setIsSharing] = React.useState(false);
+ const [shareErrorMessage, setShareErrorMessage] = React.useState<string>();
+
+ const submit = () => {
+ if (isSubmitting || isSent) return;
+
+ const normalizedUsername = normalizeSpaceUsername(username);
+ const validationError = normalizedUsername
+ ? spaceUsernameValidationError(normalizedUsername)
+ : "Enter a username.";
+ if (validationError) {
+ setErrorMessage(validationError);
+ return;
+ }
+ if (normalizedUsername == normalizeSpaceUsername(currentUsername)) {
+ setErrorMessage("You can't add yourself as a friend.");
+ return;
+ }
+ if (
+ friends.some(
+ (friend) =>
+ normalizeSpaceUsername(friend.username) ==
+ normalizedUsername,
+ )
+ ) {
+ setErrorMessage(
+ `You're already friends with @${normalizedUsername}.`,
+ );
+ return;
+ }
+ if (
+ friendRequests.some(
+ (request) =>
+ request.direction == "sent" &&
+ normalizeSpaceUsername(request.friend.username) ==
+ normalizedUsername,
+ )
+ ) {
+ setErrorMessage(
+ `Friend request already sent to @${normalizedUsername}.`,
+ );
+ return;
+ }
+ const sentRequestCount = friendRequests.filter(
+ (request) => request.direction == "sent",
+ ).length;
+ if (friends.length + sentRequestCount >= maximumSpaceFriendCount) {
+ setErrorMessage(spaceFriendLimitMessage);
+ return;
+ }
+
+ setErrorMessage(undefined);
+ setIsSubmitting(true);
+ void onAddFriend(normalizedUsername)
+ .then(() => setIsSent(true))
+ .catch((error: unknown) => {
+ if (!isSpaceFriendLimitError(error)) {
+ log.error("Failed to send space friend request", error);
+ }
+ setErrorMessage(
+ friendRequestErrorMessage(error, normalizedUsername),
+ );
+ })
+ .finally(() => setIsSubmitting(false));
+ };
+
+ React.useEffect(() => {
+ if (!open || !isSent) return;
+
+ const timeoutID = window.setTimeout(onClose, spaceActionDoneDurationMs);
+ return () => window.clearTimeout(timeoutID);
+ }, [isSent, onClose, open]);
+
+ return (
+ <Dialog
+ open={open}
+ onClose={isSubmitting ? undefined : onClose}
+ maxWidth={false}
+ aria-labelledby={titleID}
+ slots={
+ isBottomSheet
+ ? { transition: SpaceBottomSheetTransition }
+ : undefined
+ }
+ slotProps={{
+ paper: {
+ sx: {
+ borderRadius: "28px 28px 0 0",
+ bottom: 0,
+ boxShadow: "none",
+ boxSizing: "border-box",
+ left: 0,
+ m: 0,
+ maxWidth: "none",
+ p: "26px 20px 24px",
+ position: "fixed",
+ width: "100vw",
+ "@media (min-width: 600px)": {
+ borderRadius: "20px",
+ bottom: "auto",
+ left: "50%",
+ maxWidth: 363,
+ top: "50%",
+ transform: "translate(-50%, -50%)",
+ width: 363,
+ },
+ },
+ },
+ transition: {
+ onExited: () => {
+ setUsername("");
+ setIsSent(false);
+ setErrorMessage(undefined);
+ setShareErrorMessage(undefined);
+ },
+ },
+ }}
+ >
+ <Box
+ component="form"
+ noValidate
+ onSubmit={(event) => {
+ event.preventDefault();
+ submit();
+ }}
+ sx={{
+ maxWidth: 320,
+ mx: "auto",
+ width: "100%",
+ "@media (min-width: 600px)": { maxWidth: "none" },
+ }}
+ >
+ <Box
+ component="h2"
+ id={titleID}
+ sx={{
+ color: spaceText,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 15,
+ fontWeight: 600,
+ lineHeight: "20px",
+ m: 0,
+ px: "20px",
+ textAlign: "center",
+ }}
+ >
+ Add a friend
+ </Box>
+ <Box
+ sx={{
+ color: spaceTextMuted,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ lineHeight: "18px",
+ mt: "8px",
+ textAlign: "center",
+ }}
+ >
+ Enter your friend&apos;s username to add them on Space
+ </Box>
+ <Box
+ component="label"
+ sx={{ display: "block", mt: "20px", width: "100%" }}
+ >
+ <Box
+ sx={{
+ alignItems: "center",
+ bgcolor: spaceSurface,
+ border: `1px solid ${errorMessage ? dangerColor : "transparent"}`,
+ borderRadius: "14px",
+ display: "flex",
+ height: 48,
+ px: "14px",
+ width: "100%",
+ "&:focus-within": {
+ borderColor: green,
+ boxShadow: `0 0 0 1px ${green}`,
+ },
+ }}
+ >
+ <Box
+ component="span"
+ aria-hidden
+ sx={{
+ color: spaceTextMuted,
+ flexShrink: 0,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 600,
+ }}
+ >
+ @
+ </Box>
+ <Box
+ component="input"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect="off"
+ autoFocus
+ aria-label="Friend's username"
+ aria-invalid={Boolean(errorMessage) || undefined}
+ disabled={isSubmitting || isSent}
+ onChange={(
+ event: React.ChangeEvent<HTMLInputElement>,
+ ) => {
+ const value = event.target.value;
+ setUsername(
+ value.startsWith("@")
+ ? value.slice(1)
+ : value,
+ );
+ setErrorMessage(undefined);
+ }}
+ placeholder="username"
+ spellCheck={false}
+ value={username}
+ sx={{
+ bgcolor: "transparent",
+ border: 0,
+ color: spaceText,
+ flex: 1,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 500,
+ height: "100%",
+ minWidth: 0,
+ outline: 0,
+ p: 0,
+ "&::placeholder": {
+ color: spaceTextMuted,
+ opacity: 1,
+ },
+ }}
+ />
+ </Box>
+ </Box>
+ {errorMessage && (
+ <Box
+ role="alert"
+ sx={{
+ color: dangerColor,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 600,
+ lineHeight: "18px",
+ mt: "8px",
+ textAlign: "center",
+ }}
+ >
+ {errorMessage}
+ </Box>
+ )}
+ <Box
+ className="green-bg"
+ component="button"
+ type="submit"
+ disabled={isSubmitting || isSent}
+ sx={{
+ alignItems: "center",
+ bgcolor: green,
+ border: 0,
+ borderRadius: "20px",
+ color: spaceOnAccent,
+ cursor: isSubmitting || isSent ? "default" : "pointer",
+ display: "flex",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 600,
+ height: 48,
+ justifyContent: "center",
+ lineHeight: "20px",
+ mt: "20px",
+ px: "24px",
+ width: "100%",
+ "&:disabled": { opacity: isSent ? 1 : 0.6 },
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ }}
+ >
+ {isSubmitting ? (
+ <SpaceActionFeedbackIcon phase="busy" />
+ ) : isSent ? (
+ <SpaceActionFeedbackIcon phase="done" />
+ ) : (
+ "Send request"
+ )}
+ </Box>
+ {profileLink && (
+ <Box sx={{ mt: "12px", textAlign: "center" }}>
+ <SpaceShareInviteButton
+ disabled={isSubmitting || isSent}
+ profileLink={profileLink}
+ sharing={isSharing}
+ variant="text"
+ onSharingChange={(sharing) => {
+ setIsSharing(sharing);
+ if (sharing) setShareErrorMessage(undefined);
+ }}
+ onShareError={(error) => {
+ log.error(
+ "Failed to share Space invite link",
+ error,
+ );
+ setShareErrorMessage(
+ "Couldn't share the invite link. Please try again.",
+ );
+ }}
+ />
+ {shareErrorMessage && (
+ <Box
+ role="alert"
+ sx={{
+ color: dangerColor,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 600,
+ lineHeight: "18px",
+ }}
+ >
+ {shareErrorMessage}
+ </Box>
+ )}
+ </Box>
+ )}
+ </Box>
+ </Dialog>
+ );
+};
diff --git a/web/apps/space/src/components/AddFriendTile.tsx b/web/apps/space/src/components/AddFriendTile.tsx
index 186c7813cd..9b14b3da35 100644
--- a/web/apps/space/src/components/AddFriendTile.tsx
+++ b/web/apps/space/src/components/AddFriendTile.tsx
@@ -1,9 +1,8 @@
import { UserAdd02Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
-import { SpaceShareInviteButton } from "components/ShareInviteButton";
-import log from "ente-base/log";
import React from "react";
+import { spaceEmptyStateButtonSx } from "styles/buttons";
import {
spaceSurface,
spaceSurfaceHover,
@@ -19,18 +18,14 @@ import type {
interface SpaceAddFriendTileProps {
onClick: () => void;
placement: HomeTilePlacement;
- profileLink?: string;
variant: AddFriendTileVariant;
}
export const SpaceAddFriendTile: React.FC<SpaceAddFriendTileProps> = ({
onClick,
placement,
- profileLink,
variant,
}) => {
- const [isSharing, setIsSharing] = React.useState(false);
-
return (
<Box
component="li"
@@ -102,17 +97,20 @@ export const SpaceAddFriendTile: React.FC<SpaceAddFriendTileProps> = ({
Space.
</Box>
<Box sx={{ mt: "24px" }}>
- <SpaceShareInviteButton
- profileLink={profileLink}
- sharing={isSharing}
- onSharingChange={setIsSharing}
- onShareError={(error) =>
- log.error(
- "Failed to share Space invite link",
- error,
- )
- }
- />
+ <Box
+ className="green-bg"
+ component="button"
+ type="button"
+ onClick={onClick}
+ sx={spaceEmptyStateButtonSx}
+ >
+ <HugeiconsIcon
+ icon={UserAdd02Icon}
+ size={18}
+ strokeWidth={1.8}
+ />
+ Add a friend
+ </Box>
</Box>
</Box>
) : (
diff --git a/web/apps/space/src/components/OwnPostTile.tsx b/web/apps/space/src/components/OwnPostTile.tsx
index 32507b77e9..31441cf83a 100644
--- a/web/apps/space/src/components/OwnPostTile.tsx
+++ b/web/apps/space/src/components/OwnPostTile.tsx
@@ -7,7 +7,11 @@ import React from "react";
import type { SetupProfile } from "screens/SetupProfileScreen";
import type { SpacePost, SpacePostAssetURLLoader } from "services/space";
import { useSpaceAppState, type SpacePostPublishPhase } from "state/app-state";
-import { spaceSurface, spaceTextMuted } from "styles/colors";
+import {
+ spaceAppBackground,
+ spaceSurface,
+ spaceTextMuted,
+} from "styles/colors";
import {
spacePostTileRadius,
spaceTileCircleInset,
@@ -350,9 +354,8 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({
>
<Box
sx={{
- border: avatarUrl
- ? "2px solid rgba(255, 255, 255, 0.36)"
- : "2px solid rgba(255, 255, 255, 0.28)",
+ bgcolor: spaceAppBackground,
+ border: `3px solid ${spaceAppBackground}`,
borderRadius: "50%",
boxSizing: "border-box",
flexShrink: 0,
diff --git a/web/apps/space/src/components/ShareInviteButton.tsx b/web/apps/space/src/components/ShareInviteButton.tsx
index 131ab8a34d..e55d6915fc 100644
--- a/web/apps/space/src/components/ShareInviteButton.tsx
+++ b/web/apps/space/src/components/ShareInviteButton.tsx
@@ -4,7 +4,12 @@ import { Box } from "@mui/material";
import { spaceToastAutoDismissDurationMs } from "components/ActionToast";
import React from "react";
import { spaceEmptyStateButtonSx } from "styles/buttons";
-import { spaceAppBackgroundColor, spaceText } from "styles/colors";
+import {
+ spaceAppBackgroundColor,
+ spaceText,
+ spaceTextMuted,
+} from "styles/colors";
+import { spaceTouchTargetSize } from "styles/touch-targets";
export const SpaceShareIcon: React.FC<{
size?: number;
@@ -14,14 +19,16 @@ export const SpaceShareIcon: React.FC<{
);
interface SpaceShareInviteButtonProps {
+ disabled?: boolean;
profileLink?: string;
sharing?: boolean;
- variant?: "green" | "secondary";
+ variant?: "green" | "secondary" | "text";
onShareError?: (error: unknown) => void;
onSharingChange?: (sharing: boolean) => void;
}
export const SpaceShareInviteButton: React.FC<SpaceShareInviteButtonProps> = ({
+ disabled = false,
profileLink,
sharing,
variant = "green",
@@ -31,7 +38,7 @@ export const SpaceShareInviteButton: React.FC<SpaceShareInviteButtonProps> = ({
const [copied, setCopied] = React.useState(false);
const [canShare, setCanShare] = React.useState(false);
const isSharing = sharing ?? false;
- const isDisabled = isSharing || !profileLink;
+ const isDisabled = disabled || isSharing || !profileLink;
React.useEffect(() => {
setCanShare(typeof navigator.share == "function");
@@ -82,26 +89,49 @@ export const SpaceShareInviteButton: React.FC<SpaceShareInviteButtonProps> = ({
disabled={isDisabled}
onClick={() => void shareInvite()}
sx={
- variant == "secondary"
+ variant == "text"
? {
- ...spaceEmptyStateButtonSx,
- bgcolor: "#FFFFFF",
- color: spaceAppBackgroundColor,
+ bgcolor: "transparent",
+ border: 0,
+ borderRadius: "8px",
+ color: spaceTextMuted,
+ cursor: "pointer",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 500,
+ lineHeight: "18px",
+ minHeight: spaceTouchTargetSize,
+ p: "8px 12px",
+ textDecoration: "underline",
+ textUnderlineOffset: "3px",
+ "&:disabled": { cursor: "default", opacity: 0.45 },
"&:focus-visible": {
outline: `2px solid ${spaceText}`,
outlineOffset: 2,
},
- "&:hover:not(:disabled)": { bgcolor: spaceText },
+ "&:hover:not(:disabled)": { color: spaceText },
}
- : spaceEmptyStateButtonSx
+ : variant == "secondary"
+ ? {
+ ...spaceEmptyStateButtonSx,
+ bgcolor: "#FFFFFF",
+ color: spaceAppBackgroundColor,
+ "&:focus-visible": {
+ outline: `2px solid ${spaceText}`,
+ outlineOffset: 2,
+ },
+ "&:hover:not(:disabled)": { bgcolor: spaceText },
+ }
+ : spaceEmptyStateButtonSx
}
>
- <SpaceShareIcon />
+ {variant != "text" && <SpaceShareIcon />}
{copied
? "Invite link copied"
: canShare
? "Share invite link"
: "Copy invite link"}
+ {variant == "text" && !copied && " instead"}
</Box>
);
};
diff --git a/web/apps/space/src/components/ShareLinkDialog.tsx b/web/apps/space/src/components/ShareLinkDialog.tsx
deleted file mode 100644
index 2eee6a2e45..0000000000
--- a/web/apps/space/src/components/ShareLinkDialog.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-import { Box, Dialog, useMediaQuery } from "@mui/material";
-import { SpaceBottomSheetTransition } from "components/BottomSheetTransition";
-import log from "ente-base/log";
-import React from "react";
-import { onOpenSpaceShareLinkDialog } from "services/share-link";
-import { spaceOnAccent, spaceText, spaceTextMuted } from "styles/colors";
-
-const green = "#08C225";
-const dangerColor = "#F63A3A";
-
-const isMobileBrowser = () => {
- const { maxTouchPoints, userAgent } = navigator;
- return (
- /Android|iPad|iPhone|iPod/i.test(userAgent) ||
- (userAgent.includes("Macintosh") && maxTouchPoints > 1)
- );
-};
-
-export const SpaceShareLinkDialogHost: React.FC = () => {
- const isBottomSheet = useMediaQuery("(max-width: 599px)");
- const [open, setOpen] = React.useState(false);
- const [profileLink, setProfileLink] = React.useState("");
- const [error, setError] = React.useState<string>();
- const [copied, setCopied] = React.useState(false);
- const [useNativeShare, setUseNativeShare] = React.useState(false);
-
- const showLink = React.useCallback((nextProfileLink: string) => {
- setOpen(true);
- setProfileLink(nextProfileLink);
- setError(undefined);
- setCopied(false);
- setUseNativeShare(
- isMobileBrowser() && typeof navigator.share == "function",
- );
- }, []);
-
- React.useEffect(() => {
- return onOpenSpaceShareLinkDialog(showLink);
- }, [showLink]);
-
- const close = () => {
- setProfileLink("");
- setOpen(false);
- };
-
- const copy = async () => {
- if (!profileLink) return;
- try {
- await navigator.clipboard.writeText(profileLink);
- setCopied(true);
- } catch (error) {
- log.error("Failed to copy Space link", error);
- setError("Couldn't copy the link.");
- }
- };
-
- const share = async () => {
- if (!profileLink) return;
- if (!useNativeShare) {
- await copy();
- return;
- }
- try {
- await navigator.share({ url: profileLink });
- } catch (error) {
- if (
- !(error instanceof DOMException && error.name == "AbortError")
- ) {
- log.error("Failed to share Space link", error);
- setError("Couldn't share the link.");
- }
- }
- };
-
- return (
- <Dialog
- open={open}
- onClose={close}
- maxWidth={false}
- slots={
- isBottomSheet
- ? { transition: SpaceBottomSheetTransition }
- : undefined
- }
- slotProps={{
- paper: {
- sx: {
- borderRadius: "28px 28px 0 0",
- bottom: 0,
- boxShadow: "none",
- boxSizing: "border-box",
- left: 0,
- m: 0,
- maxWidth: "none",
- p: "26px 20px 24px",
- position: "fixed",
- width: "100vw",
- "@media (min-width: 600px)": {
- borderRadius: "20px",
- bottom: "auto",
- left: "50%",
- maxWidth: 363,
- top: "50%",
- transform: "translate(-50%, -50%)",
- width: 363,
- },
- },
- },
- }}
- >
- <Box
- sx={{
- maxWidth: 320,
- mx: "auto",
- width: "100%",
- "@media (min-width: 600px)": { maxWidth: "none" },
- }}
- >
- <Box
- component="h2"
- sx={{
- color: spaceText,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 15,
- fontWeight: 600,
- lineHeight: "20px",
- m: 0,
- px: "20px",
- textAlign: "center",
- }}
- >
- Invite friends
- </Box>
- <Box
- sx={{
- color: spaceTextMuted,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- lineHeight: "18px",
- mt: "8px",
- mx: "-10px",
- px: 0,
- textAlign: "center",
- }}
- >
- Let friends and family add you as a friend on Space
- </Box>
- <Box
- sx={{
- display: "flex",
- flexDirection: "column",
- gap: "12px",
- mt: "20px",
- }}
- >
- <ActionButton
- disabled={!profileLink}
- label={
- copied
- ? "Invite link copied"
- : useNativeShare
- ? "Share invite link"
- : "Copy invite link"
- }
- onClick={share}
- />
- {error && (
- <Box
- role="alert"
- sx={{
- color: dangerColor,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 600,
- lineHeight: "18px",
- px: "12px",
- textAlign: "center",
- }}
- >
- {error}
- </Box>
- )}
- </Box>
- </Box>
- </Dialog>
- );
-};
-
-interface ActionButtonProps {
- disabled?: boolean;
- label: string;
- onClick: () => void | Promise<void>;
-}
-
-const ActionButton: React.FC<ActionButtonProps> = ({
- disabled,
- label,
- onClick,
-}) => (
- <Box
- className="green-bg"
- component="button"
- type="button"
- disabled={disabled}
- onClick={() => void onClick()}
- sx={{
- alignItems: "center",
- bgcolor: green,
- border: 0,
- borderRadius: "20px",
- color: spaceOnAccent,
- cursor: disabled ? "default" : "pointer",
- display: "flex",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 600,
- height: 48,
- justifyContent: "center",
- lineHeight: "20px",
- opacity: disabled ? 0.5 : 1,
- px: "24px",
- transition: "filter 120ms ease, opacity 120ms ease",
- width: "100%",
- "&:active": disabled ? undefined : { filter: "brightness(0.96)" },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": disabled ? undefined : { filter: "brightness(0.98)" },
- }}
- >
- {label}
- </Box>
-);
diff --git a/web/apps/space/src/pages/_app.tsx b/web/apps/space/src/pages/_app.tsx
index da1bb5ecbe..4a54248bf9 100644
--- a/web/apps/space/src/pages/_app.tsx
+++ b/web/apps/space/src/pages/_app.tsx
@@ -4,7 +4,6 @@ import { CssBaseline } from "@mui/material";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { SpacePostComposerHost } from "components/PostComposer";
import { SpaceRouteTransitionBoundary } from "components/RouteTransitionBoundary";
-import { SpaceShareLinkDialogHost } from "components/ShareLinkDialog";
import "configure-zod";
import { CustomHead } from "ente-base/components/Head";
import { useSetupLogs } from "ente-base/components/utils/hooks-app";
@@ -155,7 +154,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<SpaceAppStateProvider>
<Component {...pageProps} />
<SpacePostComposerHost />
- <SpaceShareLinkDialogHost />
</SpaceAppStateProvider>
</SpaceRouteTransitionBoundary>
</ThemeProvider>
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index c0bf355a14..f10fdab1b3 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -1,3 +1,4 @@
+import { SpaceAddFriendDialog } from "components/AddFriendDialog";
import { SpaceFriendLimitToast } from "components/FriendLimitToast";
import { SpaceFriendRequestCanceledToast } from "components/FriendRequestCanceledToast";
import { SpacePageMeta } from "components/PageMeta";
@@ -27,6 +28,7 @@ import {
loadCurrentSpacePostAssetURL,
loadCurrentUnreadStatus,
replyToCurrentPost,
+ requestFriendByUsername,
sendCurrentPoke,
setCurrentPostLiked,
type SpaceFriendRequest,
@@ -54,6 +56,7 @@ const Page: React.FC = () => {
} = useSpaceAppState();
const [friendRequestSentToastName, setFriendRequestSentToastName] =
useState<string>();
+ const [isAddFriendOpen, setIsAddFriendOpen] = useState(false);
const [friendRequests, setFriendRequests] = useState<SpaceFriendRequest[]>(
[],
);
@@ -269,11 +272,6 @@ const Page: React.FC = () => {
isFriendRequestsLoading={isFriendRequestsLoading}
isHomeCacheLoading={isHomeCacheLoading}
profile={profile}
- profileLink={
- profile
- ? spaceInviteURL({ spaceUsername: profile.username })
- : undefined
- }
viewerSpaceId={spaceId ?? profile?.spaceId}
showInstallPrompt={
profileLoadStatus == "ready" &&
@@ -282,6 +280,7 @@ const Page: React.FC = () => {
!isFriendsLoading
}
onFriendRequestSentToastClose={closeFriendRequestSentToast}
+ onAddFriend={() => setIsAddFriendOpen(true)}
onAcceptFriendRequest={async (requestID) => {
if (!profile?.spaceId) throw new Error("Missing space.");
const sentRequestCount = friendRequests.filter(
@@ -457,6 +456,62 @@ const Page: React.FC = () => {
onClose={() => setShowFriendRequestCanceledToast(false)}
/>
)}
+ {profile && (
+ <SpaceAddFriendDialog
+ friendRequests={friendRequests}
+ friends={friends}
+ open={isAddFriendOpen}
+ onClose={() => setIsAddFriendOpen(false)}
+ profileLink={spaceInviteURL({
+ spaceUsername: profile.username,
+ })}
+ username={profile.username}
+ onAddFriend={async (username) => {
+ const actorSpaceId = profile.spaceId;
+ if (!actorSpaceId) throw new Error("Missing space.");
+ const status = await requestFriendByUsername({
+ spaceUsername: username,
+ });
+ try {
+ if (status == "friend") {
+ clearSpaceFriendsCache();
+ const [requests, friends] = await Promise.all([
+ loadCurrentFriendRequests(actorSpaceId),
+ loadCurrentSpaceFriends(actorSpaceId),
+ ]);
+ setFriendRequests(requests);
+ setFriends(friends);
+ const refreshedHomePosts =
+ await refreshSpaceHomePosts(
+ actorSpaceId,
+ friends,
+ );
+ if (refreshedHomePosts) {
+ setLatestPosts(
+ refreshedHomePosts.latestPosts,
+ );
+ setUnreadPosts(
+ refreshedHomePosts.unreadPosts,
+ );
+ }
+ await refreshUnreadStatus(actorSpaceId);
+ } else {
+ setFriendRequests(
+ await loadCurrentFriendRequests(
+ actorSpaceId,
+ ),
+ );
+ }
+ } catch (error) {
+ log.error(
+ "Failed to refresh friends after sending request",
+ error,
+ );
+ }
+ return status;
+ }}
+ />
+ )}
{showFriendLimitToast && (
<SpaceFriendLimitToast
onClose={() => setShowFriendLimitToast(false)}
diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsx
index 3f5c3053d2..b5838a4e1d 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, ArrowRight02Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
+import { SpaceAddFriendDialog } from "components/AddFriendDialog";
import { SpaceAddFriendTile } from "components/AddFriendTile";
import { SpaceFileViewer } from "components/FileViewer";
import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";
@@ -9,6 +10,7 @@ import { useBrowserBackClose } from "hooks/use-browser-back-close";
import React from "react";
import { FriendPostTile } from "screens/HomeScreen";
import type { SetupProfile } from "screens/SetupProfileScreen";
+import { spaceInviteURL } from "services/invite";
import type { SpacePost } from "services/space";
import { spaceAppBackground, spaceSurface, spaceText } from "styles/colors";
import {
@@ -145,6 +147,8 @@ const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({
const LayoutDemoPage: React.FC = () => {
const router = useSpaceRouter();
+ const [isAddFriendOpen, setIsAddFriendOpen] = React.useState(false);
+ const [profileLink, setProfileLink] = React.useState<string>();
const [{ friendCount, ownPosts }, setDemo] = React.useState({
friendCount: 0,
ownPosts: [] as SpacePost[],
@@ -196,7 +200,7 @@ const LayoutDemoPage: React.FC = () => {
}, []);
React.useEffect(() => {
- if (ownViewerOpen) return;
+ if (ownViewerOpen || isAddFriendOpen) return;
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key == "ArrowLeft") {
@@ -207,7 +211,7 @@ const LayoutDemoPage: React.FC = () => {
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
- }, [changeFriendCount, ownViewerOpen]);
+ }, [changeFriendCount, isAddFriendOpen, ownViewerOpen]);
const layout = homeTileLayout(
friendCount,
@@ -287,7 +291,15 @@ const LayoutDemoPage: React.FC = () => {
<SpaceAddFriendTile
placement={layout.addFriend}
variant={layout.addFriendVariant}
- onClick={() => changeFriendCount(1)}
+ onClick={() => {
+ setProfileLink(
+ spaceInviteURL({
+ spaceUsername:
+ demoProfile.username,
+ }),
+ );
+ setIsAddFriendOpen(true);
+ }}
/>
)}
</>
@@ -392,6 +404,18 @@ const LayoutDemoPage: React.FC = () => {
</Box>
</Box>
</Box>
+ <SpaceAddFriendDialog
+ friendRequests={[]}
+ friends={[]}
+ open={isAddFriendOpen}
+ onClose={() => setIsAddFriendOpen(false)}
+ onAddFriend={() => {
+ changeFriendCount(1);
+ return Promise.resolve("requested");
+ }}
+ profileLink={profileLink}
+ username={demoProfile.username}
+ />
{ownPostIndex !== undefined && (
<SpaceFileViewer
photo={ownPostPhotos[ownPostIndex]!}
diff --git a/web/apps/space/src/screens/FriendsScreen.tsx b/web/apps/space/src/screens/FriendsScreen.tsx
index 06043b8da6..06542759a8 100644
--- a/web/apps/space/src/screens/FriendsScreen.tsx
+++ b/web/apps/space/src/screens/FriendsScreen.tsx
@@ -7,31 +7,20 @@ import {
UserRemove01Icon,
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
-import {
- Box,
- Dialog,
- Menu,
- MenuItem,
- Skeleton,
- useMediaQuery,
-} from "@mui/material";
+import { Box, Menu, MenuItem, Skeleton } from "@mui/material";
import {
SpaceActionFeedbackIcon,
spaceActionDoneDurationMs,
type SpaceActionPhase,
} from "components/ActionFeedback";
+import { SpaceAddFriendDialog } from "components/AddFriendDialog";
import { SpaceAvatarImage } from "components/AvatarImage";
-import { SpaceBottomSheetTransition } from "components/BottomSheetTransition";
import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";
import { SpaceLoadingSpinner } from "components/RouteFallback";
import { SpaceShareInviteButton } from "components/ShareInviteButton";
import type { FriendProfile } from "data/friends";
import log from "ente-base/log";
import React, { useState } from "react";
-import {
- normalizeSpaceUsername,
- spaceUsernameValidationError,
-} from "services/profile";
import type { SpaceFriendRequest } from "services/space";
import {
spaceAppBackground,
@@ -43,14 +32,6 @@ import {
spaceTextMuted,
} from "styles/colors";
import { spaceTouchTargetSize } from "styles/touch-targets";
-import {
- friendRequestErrorMessage,
- isSpaceFriendLimitError,
-} from "utils/friend-errors";
-import {
- maximumSpaceFriendCount,
- spaceFriendLimitMessage,
-} from "utils/friend-limits";
const green = "#08C225";
const avatarSkeletonBackground = spaceSurface;
@@ -625,321 +606,6 @@ const FriendRequestRow: React.FC<FriendRequestRowProps> = ({
);
};
-interface AddFriendSheetProps {
- friendRequests: SpaceFriendRequest[];
- friends: FriendProfile[];
- onAddFriend: FriendsScreenProps["onAddFriend"];
- onClose: () => void;
- open: boolean;
- username: string;
-}
-
-const AddFriendSheet: React.FC<AddFriendSheetProps> = ({
- friendRequests,
- friends,
- onAddFriend,
- onClose,
- open,
- username: currentUsername,
-}) => {
- const titleID = React.useId();
- const isBottomSheet = useMediaQuery("(max-width: 599px)");
- const [username, setUsername] = React.useState("");
- const [isSubmitting, setIsSubmitting] = React.useState(false);
- const [isSent, setIsSent] = React.useState(false);
- const [errorMessage, setErrorMessage] = React.useState<string>();
-
- const submit = () => {
- if (isSubmitting || isSent) return;
-
- const normalizedUsername = normalizeSpaceUsername(username);
- const validationError = normalizedUsername
- ? spaceUsernameValidationError(normalizedUsername)
- : "Enter a username.";
- if (validationError) {
- setErrorMessage(validationError);
- return;
- }
- if (normalizedUsername == normalizeSpaceUsername(currentUsername)) {
- setErrorMessage("You can't add yourself as a friend.");
- return;
- }
- if (
- friends.some(
- (friend) =>
- normalizeSpaceUsername(friend.username) ==
- normalizedUsername,
- )
- ) {
- setErrorMessage(
- `You're already friends with @${normalizedUsername}.`,
- );
- return;
- }
- if (
- friendRequests.some(
- (request) =>
- request.direction == "sent" &&
- normalizeSpaceUsername(request.friend.username) ==
- normalizedUsername,
- )
- ) {
- setErrorMessage(
- `Friend request already sent to @${normalizedUsername}.`,
- );
- return;
- }
- const sentRequestCount = friendRequests.filter(
- (request) => request.direction == "sent",
- ).length;
- if (friends.length + sentRequestCount >= maximumSpaceFriendCount) {
- setErrorMessage(spaceFriendLimitMessage);
- return;
- }
-
- setErrorMessage(undefined);
- setIsSubmitting(true);
- void onAddFriend(normalizedUsername)
- .then(() => setIsSent(true))
- .catch((error: unknown) => {
- if (!isSpaceFriendLimitError(error)) {
- log.error("Failed to send space friend request", error);
- }
- setErrorMessage(
- friendRequestErrorMessage(error, normalizedUsername),
- );
- })
- .finally(() => setIsSubmitting(false));
- };
-
- React.useEffect(() => {
- if (!open || !isSent) return;
-
- const timeoutID = window.setTimeout(onClose, spaceActionDoneDurationMs);
- return () => window.clearTimeout(timeoutID);
- }, [isSent, onClose, open]);
-
- return (
- <Dialog
- open={open}
- onClose={isSubmitting ? undefined : onClose}
- maxWidth={false}
- aria-labelledby={titleID}
- slots={
- isBottomSheet
- ? { transition: SpaceBottomSheetTransition }
- : undefined
- }
- slotProps={{
- paper: {
- sx: {
- borderRadius: "28px 28px 0 0",
- bottom: 0,
- boxShadow: "none",
- boxSizing: "border-box",
- left: 0,
- m: 0,
- maxWidth: "none",
- p: "26px 20px 24px",
- position: "fixed",
- width: "100vw",
- "@media (min-width: 600px)": {
- borderRadius: "20px",
- bottom: "auto",
- left: "50%",
- maxWidth: 363,
- top: "50%",
- transform: "translate(-50%, -50%)",
- width: 363,
- },
- },
- },
- transition: {
- onExited: () => {
- setUsername("");
- setIsSent(false);
- setErrorMessage(undefined);
- },
- },
- }}
- >
- <Box
- component="form"
- noValidate
- onSubmit={(event) => {
- event.preventDefault();
- submit();
- }}
- sx={{
- maxWidth: 320,
- mx: "auto",
- width: "100%",
- "@media (min-width: 600px)": { maxWidth: "none" },
- }}
- >
- <Box
- component="h2"
- id={titleID}
- sx={{
- color: textBase,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 15,
- fontWeight: 600,
- lineHeight: "20px",
- m: 0,
- px: "20px",
- textAlign: "center",
- }}
- >
- Add a friend
- </Box>
- <Box
- sx={{
- color: textSoft,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- lineHeight: "18px",
- mt: "8px",
- textAlign: "center",
- }}
- >
- Enter your friend&apos;s username to add them on Space
- </Box>
- <Box
- component="label"
- sx={{ display: "block", mt: "20px", width: "100%" }}
- >
- <Box
- sx={{
- alignItems: "center",
- bgcolor: spaceSurface,
- border: `1px solid ${errorMessage ? dangerColor : "transparent"}`,
- borderRadius: "14px",
- display: "flex",
- height: 48,
- px: "14px",
- width: "100%",
- "&:focus-within": {
- borderColor: green,
- boxShadow: `0 0 0 1px ${green}`,
- },
- }}
- >
- <Box
- component="span"
- aria-hidden
- sx={{
- color: textSoft,
- flexShrink: 0,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 600,
- }}
- >
- @
- </Box>
- <Box
- component="input"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect="off"
- autoFocus
- aria-invalid={Boolean(errorMessage) || undefined}
- disabled={isSubmitting || isSent}
- onChange={(
- event: React.ChangeEvent<HTMLInputElement>,
- ) => {
- const value = event.target.value;
- setUsername(
- value.startsWith("@")
- ? value.slice(1)
- : value,
- );
- setErrorMessage(undefined);
- }}
- placeholder="username"
- spellCheck={false}
- value={username}
- sx={{
- bgcolor: "transparent",
- border: 0,
- color: textBase,
- flex: 1,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
- height: "100%",
- minWidth: 0,
- outline: 0,
- p: 0,
- "&::placeholder": {
- color: textSoft,
- opacity: 1,
- },
- }}
- />
- </Box>
- </Box>
- {errorMessage && (
- <Box
- role="alert"
- sx={{
- color: dangerColor,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 600,
- lineHeight: "18px",
- mt: "8px",
- textAlign: "center",
- }}
- >
- {errorMessage}
- </Box>
- )}
- <Box
- className="green-bg"
- component="button"
- type="submit"
- disabled={isSubmitting || isSent}
- sx={{
- alignItems: "center",
- bgcolor: green,
- border: 0,
- borderRadius: "20px",
- color: spaceOnAccent,
- cursor: isSubmitting || isSent ? "default" : "pointer",
- display: "flex",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 600,
- height: 48,
- justifyContent: "center",
- lineHeight: "20px",
- mt: "20px",
- px: "24px",
- width: "100%",
- "&:disabled": { opacity: isSent ? 1 : 0.6 },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- }}
- >
- {isSubmitting ? (
- <SpaceActionFeedbackIcon phase="busy" />
- ) : isSent ? (
- <SpaceActionFeedbackIcon phase="done" />
- ) : (
- "Send request"
- )}
- </Box>
- </Box>
- </Dialog>
- );
-};
-
export const FriendsScreen: React.FC<FriendsScreenProps> = ({
friendRequests,
friends,
@@ -1165,7 +831,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
</Box>
</Box>
- <AddFriendSheet
+ <SpaceAddFriendDialog
friendRequests={friendRequests}
friends={friends}
onAddFriend={onAddFriend}
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index cc9b226108..0062dd04a1 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -29,7 +29,6 @@ import { useBrowserBackClose } from "hooks/use-browser-back-close";
import React, { useState } from "react";
import type { SetupProfile } from "screens/SetupProfileScreen";
import { markSpaceHomePostRead } from "services/home-posts";
-import { openSpaceShareLinkDialog } from "services/share-link";
import {
isSpaceContentError,
type SpaceFriendRequest,
@@ -103,6 +102,7 @@ interface HomeScreenProps {
onLoadPostImage?: SpacePostAssetURLLoader;
onFriendRequestSentToastClose?: () => void;
onAcceptFriendRequest?: (requestID: number) => Promise<void>;
+ onAddFriend: () => void;
onDiscardFriendRequest?: (requestID: number) => Promise<void>;
onOpenFriend?: (friendID: string, username?: string) => void;
onOpenFriendRequests?: () => void;
@@ -118,7 +118,6 @@ interface HomeScreenProps {
) => Promise<void>;
onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;
profile: SetupProfile | null;
- profileLink?: string;
viewerSpaceId?: string;
}
@@ -656,10 +655,8 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
onClick={openAvatar}
sx={{
appearance: "none",
- bgcolor: "transparent",
- border: displayAvatarUrl
- ? "2px solid rgba(255, 255, 255, 0.36)"
- : "2px solid rgba(255, 255, 255, 0.28)",
+ bgcolor: spaceAppBackground,
+ border: `3px solid ${spaceAppBackground}`,
borderRadius: "50%",
bottom: spaceTileCircleInset(avatarSize),
boxSizing: "border-box",
@@ -992,6 +989,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onDeletePost,
onUpdatePostCaption,
onAcceptFriendRequest,
+ onAddFriend,
onDiscardFriendRequest,
onLoadFriendAvatar,
onLoadPostImage,
@@ -1006,7 +1004,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onReplyToPost,
onSetPostLiked,
profile,
- profileLink,
viewerSpaceId,
}) => {
const [selectedViewer, setSelectedViewer] =
@@ -1737,16 +1734,10 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
{postLayout.addFriend && (
<SpaceAddFriendTile
placement={postLayout.addFriend}
- profileLink={profileLink}
variant={
postLayout.addFriendVariant
}
- onClick={() => {
- if (profileLink)
- openSpaceShareLinkDialog(
- profileLink,
- );
- }}
+ onClick={onAddFriend}
/>
)}
</Box>
diff --git a/web/apps/space/src/services/share-link.ts b/web/apps/space/src/services/share-link.ts
deleted file mode 100644
index 1c20fed375..0000000000
--- a/web/apps/space/src/services/share-link.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-const openEvent = "ente-space-open-share-link";
-
-export const openSpaceShareLinkDialog = (profileLink: string) => {
- window.dispatchEvent(new CustomEvent(openEvent, { detail: profileLink }));
-};
-
-export const onOpenSpaceShareLinkDialog = (
- listener: (profileLink: string) => void,
-) => {
- const handleOpen = (event: Event) => {
- listener((event as CustomEvent<string>).detail);
- };
-
- window.addEventListener(openEvent, handleOpen);
- return () => window.removeEventListener(openEvent, handleOpen);
-};