Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add Space shared invite prompt

Anand Baburajanc814cdf5fe4e
diff --git a/web/apps/space/src/components/SpaceSharedInviteDialog.tsx b/web/apps/space/src/components/SpaceSharedInviteDialog.tsx
new file mode 100644
index 0000000000..a5d87533cf
--- /dev/null
+++ b/web/apps/space/src/components/SpaceSharedInviteDialog.tsx
@@ -0,0 +1,169 @@
+import { Cancel01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import {
+ Box,
+ Button,
+ Dialog,
+ IconButton,
+ styled,
+ Typography,
+} from "@mui/material";
+import { SpaceAvatarImage } from "components/SpaceAvatarImage";
+import React from "react";
+
+interface SpaceSharedInviteDialogProps {
+ avatarUrl?: string | null;
+ name: string;
+ open: boolean;
+ onAddFriend: () => void;
+ onClose: () => void;
+}
+
+export const SpaceSharedInviteDialog: React.FC<
+ SpaceSharedInviteDialogProps
+> = ({ avatarUrl, name, open, onAddFriend, onClose }) => {
+ const titleID = React.useId();
+ const subtitleID = React.useId();
+
+ return (
+ <StyledDialog
+ open={open}
+ onClose={onClose}
+ aria-labelledby={titleID}
+ aria-describedby={subtitleID}
+ >
+ <DialogWrapper>
+ <CloseButton aria-label="Close" onClick={onClose}>
+ <HugeiconsIcon
+ icon={Cancel01Icon}
+ size={20}
+ strokeWidth={1.8}
+ />
+ </CloseButton>
+
+ <ContentContainer>
+ <AvatarWrapper>
+ <SpaceAvatarImage
+ aria-hidden
+ borderRadius="50%"
+ src={avatarUrl}
+ />
+ </AvatarWrapper>
+
+ <TitleSection>
+ <Title id={titleID}>{name} invited you!</Title>
+ <Subtitle id={subtitleID}>
+ Add {name} as a friend to get their latest posts on
+ Ente Space.
+ </Subtitle>
+ </TitleSection>
+
+ <ButtonsSection>
+ <SignInButton
+ variant="contained"
+ fullWidth
+ onClick={onAddFriend}
+ >
+ Add friend
+ </SignInButton>
+ </ButtonsSection>
+ </ContentContainer>
+ </DialogWrapper>
+ </StyledDialog>
+ );
+};
+
+const StyledDialog = styled(Dialog)(() => ({
+ "& .MuiDialog-paper": {
+ width: 381,
+ maxWidth: "calc(100% - 32px)",
+ borderRadius: 28,
+ backgroundColor: "#fff",
+ padding: 0,
+ margin: 16,
+ overflow: "visible",
+ boxShadow: "none",
+ border: "1px solid #E0E0E0",
+ },
+ "& .MuiBackdrop-root": { backgroundColor: "rgba(0, 0, 0, 0.5)" },
+}));
+
+const DialogWrapper = styled(Box)(() => ({
+ position: "relative",
+ padding: "48px 16px 16px 16px",
+}));
+
+const CloseButton = styled(IconButton)(() => ({
+ position: "absolute",
+ top: 11,
+ right: 12,
+ backgroundColor: "#FAFAFA",
+ color: "#000",
+ padding: 10,
+ "&:hover": { backgroundColor: "#F0F0F0" },
+}));
+
+const ContentContainer = styled(Box)(() => ({
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: 16,
+}));
+
+const AvatarWrapper = styled(Box)(() => ({
+ backgroundColor: "#FAFAFA",
+ border: "1px solid #E0E0E0",
+ borderRadius: "50%",
+ height: 112,
+ marginBottom: 8,
+ overflow: "hidden",
+ width: 112,
+}));
+
+const TitleSection = styled(Box)(() => ({
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: 9,
+ textAlign: "center",
+ marginBottom: 16,
+}));
+
+const Title = styled(Typography)(() => ({
+ fontWeight: 600,
+ fontSize: 24,
+ lineHeight: "28px",
+ letterSpacing: 0,
+ color: "#000",
+}));
+
+const Subtitle = styled(Typography)(() => ({
+ fontWeight: 500,
+ fontSize: 14,
+ lineHeight: "20px",
+ color: "#666666",
+ maxWidth: 295,
+}));
+
+const ButtonsSection = styled(Box)(() => ({
+ width: "100%",
+ display: "flex",
+ flexDirection: "column",
+ gap: 12,
+}));
+
+const SignInButton = styled(Button)(() => ({
+ display: "flex",
+ padding: "20px 16px",
+ justifyContent: "center",
+ alignItems: "center",
+ gap: 8,
+ flex: "1 0 0",
+ borderRadius: 20,
+ backgroundColor: "#08C225",
+ fontSize: 16,
+ fontWeight: 500,
+ textTransform: "none",
+ color: "#fff",
+ "&:hover": { backgroundColor: "#07A820" },
+}));
diff --git a/web/apps/space/src/pages/index.tsx b/web/apps/space/src/pages/index.tsx
index 69f52e3be3..616d65718c 100644
--- a/web/apps/space/src/pages/index.tsx
+++ b/web/apps/space/src/pages/index.tsx
@@ -1,6 +1,7 @@
import { Box } from "@mui/material";
import { SpacePageMeta } from "components/SpacePageMeta";
import { SpaceRouteFallback } from "components/SpaceRouteFallback";
+import { SpaceSharedInviteDialog } from "components/SpaceSharedInviteDialog";
import React, { useEffect, useMemo, useState } from "react";
import {
OnboardingScreen,
@@ -92,6 +93,15 @@ const PublicProfileUnavailable: React.FC = () => (
const onboardingEntrySourceFromPendingInvite = (): OnboardingEntrySource =>
savedPendingSpaceInvite() ? "add-friend-link" : "direct";
+const sharedInviteDialogStorageKey = "spaceSharedInviteDialogShown";
+
+const hasShownSharedInviteDialog = () =>
+ window.localStorage.getItem(sharedInviteDialogStorageKey) == "1";
+
+const markSharedInviteDialogShown = () => {
+ window.localStorage.setItem(sharedInviteDialogStorageKey, "1");
+};
+
const Page: React.FC = () => {
const router = useSpaceRouter();
const {
@@ -111,6 +121,7 @@ const Page: React.FC = () => {
useState<SpacePostAssetURLLoader>();
const [publicError, setPublicError] = useState<string>();
const [hasSavedSpaceSession, setHasSavedSpaceSession] = useState(false);
+ const [showSharedInviteDialog, setShowSharedInviteDialog] = useState(false);
const publicPostGroups = useMemo(
() => profilePostGroupsFromPosts(publicPosts),
[publicPosts],
@@ -184,6 +195,23 @@ const Page: React.FC = () => {
}
}, [profile, profileLoadStatus, routeMode.kind, router]);
+ useEffect(() => {
+ if (
+ routeMode.kind != "public-profile" ||
+ !publicProfile ||
+ hasShownSharedInviteDialog()
+ ) {
+ setShowSharedInviteDialog(false);
+ return;
+ }
+
+ const timeoutID = window.setTimeout(
+ () => setShowSharedInviteDialog(true),
+ 2500,
+ );
+ return () => window.clearTimeout(timeoutID);
+ }, [publicProfile, routeMode.kind]);
+
const hasProfileLoadError =
routeMode.kind == "app" && profileLoadStatus == "error";
@@ -218,6 +246,43 @@ const Page: React.FC = () => {
);
}
+ const inviteFriend = {
+ fullName: publicProfile.fullName,
+ username: publicProfile.username,
+ };
+ const inviteFriendName =
+ inviteFriend.fullName.trim() ||
+ inviteFriend.username.trim() ||
+ "Someone";
+ const addFriend = () => {
+ savePendingSpaceInvite(routeMode);
+ savePendingSpaceInviteFriend(inviteFriend);
+ setOnboardingEntrySource("add-friend-link");
+ if (profile) {
+ void joinSpaceInvite(routeMode)
+ .then(() => {
+ clearPendingSpaceInvite();
+ clearPendingSpaceInviteFriend();
+ saveAcceptedSpaceInviteFriend(inviteFriend);
+ void router.push(spaceRoutes.home);
+ })
+ .catch((error: unknown) =>
+ console.error("Failed to join space invite", error),
+ );
+ return;
+ }
+ window.location.assign("/");
+ };
+ const closeSharedInviteDialog = () => {
+ markSharedInviteDialogShown();
+ setShowSharedInviteDialog(false);
+ };
+ const addFriendFromSharedInviteDialog = () => {
+ markSharedInviteDialogShown();
+ setShowSharedInviteDialog(false);
+ addFriend();
+ };
+
return (
<>
<SpacePageMeta themeColor={profileBackground} />
@@ -231,33 +296,14 @@ const Page: React.FC = () => {
? spaceRoutes.home
: undefined
}
- onAddFriend={() => {
- const inviteFriend = {
- fullName: publicProfile.fullName,
- username: publicProfile.username,
- };
-
- savePendingSpaceInvite(routeMode);
- savePendingSpaceInviteFriend(inviteFriend);
- setOnboardingEntrySource("add-friend-link");
- if (profile) {
- void joinSpaceInvite(routeMode)
- .then(() => {
- clearPendingSpaceInvite();
- clearPendingSpaceInviteFriend();
- saveAcceptedSpaceInviteFriend(inviteFriend);
- void router.push(spaceRoutes.home);
- })
- .catch((error: unknown) =>
- console.error(
- "Failed to join space invite",
- error,
- ),
- );
- return;
- }
- window.location.assign("/");
- }}
+ onAddFriend={addFriend}
+ />
+ <SpaceSharedInviteDialog
+ avatarUrl={publicProfile.avatarUrl}
+ name={inviteFriendName}
+ open={showSharedInviteDialog}
+ onAddFriend={addFriendFromSharedInviteDialog}
+ onClose={closeSharedInviteDialog}
/>
</>
);