π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refactor space invite sharing
Anand Baburajan2edaf52da63a
diff --git a/web/apps/space/src/components/SpaceInviteFriendsDialog.tsx b/web/apps/space/src/components/SpaceInviteFriendsDialog.tsxindex db6449d088..9447bc127e 100644--- a/web/apps/space/src/components/SpaceInviteFriendsDialog.tsx+++ b/web/apps/space/src/components/SpaceInviteFriendsDialog.tsx@@ -1,7 +1,6 @@-import { Share08Icon } from "@hugeicons/core-free-icons";-import { HugeiconsIcon } from "@hugeicons/react";import { Box, Dialog, useMediaQuery } from "@mui/material";import { SpaceBottomSheetTransition } from "components/SpaceBottomSheetTransition";+import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";import React from "react";const textBase = "#000";@@ -9,18 +8,25 @@ const textSoft = "#777777";const dangerColor = "#F63A3A";interface SpaceInviteFriendsDialogProps {- errorMessage?: string | null;open: boolean;+ profileLink?: string;sharing: boolean;onClose: () => void;- onShare: () => void;+ onSharingChange: (sharing: boolean) => void;}export const SpaceInviteFriendsDialog: React.FC<SpaceInviteFriendsDialogProps-> = ({ errorMessage, open, sharing, onClose, onShare }) => {+> = ({ 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@@ -110,12 +116,22 @@ export const SpaceInviteFriendsDialog: React.FC<mt: "22px",}}>- <Box+ <SpaceShareInviteButtonclassName="green-bg"- component="button"- type="button"- disabled={sharing}- onClick={onShare}+ 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,@@ -146,15 +162,8 @@ export const SpaceInviteFriendsDialog: React.FC<? undefined: { filter: "brightness(0.98)" },}}- >- <HugeiconsIcon- icon={Share08Icon}- size={18}- strokeWidth={1.8}- />- {sharing ? "Sharing..." : "Share invite"}- </Box>- {errorMessage && (+ />+ {shareErrorMessage && (<Boxrole="alert"sx={{@@ -167,7 +176,7 @@ export const SpaceInviteFriendsDialog: React.FC<textAlign: "center",}}>- {errorMessage}+ {shareErrorMessage}</Box>)}</Box>diff --git a/web/apps/space/src/components/SpaceMessagesPage.tsx b/web/apps/space/src/components/SpaceMessagesPage.tsxindex 70f10aefce..6a23da4c07 100644--- a/web/apps/space/src/components/SpaceMessagesPage.tsx+++ b/web/apps/space/src/components/SpaceMessagesPage.tsx@@ -5,7 +5,6 @@ import { MessagesScreen, messagesBackground } from "screens/MessagesScreen";import type { SetupProfile } from "screens/SetupProfileScreen";import {confirmCurrentFriendRequest,- createCurrentProfileLink,deleteCurrentFriendRequest,deleteCurrentMessage,loadCurrentMessageConversations,@@ -19,6 +18,7 @@ import {type SpaceMessage,type SpaceMessageConversation,} from "services/space";+import { spaceInviteURL } from "services/spaceInvite";import { useSpaceAppState } from "state/spaceAppState";import { spaceRoutes } from "utils/spaceRoutes";import { useSpaceRouter } from "utils/spaceRouteTransitions";@@ -573,11 +573,9 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({);void refreshConversations();}}- onShareProfileLink={async () => {- if (!profile.spaceId) throw new Error("Missing space.");- return (await createCurrentProfileLink(profile.spaceId))- .url;- }}+ profileLink={spaceInviteURL({+ spaceUsername: profile.username,+ })}onDeleteMessage={async (messageId) => {await deleteCurrentMessage(messageId);setMessages((currentMessages) =>diff --git a/web/apps/space/src/components/SpaceShareInviteButton.tsx b/web/apps/space/src/components/SpaceShareInviteButton.tsxnew file mode 100644index 0000000000..d9c50bdba7--- /dev/null+++ b/web/apps/space/src/components/SpaceShareInviteButton.tsx@@ -0,0 +1,132 @@+import { Share08Icon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { Box, type SxProps, type Theme } from "@mui/material";+import React from "react";++type ShareInviteResult = "shared" | "copied" | "dismissed";+type ShareInvitePhase = "idle" | "sharing" | "copied";++const copiedLabelDurationMs = 1400;++const shareSpaceLink = async (+ profileLink: string,+): Promise<ShareInviteResult> => {+ if (typeof navigator.share == "function") {+ try {+ await navigator.share({ url: profileLink });+ return "shared";+ } catch (error) {+ if (error instanceof DOMException && error.name == "AbortError") {+ return "dismissed";+ }+ throw error;+ }+ }++ await navigator.clipboard.writeText(profileLink);+ return "copied";+};++export const SpaceShareIcon: React.FC<{ strokeWidth?: number }> = ({+ strokeWidth = 1.8,+}) => <HugeiconsIcon icon={Share08Icon} size={18} strokeWidth={strokeWidth} />;++interface SpaceShareInviteButtonProps {+ className?: string;+ iconStrokeWidth?: number;+ profileLink?: string;+ sharing?: boolean;+ sx?: SxProps<Theme>;+ onShareComplete?: () => void;+ onShareError?: (error: unknown) => void;+ onShareStart?: () => void;+ onSharingChange?: (sharing: boolean) => void;+}++export const SpaceShareInviteButton: React.FC<SpaceShareInviteButtonProps> = ({+ className,+ iconStrokeWidth,+ profileLink,+ sharing,+ sx,+ onShareComplete,+ onShareError,+ onShareStart,+ onSharingChange,+}) => {+ const [phase, setPhase] = React.useState<ShareInvitePhase>("idle");+ const copiedResetTimeoutRef = React.useRef<number | undefined>(undefined);+ const shareInFlightRef = React.useRef(false);+ const isSharing = sharing ?? phase == "sharing";+ const isDisabled = isSharing || !profileLink;+ const buttonLabel =+ phase == "copied"+ ? "Invite link copied"+ : isSharing+ ? "Sharing invite..."+ : "Share invite";++ const setSharing = (nextSharing: boolean) => {+ if (sharing === undefined) setPhase(nextSharing ? "sharing" : "idle");+ onSharingChange?.(nextSharing);+ };++ const clearCopiedResetTimeout = React.useCallback(() => {+ if (copiedResetTimeoutRef.current === undefined) return;+ window.clearTimeout(copiedResetTimeoutRef.current);+ copiedResetTimeoutRef.current = undefined;+ }, []);++ React.useEffect(+ () => () => {+ clearCopiedResetTimeout();+ },+ [clearCopiedResetTimeout],+ );++ const shareInvite = async () => {+ if (isDisabled || shareInFlightRef.current || !profileLink) return;++ shareInFlightRef.current = true;+ clearCopiedResetTimeout();+ setPhase("idle");+ onShareStart?.();++ try {+ if (typeof navigator.share == "function") setSharing(true);+ const result = await shareSpaceLink(profileLink);+ if (result == "shared") onShareComplete?.();+ if (result == "copied") {+ setPhase("copied");+ copiedResetTimeoutRef.current = window.setTimeout(() => {+ setPhase("idle");+ copiedResetTimeoutRef.current = undefined;+ onShareComplete?.();+ }, copiedLabelDurationMs);+ }+ } catch (error) {+ if (onShareError) {+ onShareError(error);+ } else {+ throw error;+ }+ } finally {+ shareInFlightRef.current = false;+ if (typeof navigator.share == "function") setSharing(false);+ }+ };++ return (+ <Box+ className={className}+ component="button"+ type="button"+ disabled={isDisabled}+ onClick={() => void shareInvite()}+ sx={sx}+ >+ <SpaceShareIcon strokeWidth={iconStrokeWidth} />+ {buttonLabel}+ </Box>+ );+};diff --git a/web/apps/space/src/pages/app/friends/index.tsx b/web/apps/space/src/pages/app/friends/index.tsxindex 414429a93e..e42991fa36 100644--- a/web/apps/space/src/pages/app/friends/index.tsx+++ b/web/apps/space/src/pages/app/friends/index.tsx@@ -3,11 +3,11 @@ import { SpaceRouteFallback } from "components/SpaceRouteFallback";import React, { useEffect } from "react";import { FriendsScreen, friendsBackground } from "screens/FriendsScreen";import {- createCurrentProfileLink,loadCurrentFriendAvatarURL,loadCurrentSpaceFriends,removeCurrentSpaceFriend,} from "services/space";+import { spaceInviteURL } from "services/spaceInvite";import { useSpaceAppState } from "state/spaceAppState";import { spaceRoutes } from "utils/spaceRoutes";import { useSpaceRouter } from "utils/spaceRouteTransitions";@@ -57,11 +57,9 @@ const Page: React.FC = () => {onOpenFriend={(friendID) =>void router.push(spaceRoutes.friend(friendID))}- onShareProfileLink={async () => {- if (!profile.spaceId) throw new Error("Missing space.");- return (await createCurrentProfileLink(profile.spaceId))- .url;- }}+ profileLink={spaceInviteURL({+ spaceUsername: profile.username,+ })}onUnfriend={async (friendID) => {const friend = friends.find((candidate) => candidate.id == friendID,diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsxindex 8342926716..420b424729 100644--- a/web/apps/space/src/pages/app/index.tsx+++ b/web/apps/space/src/pages/app/index.tsx@@ -4,7 +4,6 @@ import React, { useEffect, useState } from "react";import { HomeScreen, homeBackground } from "screens/HomeScreen";import {createCurrentPhotoPost,- createCurrentProfileLink,deleteCurrentPost,loadCurrentFeedPage,loadCurrentSpaceFriends,@@ -15,7 +14,10 @@ import {setCurrentPostLiked,type SpacePost,} from "services/space";-import { consumeSentSpaceInviteFriend } from "services/spaceInvite";+import {+ consumeSentSpaceInviteFriend,+ spaceInviteURL,+} from "services/spaceInvite";import { useSpaceAppState } from "state/spaceAppState";import {confirmLocalFeedPost,@@ -304,17 +306,9 @@ const Page: React.FC = () => {}onReplyToPost={replyToCurrentPost}onSetPostLiked={setFeedPostLiked}- onShareProfileLink={+ profileLink={profile- ? async () => {- if (!profile.spaceId)- throw new Error("Missing space.");- return (- await createCurrentProfileLink(- profile.spaceId,- )- ).url;- }+ ? spaceInviteURL({ spaceUsername: profile.username }): undefined}/>diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsxindex 8b4a635628..5c3ed6f5c1 100644--- a/web/apps/space/src/pages/app/profile.tsx+++ b/web/apps/space/src/pages/app/profile.tsx@@ -4,7 +4,6 @@ import React, { useEffect, useMemo, useState } from "react";import { ProfileScreen, profileBackground } from "screens/ProfileScreen";import {createCurrentPhotoPost,- createCurrentProfileLink,deleteCurrentPost,loadCurrentSpaceFriendsCount,loadCurrentSpacePostAssetURL,@@ -12,6 +11,7 @@ import {setCurrentPostLiked,type SpaceProfilePost,} from "services/space";+import { spaceInviteURL } from "services/spaceInvite";import { useSpaceAppState } from "state/spaceAppState";import {confirmLocalFeedPost,@@ -193,11 +193,9 @@ const Page: React.FC = () => {onOpenSettings={() => void router.push(spaceRoutes.settings)}onLoadPostImage={loadCurrentSpacePostAssetURL}onSetPostLiked={setCurrentPostLiked}- onShareProfileLink={async () => {- if (!profile.spaceId) throw new Error("Missing space.");- return (await createCurrentProfileLink(profile.spaceId))- .url;- }}+ profileLink={spaceInviteURL({+ spaceUsername: profile.username,+ })}/></>);diff --git a/web/apps/space/src/pages/index.tsx b/web/apps/space/src/pages/index.tsxindex 3f21ac9528..3f06ad0c88 100644--- a/web/apps/space/src/pages/index.tsx+++ b/web/apps/space/src/pages/index.tsx@@ -204,7 +204,7 @@ const PublicFriendRequestScreen: React.FC<PublicFriendRequestScreenProps> = ({}}>Add <Box component="span">@{identity.username}</Box> as a- friend to see what they're up to on Ente Space+ friend to see what they're up to on Ente Space</Box></Box><Boxdiff --git a/web/apps/space/src/pages/invite.tsx b/web/apps/space/src/pages/invite.tsxindex 7178248bfa..6b3fd3b094 100644--- a/web/apps/space/src/pages/invite.tsx+++ b/web/apps/space/src/pages/invite.tsx@@ -1,11 +1,11 @@import { SpacePageMeta } from "components/SpacePageMeta";import { SpaceRouteFallback } from "components/SpaceRouteFallback";-import React, { useCallback, useEffect, useState } from "react";+import React, { useEffect } from "react";import {ShareProfileLinkScreen,shareProfileLinkBackground,} from "screens/ShareProfileLinkScreen";-import { createCurrentProfileLink } from "services/space";+import { spaceInviteURL } from "services/spaceInvite";import { useSpaceAppState } from "state/spaceAppState";import { spaceRoutes } from "utils/spaceRoutes";import { useSpaceRouter } from "utils/spaceRouteTransitions";@@ -13,8 +13,6 @@ import { useSpaceRouter } from "utils/spaceRouteTransitions";const Page: React.FC = () => {const router = useSpaceRouter();const { profile, profileLoadError, profileLoadStatus } = useSpaceAppState();- const [profileLink, setProfileLink] = useState<string>();- const [linkError, setLinkError] = useState<string>();useEffect(() => {if (profileLoadStatus == "ready" && !profile) {@@ -22,24 +20,6 @@ const Page: React.FC = () => {}}, [profile, profileLoadStatus, router]);- const loadInviteLink = useCallback(async () => {- if (!profile?.spaceId) return;-- setLinkError(undefined);- try {- setProfileLink(- (await createCurrentProfileLink(profile.spaceId)).url,- );- } catch (error) {- console.error("Failed to create space invite link", error);- setLinkError("Couldn't create invite link. Tap to retry.");- }- }, [profile?.spaceId]);-- useEffect(() => {- if (!profileLink) void loadInviteLink();- }, [loadInviteLink, profileLink]);-if (profileLoadStatus != "ready" || !profile) {return (<SpaceRouteFallback@@ -53,11 +33,11 @@ const Page: React.FC = () => {<><SpacePageMeta themeColor={shareProfileLinkBackground} /><ShareProfileLinkScreen- errorMessage={linkError}profile={profile}onDone={() => void router.push(spaceRoutes.home)}- onRetry={() => void loadInviteLink()}- profileLink={profileLink}+ profileLink={spaceInviteURL({+ spaceUsername: profile.username,+ })}/></>);diff --git a/web/apps/space/src/screens/FriendsScreen.tsx b/web/apps/space/src/screens/FriendsScreen.tsxindex 619f0f3a3b..02b7fc1a2d 100644--- a/web/apps/space/src/screens/FriendsScreen.tsx+++ b/web/apps/space/src/screens/FriendsScreen.tsx@@ -13,9 +13,9 @@ import {} from "components/SpaceActionFeedback";import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceInviteFriendsDialog } from "components/SpaceInviteFriendsDialog";+import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";import type { FriendProfile } from "data/friends";import React, { useState } from "react";-import { ShareIcon } from "screens/ShareProfileLinkScreen";import { spaceTouchTargetSize } from "styles/touchTargets";export const friendsBackground = "#FFFFFF";@@ -41,7 +41,7 @@ interface FriendsScreenProps {onLoadFriendAvatar?: (friend: FriendProfile) => Promise<string | null>;onBack?: () => void;onOpenFriend?: (friendID: string) => void;- onShareProfileLink?: () => Promise<string>;+ profileLink?: string;onUnfriend?: (friendID: string) => Promise<void> | void;}@@ -322,7 +322,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({onLoadFriendAvatar,onBack,onOpenFriend,- onShareProfileLink,+ profileLink,onUnfriend,}) => {const [friendToUnfriend, setFriendToUnfriend] =@@ -337,9 +337,6 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({>({});const [isInviteDialogOpen, setIsInviteDialogOpen] = React.useState(false);const [isInviteSharing, setIsInviteSharing] = React.useState(false);- const [inviteShareError, setInviteShareError] = React.useState<- string | null- >(null);const avatarLoadsInFlightRef = React.useRef<Map<string, Promise<string | null | undefined>>>(new Map());@@ -425,47 +422,9 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({setUnfriendErrorMessage(null);};- const openInviteDialog = () => {- setInviteShareError(null);- setIsInviteDialogOpen(true);- };+ const openInviteDialog = () => setIsInviteDialogOpen(true);- const closeInviteDialog = () => {- if (isInviteSharing) return;- setIsInviteDialogOpen(false);- };-- const shareInviteLink = async () => {- if (!onShareProfileLink || isInviteSharing) return;- setIsInviteSharing(true);- setInviteShareError(null);-- try {- const profileLink = await onShareProfileLink();-- if (typeof navigator.share == "function") {- try {- await navigator.share({ url: profileLink });- setIsInviteDialogOpen(false);- return;- } catch (error) {- if (- error instanceof DOMException &&- error.name == "AbortError"- )- return;- }- }-- await navigator.clipboard.writeText(profileLink);- setIsInviteDialogOpen(false);- } catch (error) {- console.error("Failed to share space invite", error);- setInviteShareError("Couldn't share invite. Please try again.");- } finally {- setIsInviteSharing(false);- }- };+ const closeInviteDialog = () => setIsInviteDialogOpen(false);return (<Box@@ -550,14 +509,14 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({component="button"type="button"aria-label="Invite friends"- disabled={!onShareProfileLink}+ disabled={!profileLink}onClick={openInviteDialog}sx={{alignItems: "center",bgcolor: "transparent",border: 0,color: textBase,- cursor: onShareProfileLink ? "pointer" : "default",+ cursor: profileLink ? "pointer" : "default",display: "flex",height: spaceTouchTargetSize,justifyContent: "flex-end",@@ -626,11 +585,16 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({}}>No friends yet- <Box- component="button"- type="button"- disabled={!onShareProfileLink || isInviteSharing}- onClick={() => void shareInviteLink()}+ <SpaceShareInviteButton+ profileLink={profileLink}+ sharing={isInviteSharing}+ onShareError={(error) =>+ console.error(+ "Failed to share space invite",+ error,+ )+ }+ onSharingChange={setIsInviteSharing}sx={{alignItems: "center",bgcolor: "#E8E8E8",@@ -638,7 +602,7 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({borderRadius: "18px",color: textBase,cursor:- onShareProfileLink && !isInviteSharing+ profileLink && !isInviteSharing? "pointer": "default",display: "inline-flex",@@ -660,14 +624,11 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({outlineOffset: 2,},"&:hover":- onShareProfileLink && !isInviteSharing+ profileLink && !isInviteSharing? { bgcolor: "#DEDEDE" }: undefined,}}- >- <ShareIcon />- Share invite- </Box>+ /></Box>)}</Box>@@ -684,11 +645,11 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({onExited={handleUnfriendSheetExited}/><SpaceInviteFriendsDialog- errorMessage={inviteShareError}open={isInviteDialogOpen}+ profileLink={profileLink}sharing={isInviteSharing}onClose={closeInviteDialog}- onShare={() => void shareInviteLink()}+ onSharingChange={setIsInviteSharing}/></Box>);diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex 8d2d436654..549fa0452e 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -23,10 +23,10 @@ import {} from "components/SpacePostLikeAnimation";import { SpacePWAInstallPrompt } from "components/SpacePWAInstallPrompt";import { SpaceLoadingSpinner } from "components/SpaceRouteFallback";+import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";import { useBrowserBackClose } from "hooks/useBrowserBackClose";import React, { useState } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";-import { ShareIcon } from "screens/ShareProfileLinkScreen";import type {SpacePost,SpacePostAssetURLLoader,@@ -126,7 +126,7 @@ interface HomeScreenProps {onOpenProfile?: () => void;onReplyToPost?: (postId: number, text: string) => Promise<void>;onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;- onShareProfileLink?: () => Promise<string>;+ profileLink?: string;profile: SetupProfile | null;}@@ -1282,8 +1282,8 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({onOpenProfile,onReplyToPost,onSetPostLiked,- onShareProfileLink,profile,+ profileLink,}) => {const [selectedViewer, setSelectedViewer] =useState<SelectedHomeViewer | null>(null);@@ -1582,33 +1582,6 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({return () => observer.disconnect();}, [hasMoreFeedItems, isFeedLoadingMore, onLoadMoreFeedItems]);- const shareInviteLink = async () => {- if (!onShareProfileLink || isInviteSharing) return;- setIsInviteSharing(true);-- try {- const profileLink = await onShareProfileLink();- if (typeof navigator.share == "function") {- try {- await navigator.share({ url: profileLink });- return;- } catch (error) {- if (- error instanceof DOMException &&- error.name == "AbortError"- )- return;- }- }-- await navigator.clipboard.writeText(profileLink);- } catch (error) {- console.error("Failed to share space invite", error);- } finally {- setIsInviteSharing(false);- }- };-const prepareSelectedPostPhoto = async (file: File) => {if (!profile) return;@@ -2053,13 +2026,16 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({{emptyFeedMessage}</Box>{friendsCount == 0 && (- <Box- component="button"- type="button"- disabled={- !onShareProfileLink || isInviteSharing+ <SpaceShareInviteButton+ profileLink={profileLink}+ sharing={isInviteSharing}+ onShareError={(error) =>+ console.error(+ "Failed to share space invite",+ error,+ )}- onClick={() => void shareInviteLink()}+ onSharingChange={setIsInviteSharing}sx={{alignItems: "center",bgcolor: "#E8E8E8",@@ -2067,8 +2043,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({borderRadius: "18px",color: textBase,cursor:- onShareProfileLink &&- !isInviteSharing+ profileLink && !isInviteSharing? "pointer": "default",display: "inline-flex",@@ -2089,15 +2064,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({outlineOffset: 2,},"&:hover":- onShareProfileLink &&- !isInviteSharing+ profileLink && !isInviteSharing? { bgcolor: "#DEDEDE" }: undefined,}}- >- <ShareIcon />- Share invite- </Box>+ />)}</Box>)}diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex 7bdef729fa..af224c6590 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -15,11 +15,11 @@ import {} from "@mui/material";import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceLoadingSpinner } from "components/SpaceRouteFallback";+import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";import { formatTimeAgo } from "ente-base/date";import React from "react";import { flushSync } from "react-dom";import type { SetupProfile } from "screens/SetupProfileScreen";-import { ShareIcon } from "screens/ShareProfileLinkScreen";import type {SpaceMessage,SpaceMessageConversation,@@ -89,7 +89,7 @@ interface MessagesScreenProps {) => Promise<void>;onSendMessage: (spaceId: string, text: string) => Promise<void>;onSetMessageLiked: (messageId: string, liked: boolean) => Promise<void>;- onShareProfileLink?: () => Promise<string>;+ profileLink?: string;newConversationIds?: string[];profile: SetupProfile;selectedFriend?: SpaceMessageConversation["friend"];@@ -1405,8 +1405,8 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({onReplyToMessage,onSendMessage,onSetMessageLiked,- onShareProfileLink,profile,+ profileLink,selectedFriend,threadBackLabel = "Back to messages",}) => {@@ -1439,8 +1439,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({const selectedName = selectedFriend? selectedFriend.fullName.trim() || selectedFriend.username: "";- const showInviteEmptyState =- friendsCount == 0 && Boolean(onShareProfileLink);+ const showInviteEmptyState = friendsCount == 0 && Boolean(profileLink);const emptyConversationsCopy =friendsCount == 0? "No messages yet. Once you add friends, you'll see their likes, replies and messages here."@@ -1534,33 +1533,6 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({closeMessageActions();};- const shareInviteLink = async () => {- if (!onShareProfileLink || isInviteSharing) return;- setIsInviteSharing(true);-- try {- const profileLink = await onShareProfileLink();- if (typeof navigator.share == "function") {- try {- await navigator.share({ url: profileLink });- return;- } catch (error) {- if (- error instanceof DOMException &&- error.name == "AbortError"- )- return;- }- }-- await copyTextToClipboard(profileLink);- } catch (error) {- console.error("Failed to share space invite", error);- } finally {- setIsInviteSharing(false);- }- };-const handleMessageAction = (action: "copy" | "delete" | "like" | "reply",) => {@@ -2483,16 +2455,16 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({{emptyConversationsCopy}</Box>{showInviteEmptyState && (- <Box- component="button"- type="button"- disabled={- !onShareProfileLink ||- isInviteSharing- }- onClick={() =>- void shareInviteLink()+ <SpaceShareInviteButton+ profileLink={profileLink}+ sharing={isInviteSharing}+ onShareError={(error) =>+ console.error(+ "Failed to share space invite",+ error,+ )}+ onSharingChange={setIsInviteSharing}sx={{alignItems: "center",bgcolor: "#F2F2F2",@@ -2500,7 +2472,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({borderRadius: "18px",color: textBase,cursor:- onShareProfileLink &&+ profileLink &&!isInviteSharing? "pointer": "default",@@ -2522,15 +2494,12 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({outlineOffset: 2,},"&:hover":- onShareProfileLink &&+ profileLink &&!isInviteSharing? { bgcolor: "#E8E8E8" }: undefined,}}- >- <ShareIcon />- Share invite- </Box>+ />)}</Box>) : (diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex 5a38069c7c..e05af2e0c1 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -2,6 +2,7 @@ import {AddSquareIcon,ArrowLeft02Icon,Menu01Icon,+ MultiplicationSignIcon,} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box, CircularProgress, Skeleton } from "@mui/material";@@ -14,10 +15,10 @@ import {type SpaceViewerPostActionMode,} from "components/SpaceFileViewer";import { SpacePostFloatingActionButton } from "components/SpacePostFloatingActionButton";+import { SpaceShareIcon } from "components/SpaceShareInviteButton";import { useBrowserBackClose } from "hooks/useBrowserBackClose";import React, { useState } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";-import { ShareIcon } from "screens/ShareProfileLinkScreen";import type { SpacePostAsset } from "services/space";import { spaceTouchTargetSize } from "styles/touchTargets";import { createLoadedLocalPostPhoto } from "utils/localPostPhoto";@@ -47,9 +48,11 @@ const profileAvatarSize = 120;const profileCoverHeight =profileHeaderHeight + profileAvatarTopOffset + profileAvatarSize / 2;const photoMasonryGap = "3px";+const profileHorizontalPadding = "16px";const photoMasonryPlaceholderBackground = "#F2F2F2";const photoMasonryRadius = "12px";const photoMasonryLoadRootMargin = "800px 0px";+const profileToastTransition = "opacity 160ms ease, transform 160ms ease";interface ProfilePhotoDimensions {height: number;width: number;@@ -110,6 +113,18 @@ interface PostMasonryRow {tiles: PostMasonryTile[];}+interface ProfileToastProps {+ message: string;+ open: boolean;+ onClose?: () => void;+ onExited?: () => void;+}++interface ProfileToastState {+ message: string;+ open: boolean;+}+const buildPostMasonryRows = (items: ProfilePostItem[],loadedDimensionsByID: Record<string, ProfilePhotoDimensions>,@@ -349,6 +364,125 @@ const ProfilePostTile: React.FC<ProfilePostTileProps> = ({);};+const CopyIcon: React.FC = () => (+ <svg+ width="14"+ height="14"+ viewBox="0 0 14 14"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M4.5 4.5V2.5C4.5 1.39543 5.39543 0.5 6.5 0.5H11.5C12.6046 0.5 13.5 1.39543 13.5 2.5V7.5C13.5 8.60457 12.6046 9.5 11.5 9.5H9.5M2.5 4.5H7.5C8.60457 4.5 9.5 5.39543 9.5 6.5V11.5C9.5 12.6046 8.60457 13.5 7.5 13.5H2.5C1.39543 13.5 0.5 12.6046 0.5 11.5V6.5C0.5 5.39543 1.39543 4.5 2.5 4.5Z"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ />+ </svg>+);++const ProfileToast: React.FC<ProfileToastProps> = ({+ message,+ open,+ onClose,+ onExited,+}) => (+ <Box+ onTransitionEnd={(event) => {+ if (event.currentTarget != event.target || open) return;+ onExited?.();+ }}+ sx={{+ boxSizing: "border-box",+ left: "50%",+ opacity: open ? 1 : 0,+ px: profileHorizontalPadding,+ pointerEvents: "none",+ position: "fixed",+ top: "calc(env(safe-area-inset-top) + 10px)",+ transform: open+ ? "translateX(-50%) translateY(0)"+ : "translateX(-50%) translateY(-8px)",+ transition: profileToastTransition,+ width: "100%",+ zIndex: 20,+ "@media (min-width: 600px)": { maxWidth: 390 },+ }}+ >+ <Box+ role="status"+ aria-live="polite"+ sx={{+ alignItems: "center",+ bgcolor: "#FFFFFF",+ borderRadius: "18px",+ boxShadow: "0 12px 32px rgba(0, 0, 0, 0.18)",+ boxSizing: "border-box",+ color: textBase,+ display: "flex",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 14,+ fontWeight: 650,+ gap: "10px",+ lineHeight: "20px",+ minHeight: 50,+ pointerEvents: "auto",+ pl: "16px",+ pr: "6px",+ py: "3px",+ width: "100%",+ }}+ >+ <Box component="span" sx={{ display: "flex", flexShrink: 0 }}>+ <CopyIcon />+ </Box>+ <Box+ component="span"+ sx={{+ flex: "1 1 auto",+ minWidth: 0,+ overflow: "hidden",+ textOverflow: "ellipsis",+ whiteSpace: "nowrap",+ }}+ >+ {message}+ </Box>+ <Box+ component="button"+ type="button"+ aria-label="Close"+ onClick={onClose}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: "transparent",+ border: 0,+ color: textBase,+ cursor: onClose ? "pointer" : "default",+ display: "flex",+ flexShrink: 0,+ height: spaceTouchTargetSize,+ justifyContent: "center",+ opacity: 0.9,+ p: 0,+ width: spaceTouchTargetSize,+ "&:focus-visible": {+ outline: "2px solid rgba(0 0 0 / 0.72)",+ outlineOffset: 2,+ },+ }}+ >+ <HugeiconsIcon+ icon={MultiplicationSignIcon}+ size={16}+ strokeWidth={2}+ />+ </Box>+ </Box>+ </Box>+);+interface ProfileScreenProps {friendsCount?: number;headerVariant?: "friend" | "owner";@@ -370,9 +504,9 @@ interface ProfileScreenProps {onLoadPostImage?: (asset: SpacePostAsset) => Promise<string>;onReplyToPost?: (postId: number, text: string) => Promise<void>;onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;- onShareProfileLink?: () => Promise<string>;postGroups?: ProfilePostGroup[];profile: SetupProfile;+ profileLink?: string;}export const ProfileScreen: React.FC<ProfileScreenProps> = ({@@ -392,9 +526,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({onLoadPostImage,onReplyToPost,onSetPostLiked,- onShareProfileLink,postGroups = [],profile,+ profileLink,showPostLoadingIndicator,}) => {const [selectedPost, setSelectedPost] =@@ -403,6 +537,8 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({const [deletedPostIDs, setDeletedPostIDs] = useState<Set<string>>(() => new Set(),);+ const [profileShareToast, setProfileShareToast] =+ useState<ProfileToastState | null>(null);const [loadedPhotoDimensionsByID, setLoadedPhotoDimensionsByID] = useState<Record<string, ProfilePhotoDimensions>>({});@@ -416,6 +552,12 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({>(new Map());const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());const activeLocalPostObjectUrlRef = React.useRef<string | null>(null);+ const profileShareToastTimeoutRef = React.useRef<number | undefined>(+ undefined,+ );+ const profileShareToastFrameRef = React.useRef<number | undefined>(+ undefined,+ );const isOwnerProfile = headerVariant == "owner";const isFriendProfile = headerVariant == "friend";const displayName = profile.fullName.trim() || profile.username.trim();@@ -456,6 +598,52 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({? "hidden": "like-only";+ const clearProfileShareToastTimers = React.useCallback(() => {+ if (profileShareToastTimeoutRef.current !== undefined) {+ window.clearTimeout(profileShareToastTimeoutRef.current);+ profileShareToastTimeoutRef.current = undefined;+ }+ if (profileShareToastFrameRef.current !== undefined) {+ window.cancelAnimationFrame(profileShareToastFrameRef.current);+ profileShareToastFrameRef.current = undefined;+ }+ }, []);++ const hideProfileShareToast = React.useCallback(() => {+ clearProfileShareToastTimers();+ setProfileShareToast((currentToast) =>+ currentToast ? { ...currentToast, open: false } : currentToast,+ );+ }, [clearProfileShareToastTimers]);++ const showProfileShareToast = React.useCallback(+ (message: string) => {+ clearProfileShareToastTimers();+ setProfileShareToast({ message, open: false });+ profileShareToastFrameRef.current = window.requestAnimationFrame(+ () => {+ setProfileShareToast((currentToast) =>+ currentToast+ ? { ...currentToast, open: true }+ : currentToast,+ );+ profileShareToastFrameRef.current = undefined;+ },+ );+ profileShareToastTimeoutRef.current = window.setTimeout(() => {+ profileShareToastTimeoutRef.current = undefined;+ hideProfileShareToast();+ }, 1800);+ },+ [clearProfileShareToastTimers, hideProfileShareToast],+ );++ const clearClosedProfileShareToast = React.useCallback(() => {+ setProfileShareToast((currentToast) =>+ currentToast?.open ? currentToast : null,+ );+ }, []);+const revokeLocalPostObjectUrls = React.useCallback(() => {localPostObjectUrlsRef.current.forEach((objectUrl) =>URL.revokeObjectURL(objectUrl),@@ -765,8 +953,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({};const shareProfile = async () => {- if (!onShareProfileLink) return;- const profileLink = await onShareProfileLink();+ if (!profileLink) return;if (typeof navigator.share == "function") {try {@@ -778,7 +965,13 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({}}- await navigator.clipboard.writeText(profileLink);+ try {+ await navigator.clipboard.writeText(profileLink);+ showProfileShareToast("Invite link copied");+ } catch (error) {+ console.error("Failed to copy profile link", error);+ showProfileShareToast("Couldn't copy link. Please try again.");+ }};const deleteSelectedPost = async () => {@@ -802,6 +995,13 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({[revokeLocalPostObjectUrls],);+ React.useEffect(+ () => () => {+ clearProfileShareToastTimers();+ },+ [clearProfileShareToastTimers],+ );+return (<Boxcomponent="main"@@ -1144,7 +1344,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({bgcolor: "transparent",border: 0,color: textStrong,- cursor: onShareProfileLink+ cursor: profileLink? "pointer": "default",display: "flex",@@ -1165,7 +1365,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({},}}>- <ShareIcon strokeWidth={2.2} />+ <SpaceShareIcon strokeWidth={2.2} /></Box>)}</Box>@@ -1499,6 +1699,14 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({onClick={openPostPhotoPicker}/>)}+ {profileShareToast && (+ <ProfileToast+ message={profileShareToast.message}+ open={profileShareToast.open}+ onClose={hideProfileShareToast}+ onExited={clearClosedProfileShareToast}+ />+ )}{selectedPost && (<SpaceFileViewerphoto={selectedPost.photo}diff --git a/web/apps/space/src/screens/ShareProfileLinkScreen.tsx b/web/apps/space/src/screens/ShareProfileLinkScreen.tsxindex 78f5849704..a508c52738 100644--- a/web/apps/space/src/screens/ShareProfileLinkScreen.tsx+++ b/web/apps/space/src/screens/ShareProfileLinkScreen.tsx@@ -1,8 +1,7 @@-import { Share08Icon } from "@hugeicons/core-free-icons";-import { HugeiconsIcon } from "@hugeicons/react";import { Box, Skeleton } from "@mui/material";import { SpaceAvatarImage } from "components/SpaceAvatarImage";-import React, { useState } from "react";+import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";+import React from "react";import type { SetupProfile } from "screens/SetupProfileScreen";export const shareProfileLinkBackground = "#FAFAFA";@@ -15,51 +14,18 @@ const headerHeight = 64;const headerSideWidth = 32;interface ShareProfileLinkScreenProps {- errorMessage?: string;onDone?: () => void;- onRetry?: () => void;profile: SetupProfile;profileLink?: string;}-export const ShareIcon: React.FC<{ strokeWidth?: number }> = ({- strokeWidth = 1.8,-}) => <HugeiconsIcon icon={Share08Icon} size={18} strokeWidth={strokeWidth} />;-export const ShareProfileLinkScreen: React.FC<ShareProfileLinkScreenProps> = ({- errorMessage,onDone,- onRetry,profile,profileLink,}) => {- const [copied, setCopied] = useState(false);const displayName = profile.fullName.trim() || profile.username.trim();- const copyProfileLink = async () => {- if (!profileLink) return;- await navigator.clipboard.writeText(profileLink);- setCopied(true);- window.setTimeout(() => setCopied(false), 1200);- };-- const shareProfileLink = async () => {- if (!profileLink) return;- const shareData = { url: profileLink };-- if (typeof navigator.share == "function") {- try {- await navigator.share(shareData);- return;- } catch (error) {- if (error instanceof DOMException && error.name == "AbortError")- return;- }- }-- await copyProfileLink();- };-return (<Boxcomponent="main"@@ -194,28 +160,6 @@ export const ShareProfileLinkScreen: React.FC<ShareProfileLinkScreenProps> = ({>Welcome, {displayName}</Box>- {errorMessage && (- <Box- component="button"- type="button"- onClick={onRetry}- sx={{- bgcolor: "transparent",- border: 0,- color: green,- cursor: onRetry ? "pointer" : "default",- fontFamily:- '"Inter Variable", Inter, sans-serif',- fontSize: 13,- fontWeight: 600,- lineHeight: "18px",- mt: "10px",- p: 0,- }}- >- {errorMessage}- </Box>- )}<Boxcomponent="p"sx={{@@ -253,12 +197,10 @@ export const ShareProfileLinkScreen: React.FC<ShareProfileLinkScreenProps> = ({width: "100%",}}>- <Box+ <SpaceShareInviteButtonclassName="green-bg"- component="button"- type="button"- disabled={!profileLink}- onClick={shareProfileLink}+ iconStrokeWidth={2}+ profileLink={profileLink}sx={{alignItems: "center",bgcolor: green,@@ -285,10 +227,7 @@ export const ShareProfileLinkScreen: React.FC<ShareProfileLinkScreenProps> = ({? { bgcolor: "#07AE22" }: undefined,}}- >- <ShareIcon strokeWidth={2} />- {copied ? "Copied" : "Share invite"}- </Box>+ />{onDone && (<Boxcomponent="button"diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex 72573d5709..2af62bdba8 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -2,7 +2,6 @@ import type { FriendProfile } from "data/friends";import { apiOrigin } from "ente-base/origins";import type { SpaceAccountCtxHandle } from "ente-wasm";import type { PendingSpaceInvite } from "services/spaceInvite";-import { spaceInviteURL } from "services/spaceInvite";import {ensureCurrentSpaceContext,releaseCurrentSpaceContext,@@ -213,13 +212,6 @@ export type SpacePostAvatarURLLoader = (post: SpacePost,) => Promise<string | null>;-export interface SpaceLink {- url: string;- spaceId: string;- spaceSlug: string;- spaceUsername: string;-}-export interface PublicSpaceIdentity {spaceId: string;username: string;@@ -801,28 +793,6 @@ const messageActivityFromSpaceActivity = async (};};-export const createCurrentProfileLink = async (- spaceId: string,-): Promise<SpaceLink> => {- const ctx = await ensureCurrentSpaceContext();- try {- const spaceProfile = (await ctx.get_space_profile(- spaceId,- )) as SpaceProfileResponse;- const invite: PendingSpaceInvite = {- spaceUsername: spaceProfile.spaceSlug,- };- return {- url: spaceInviteURL(invite),- spaceId: spaceProfile.spaceId,- spaceSlug: spaceProfile.spaceSlug,- spaceUsername: invite.spaceUsername,- };- } finally {- releaseCurrentSpaceContext(ctx);- }-};-export const joinSpaceInvite = async ({spaceUsername,}: PendingSpaceInvite): Promise<"friend" | "requested"> => {