💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Simplify Space profile sharing
Anand Baburajane5061dbee735
diff --git a/web/apps/space/src/components/SpaceShareInviteButton.tsx b/web/apps/space/src/components/SpaceShareInviteButton.tsxindex 6dc014eae7..77c1ce6be8 100644--- a/web/apps/space/src/components/SpaceShareInviteButton.tsx+++ b/web/apps/space/src/components/SpaceShareInviteButton.tsx@@ -44,7 +44,7 @@ export const SpaceShareInviteButton: React.FC<SpaceShareInviteButtonProps> = ({onShareStart?.();try {onSharingChange?.(true);- openSpaceShareLinkDialog("invite");+ openSpaceShareLinkDialog(profileLink, "invite");onShareComplete?.();} catch (error) {onShareError?.(error);diff --git a/web/apps/space/src/components/SpaceShareLinkDialog.tsx b/web/apps/space/src/components/SpaceShareLinkDialog.tsxindex 806bc10018..01f926929c 100644--- a/web/apps/space/src/components/SpaceShareLinkDialog.tsx+++ b/web/apps/space/src/components/SpaceShareLinkDialog.tsx@@ -1,14 +1,7 @@import { Box, Dialog, useMediaQuery } from "@mui/material";-import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";import { SpaceBottomSheetTransition } from "components/SpaceBottomSheetTransition";import log from "ente-base/log";import React from "react";-import {- getOrCreateCurrentSpaceLink,- rotateCurrentSpaceLink,- type CurrentSpaceLink,-} from "services/space";-import { spaceInviteURL } from "services/spaceInvite";import {onOpenSpaceShareLinkDialog,type SpaceShareLinkDialogMode,@@ -27,67 +20,40 @@ const isMobileBrowser = () => {export const SpaceShareLinkDialogHost: React.FC = () => {const isBottomSheet = useMediaQuery("(max-width: 599px)");- const linkRequestID = React.useRef(0);const [open, setOpen] = React.useState(false);- const [link, setLink] = React.useState<CurrentSpaceLink>();- const [loading, setLoading] = React.useState(false);+ const [profileLink, setProfileLink] = React.useState("");const [error, setError] = React.useState<string>();const [copied, setCopied] = React.useState(false);- const [linkChanged, setLinkChanged] = React.useState(false);const [useNativeShare, setUseNativeShare] = 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((nextMode: SpaceShareLinkDialogMode) => {- const requestID = ++linkRequestID.current;- setOpen(true);- setMode(nextMode);- setLink(undefined);- setLoading(true);- setError(undefined);- setCopied(false);- setLinkChanged(false);- setUseNativeShare(- isMobileBrowser() && typeof navigator.share == "function",- );- void getOrCreateCurrentSpaceLink()- .then((nextLink) => {- if (linkRequestID.current == requestID) setLink(nextLink);- })- .catch((error: unknown) => {- if (linkRequestID.current != requestID) return;- log.error("Failed to create Space link", error);- setError("Couldn't create the link. Please try again.");- })- .finally(() => {- if (linkRequestID.current == requestID) setLoading(false);- });- }, []);+ const showLink = React.useCallback(+ (nextMode: SpaceShareLinkDialogMode, nextProfileLink: string) => {+ setOpen(true);+ setMode(nextMode);+ setProfileLink(nextProfileLink);+ setError(undefined);+ setCopied(false);+ setUseNativeShare(+ isMobileBrowser() && typeof navigator.share == "function",+ );+ },+ [],+ );React.useEffect(() => {- return onOpenSpaceShareLinkDialog(loadLink);- }, [loadLink]);+ return onOpenSpaceShareLinkDialog(showLink);+ }, [showLink]);const close = () => {- linkRequestID.current++;- setLink(undefined);- setLoading(false);+ setProfileLink("");setOpen(false);};- const url = link- ? spaceInviteURL({- accessKey: link.accessKey,- spaceUsername: link.spaceSlug,- })- : "";-const copy = async () => {- if (!url) return;+ if (!profileLink) return;try {- await navigator.clipboard.writeText(url);+ await navigator.clipboard.writeText(profileLink);setCopied(true);} catch (error) {log.error("Failed to copy Space link", error);@@ -96,13 +62,13 @@ export const SpaceShareLinkDialogHost: React.FC = () => {};const share = async () => {- if (!url) return;+ if (!profileLink) return;if (!useNativeShare) {await copy();return;}try {- await navigator.share({ url });+ await navigator.share({ url: profileLink });} catch (error) {if (!(error instanceof DOMException && error.name == "AbortError")@@ -113,171 +79,118 @@ export const SpaceShareLinkDialogHost: React.FC = () => {}};- const confirm = () => {- if (confirming) return;- setConfirming(true);- setError(undefined);- void rotateCurrentSpaceLink()- .then((nextLink) => {- setIsChangeConfirmationOpen(false);- setLink(nextLink);- setCopied(false);- setLinkChanged(true);- })- .catch((error: unknown) => {- log.error("Failed to change Space link", error);- setIsChangeConfirmationOpen(false);- setError("Couldn't change the link.");- })- .finally(() => setConfirming(false));- };-return (- <>- <Dialog- open={open}- onClose={close}- maxWidth={false}- slots={- isBottomSheet- ? { transition: SpaceBottomSheetTransition }- : undefined- }- slotProps={{- 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 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,- },+ <Dialog+ open={open}+ onClose={close}+ maxWidth={false}+ slots={+ isBottomSheet+ ? { transition: SpaceBottomSheetTransition }+ : undefined+ }+ slotProps={{+ 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 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={{- maxWidth: 320,- mx: "auto",- width: "100%",- "@media (min-width: 600px)": { maxWidth: "none" },+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 15,+ fontWeight: 600,+ lineHeight: "20px",+ m: 0,+ px: "20px",+ textAlign: "center",}}>- <Box- component="h2"- sx={{- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 15,- fontWeight: 600,- lineHeight: "20px",- m: 0,- px: "20px",- textAlign: "center",- }}- >- {linkChanged- ? "New link is ready"- : mode == "invite"- ? "Invite friends"- : "Share your profile"}- </Box>- <Box- sx={{- color: "#666",- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 13,- lineHeight: "18px",- mt: "8px",- mx: "-10px",- px: 0,- textAlign: "center",- }}- >- {linkChanged- ? "Share it with friends and family. Only you and people with this link can see your posts."- : "Let friends and family see what you share on Space. Only you and people with this link can see your posts."}- </Box>- <Box- sx={{- display: "flex",- flexDirection: "column",- gap: "12px",- mt: "20px",- }}- >- <ActionButton- disabled={!link || loading}- label={- copied- ? "Copied"- : loading- ? "Getting link…"- : useNativeShare- ? linkChanged- ? "Share new link"- : "Share profile"- : "Copy link"- }- onClick={share}- variant="primary"- />- <ActionButton- disabled={!link || loading}- label="Change link"- onClick={() => setIsChangeConfirmationOpen(true)}- variant="text"- />- {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>+ {mode == "invite" ? "Invite friends" : "Share your profile"}</Box>- </Dialog>- <ConfirmationActionSheet- open={isChangeConfirmationOpen}- title="Change profile link?"- description="You'll get a new link to share. The current one will stop working for anyone with the link."- confirmLabel="Change link"- confirmBackgroundColor={green}- confirmClassName="green-bg"- confirmDisabled={confirming}- confirmActionPhase={confirming ? "busy" : null}- cancelDisabled={confirming}- onCancel={() => {- if (!confirming) setIsChangeConfirmationOpen(false);- }}- onConfirm={confirm}- />- </>+ <Box+ sx={{+ color: "#666",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 13,+ lineHeight: "18px",+ mt: "8px",+ mx: "-10px",+ px: 0,+ textAlign: "center",+ }}+ >+ Share your profile so friends and family can find you.+ </Box>+ <Box+ sx={{+ display: "flex",+ flexDirection: "column",+ gap: "12px",+ mt: "20px",+ }}+ >+ <ActionButton+ disabled={!profileLink}+ label={+ copied+ ? "Copied"+ : useNativeShare+ ? "Share profile"+ : "Copy 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>);};@@ -285,39 +198,35 @@ interface ActionButtonProps {disabled?: boolean;label: string;onClick: () => void | Promise<void>;- variant: "primary" | "text";}const ActionButton: React.FC<ActionButtonProps> = ({disabled,label,onClick,- variant,}) => (<Box- className={variant == "primary" ? "green-bg" : undefined}+ className="green-bg"component="button"type="button"disabled={disabled}onClick={() => void onClick()}sx={{alignItems: "center",- bgcolor: variant == "primary" ? green : "transparent",+ bgcolor: green,border: 0,borderRadius: "20px",- color: variant == "primary" ? "#FFF" : "#8A8A8A",+ color: "#FFF",cursor: disabled ? "default" : "pointer",display: "flex",fontFamily: '"Inter Variable", Inter, sans-serif',fontSize: 14,fontWeight: 600,- height: variant == "primary" ? 48 : 32,+ height: 48,justifyContent: "center",lineHeight: "20px",opacity: disabled ? 0.5 : 1,- px: variant == "primary" ? "24px" : 0,- textDecoration: variant == "text" ? "underline" : "none",- textUnderlineOffset: "3px",+ px: "24px",transition: "filter 120ms ease, opacity 120ms ease",width: "100%","&:active": disabled ? undefined : { filter: "brightness(0.96)" },diff --git a/web/apps/space/src/screens/FriendsScreen.tsx b/web/apps/space/src/screens/FriendsScreen.tsxindex aafcee8bcc..f3309e801a 100644--- a/web/apps/space/src/screens/FriendsScreen.tsx+++ b/web/apps/space/src/screens/FriendsScreen.tsx@@ -786,7 +786,10 @@ export const FriendsScreen: React.FC<FriendsScreenProps> = ({type="button"aria-label="Invite friends"disabled={!profileLink}- onClick={() => openSpaceShareLinkDialog("invite")}+ onClick={() =>+ profileLink &&+ openSpaceShareLinkDialog(profileLink, "invite")+ }sx={{alignItems: "center",bgcolor: "transparent",diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex dfedc21a3d..8e5e775c99 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -1018,7 +1018,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({const shareProfile = () => {if (!profileLink) return;- openSpaceShareLinkDialog();+ openSpaceShareLinkDialog(profileLink);};const deleteSelectedPost = async () => {diff --git a/web/apps/space/src/services/spaceShareLink.ts b/web/apps/space/src/services/spaceShareLink.tsindex 0326ab9871..47f10ed0a3 100644--- a/web/apps/space/src/services/spaceShareLink.ts+++ b/web/apps/space/src/services/spaceShareLink.ts@@ -3,18 +3,26 @@ const openEvent = "ente-space-open-share-link";export type SpaceShareLinkDialogMode = "invite" | "profile";export const openSpaceShareLinkDialog = (+ profileLink: string,mode: SpaceShareLinkDialogMode = "profile",) => {window.dispatchEvent(- new CustomEvent<SpaceShareLinkDialogMode>(openEvent, { detail: mode }),+ new CustomEvent(openEvent, { detail: { mode, profileLink } }),);};export const onOpenSpaceShareLinkDialog = (- listener: (mode: SpaceShareLinkDialogMode) => void,+ listener: (mode: SpaceShareLinkDialogMode, profileLink: string) => void,) => {- const handleOpen = (event: Event) =>- listener((event as CustomEvent<SpaceShareLinkDialogMode>).detail);+ const handleOpen = (event: Event) => {+ const { mode, profileLink } = (+ event as CustomEvent<{+ mode: SpaceShareLinkDialogMode;+ profileLink: string;+ }>+ ).detail;+ listener(mode, profileLink);+ };window.addEventListener(openEvent, handleOpen);return () => window.removeEventListener(openEvent, handleOpen);