Skip to content

armgit / ente

Public Imported from GitHub
0

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

Simplify Space friend invite flow

Anand Baburajanffa9d10d27c8
diff --git a/web/apps/space/src/components/SpaceInviteFriendsDialog.tsx b/web/apps/space/src/components/SpaceInviteFriendsDialog.tsx
deleted file mode 100644
index 977e7927d1..0000000000
--- a/web/apps/space/src/components/SpaceInviteFriendsDialog.tsx
+++ /dev/null
@@ -1,185 +0,0 @@
-import { Box, Dialog, useMediaQuery } from "@mui/material";
-import { SpaceBottomSheetTransition } from "components/SpaceBottomSheetTransition";
-import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";
-import React from "react";
-
-const textBase = "#000";
-const textSoft = "#777777";
-const dangerColor = "#F63A3A";
-
-interface SpaceInviteFriendsDialogProps {
- open: boolean;
- profileLink?: string;
- sharing: boolean;
- onClose: () => void;
- onSharingChange: (sharing: boolean) => void;
-}
-
-export const SpaceInviteFriendsDialog: React.FC<
- SpaceInviteFriendsDialogProps
-> = ({ open, profileLink, sharing, onClose, onSharingChange }) => {
- const titleID = React.useId();
- const isBottomSheet = useMediaQuery("(max-width: 599px)");
- const [shareErrorMessage, setShareErrorMessage] = React.useState<
- string | null
- >(null);
-
- React.useEffect(() => {
- if (open) setShareErrorMessage(null);
- }, [open]);
-
- return (
- <Dialog
- open={open}
- onClose={sharing ? undefined : onClose}
- maxWidth={false}
- aria-labelledby={titleID}
- slots={
- isBottomSheet
- ? { transition: SpaceBottomSheetTransition }
- : undefined
- }
- slotProps={{
- backdrop: { sx: { backgroundColor: "rgba(0, 0, 0, 0.48)" } },
- paper: {
- sx: {
- bgcolor: "#FAFAFA",
- borderRadius: "28px 28px 0 0",
- bottom: 0,
- boxShadow: "none",
- boxSizing: "border-box",
- left: 0,
- m: 0,
- maxWidth: "none",
- p: "26px 20px calc(24px + env(safe-area-inset-bottom))",
- position: "fixed",
- width: "100vw",
- "@media (min-width: 600px)": {
- borderRadius: "20px",
- bottom: "auto",
- left: "50%",
- maxWidth: 342,
- p: "24px 20px 20px",
- top: "50%",
- transform: "translate(-50%, -50%)",
- width: 342,
- },
- },
- },
- }}
- >
- <Box
- 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 friends on Space
- </Box>
- <Box
- component="p"
- sx={{
- color: textSoft,
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
- lineHeight: "20px",
- m: 0,
- mt: "10px",
- textAlign: "center",
- }}
- >
- Share your invite link with friends and family.
- </Box>
- <Box
- sx={{
- display: "flex",
- flexDirection: "column",
- gap: "10px",
- mt: "22px",
- }}
- >
- <SpaceShareInviteButton
- className="green-bg"
- profileLink={profileLink}
- sharing={sharing}
- onShareComplete={onClose}
- onShareError={(error) => {
- console.error(
- "Failed to share space invite",
- error,
- );
- setShareErrorMessage(
- "Couldn't share invite. Please try again.",
- );
- }}
- onShareStart={() => setShareErrorMessage(null)}
- onSharingChange={onSharingChange}
- sx={{
- alignItems: "center",
- border: 0,
- borderRadius: "20px",
- color: "#FFFFFF",
- cursor: sharing ? "default" : "pointer",
- display: "flex",
- gap: "10px",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 600,
- height: 48,
- justifyContent: "center",
- lineHeight: "20px",
- px: "24px",
- py: "14px",
- transition: "filter 120ms ease, opacity 120ms ease",
- width: "100%",
- "&:active": sharing
- ? undefined
- : { filter: "brightness(0.96)" },
- "&:disabled": { opacity: 1 },
- "&:focus-visible": {
- outline: "2px solid rgba(0 0 0 / 0.72)",
- outlineOffset: 2,
- },
- "&:hover": sharing
- ? undefined
- : { filter: "brightness(0.98)" },
- }}
- />
- {shareErrorMessage && (
- <Box
- role="alert"
- sx={{
- color: dangerColor,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 650,
- lineHeight: "18px",
- textAlign: "center",
- }}
- >
- {shareErrorMessage}
- </Box>
- )}
- </Box>
- </Box>
- </Dialog>
- );
-};
diff --git a/web/apps/space/src/components/SpaceShareInviteButton.tsx b/web/apps/space/src/components/SpaceShareInviteButton.tsx
index 49cd126653..6dc014eae7 100644
--- a/web/apps/space/src/components/SpaceShareInviteButton.tsx
+++ b/web/apps/space/src/components/SpaceShareInviteButton.tsx
@@ -37,14 +37,14 @@ export const SpaceShareInviteButton: React.FC<SpaceShareInviteButtonProps> = ({
}) => {
const isSharing = sharing ?? false;
const isDisabled = isSharing || !profileLink;
- const buttonLabel = label ?? "Share invite";
+ const buttonLabel = label ?? "Share profile";
const shareInvite = () => {
if (isDisabled || !profileLink) return;
onShareStart?.();
try {
onSharingChange?.(true);
- openSpaceShareLinkDialog();
+ openSpaceShareLinkDialog("invite");
onShareComplete?.();
} catch (error) {
onShareError?.(error);
diff --git a/web/apps/space/src/components/SpaceShareLinkDialog.tsx b/web/apps/space/src/components/SpaceShareLinkDialog.tsx
index 928e1af534..3f8bbbac1d 100644
--- a/web/apps/space/src/components/SpaceShareLinkDialog.tsx
+++ b/web/apps/space/src/components/SpaceShareLinkDialog.tsx
@@ -8,7 +8,10 @@ import {
type CurrentSpaceLink,
} from "services/space";
import { spaceInviteURL } from "services/spaceInvite";
-import { onOpenSpaceShareLinkDialog } from "services/spaceShareLink";
+import {
+ onOpenSpaceShareLinkDialog,
+ type SpaceShareLinkDialogMode,
+} from "services/spaceShareLink";
const green = "#08C225";
const dangerColor = "#F63A3A";
@@ -22,13 +25,15 @@ export const SpaceShareLinkDialogHost: React.FC = () => {
const [error, setError] = React.useState<string>();
const [copied, setCopied] = React.useState(false);
const [linkChanged, setLinkChanged] = React.useState(false);
+ const [mode, setMode] = React.useState<SpaceShareLinkDialogMode>("profile");
const [isChangeConfirmationOpen, setIsChangeConfirmationOpen] =
React.useState(false);
const [confirming, setConfirming] = React.useState(false);
- const loadLink = React.useCallback(() => {
+ const loadLink = React.useCallback((nextMode: SpaceShareLinkDialogMode) => {
const requestID = ++linkRequestID.current;
setOpen(true);
+ setMode(nextMode);
setLink(undefined);
setLoading(true);
setError(undefined);
@@ -175,7 +180,11 @@ export const SpaceShareLinkDialogHost: React.FC = () => {
textAlign: "center",
}}
>
- {linkChanged ? "New link ready" : "Share your profile"}
+ {linkChanged
+ ? "New link ready"
+ : mode == "invite"
+ ? "Invite friends"
+ : "Share your profile"}
</Box>
<Box
sx={{
diff --git a/web/apps/space/src/screens/FriendsScreen.tsx b/web/apps/space/src/screens/FriendsScreen.tsx
index d087b46f56..b7cd666c87 100644
--- a/web/apps/space/src/screens/FriendsScreen.tsx
+++ b/web/apps/space/src/screens/FriendsScreen.tsx
@@ -15,12 +15,12 @@ import {
type SpaceActionPhase,
} from "components/SpaceActionFeedback";
import { SpaceAvatarImage } from "components/SpaceAvatarImage";
-import { SpaceInviteFriendsDialog } from "components/SpaceInviteFriendsDialog";
import { SpaceLoadingSpinner } from "components/SpaceRouteFallback";
import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";
import type { FriendProfile } from "data/friends";
import React, { useState } from "react";
import type { SpaceFriendRequest } from "services/space";
+import { openSpaceShareLinkDialog } from "services/spaceShareLink";
import { spaceTouchTargetSize } from "styles/touchTargets";
export const friendsBackground = "#FFFFFF";
@@ -614,7 +614,6 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
const [loadedAvatarURLsByKey, setLoadedAvatarURLsByKey] = React.useState<
Record<string, string>
>({});
- const [isInviteDialogOpen, setIsInviteDialogOpen] = React.useState(false);
const [isInviteSharing, setIsInviteSharing] = React.useState(false);
const avatarLoadsInFlightRef = React.useRef<
Map<string, Promise<string | null | undefined>>
@@ -701,10 +700,6 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
setUnfriendErrorMessage(null);
};
- const openInviteDialog = () => setIsInviteDialogOpen(true);
-
- const closeInviteDialog = () => setIsInviteDialogOpen(false);
-
return (
<Box
component="main"
@@ -789,7 +784,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
type="button"
aria-label="Invite friends"
disabled={!profileLink}
- onClick={openInviteDialog}
+ onClick={() => openSpaceShareLinkDialog("invite")}
sx={{
alignItems: "center",
bgcolor: "transparent",
@@ -886,6 +881,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
>
No friends yet
<SpaceShareInviteButton
+ label="Invite friends"
profileLink={profileLink}
sharing={isInviteSharing}
onShareError={(error) =>
@@ -944,13 +940,6 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({
onConfirm={confirmUnfriend}
onExited={handleUnfriendSheetExited}
/>
- <SpaceInviteFriendsDialog
- open={isInviteDialogOpen}
- profileLink={profileLink}
- sharing={isInviteSharing}
- onClose={closeInviteDialog}
- onSharingChange={setIsInviteSharing}
- />
</Box>
);
};
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 45bd83e6d5..21dafbc6a8 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -2384,51 +2384,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
>
{emptyFeedMessage}
</Box>
- {hasLoadedNoFriends && (
- <SpaceShareInviteButton
- profileLink={profileLink}
- sharing={isInviteSharing}
- onShareError={(error) =>
- console.error(
- "Failed to share space invite",
- error,
- )
- }
- onSharingChange={setIsInviteSharing}
- sx={{
- alignItems: "center",
- bgcolor: "#E8E8E8",
- border: 0,
- borderRadius: "18px",
- color: textBase,
- cursor:
- profileLink && !isInviteSharing
- ? "pointer"
- : "default",
- display: "inline-flex",
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 600,
- gap: "6px",
- height: spaceTouchTargetSize,
- justifyContent: "center",
- lineHeight: "18px",
- mt: emptyFeedItemGap,
- px: "14px",
- whiteSpace: "nowrap",
- "&:disabled": { opacity: 0.45 },
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover":
- profileLink && !isInviteSharing
- ? { bgcolor: "#DEDEDE" }
- : undefined,
- }}
- />
- )}
</Box>
)}
</Box>
diff --git a/web/apps/space/src/services/spaceShareLink.ts b/web/apps/space/src/services/spaceShareLink.ts
index d75ecffbb5..0326ab9871 100644
--- a/web/apps/space/src/services/spaceShareLink.ts
+++ b/web/apps/space/src/services/spaceShareLink.ts
@@ -1,10 +1,21 @@
const openEvent = "ente-space-open-share-link";
-export const openSpaceShareLinkDialog = () => {
- window.dispatchEvent(new Event(openEvent));
+export type SpaceShareLinkDialogMode = "invite" | "profile";
+
+export const openSpaceShareLinkDialog = (
+ mode: SpaceShareLinkDialogMode = "profile",
+) => {
+ window.dispatchEvent(
+ new CustomEvent<SpaceShareLinkDialogMode>(openEvent, { detail: mode }),
+ );
};
-export const onOpenSpaceShareLinkDialog = (listener: () => void) => {
- window.addEventListener(openEvent, listener);
- return () => window.removeEventListener(openEvent, listener);
+export const onOpenSpaceShareLinkDialog = (
+ listener: (mode: SpaceShareLinkDialogMode) => void,
+) => {
+ const handleOpen = (event: Event) =>
+ listener((event as CustomEvent<SpaceShareLinkDialogMode>).detail);
+
+ window.addEventListener(openEvent, handleOpen);
+ return () => window.removeEventListener(openEvent, handleOpen);
};