Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor social routes

Anand Baburajand875fa2ed056
diff --git a/web/apps/social/src/components/SocialPageMeta.tsx b/web/apps/social/src/components/SocialPageMeta.tsx
new file mode 100644
index 0000000000..64138a02a4
--- /dev/null
+++ b/web/apps/social/src/components/SocialPageMeta.tsx
@@ -0,0 +1,26 @@
+import Head from "next/head";
+import React from "react";
+import { onboardingDescription } from "screens/OnboardingScreen";
+
+interface SocialPageMetaProps {
+ themeColor: string;
+}
+
+export const SocialPageMeta: React.FC<SocialPageMetaProps> = ({
+ themeColor,
+}) => (
+ <Head>
+ <meta name="theme-color" content={themeColor} />
+ <meta name="description" content={onboardingDescription} />
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
+ <link
+ rel="preconnect"
+ href="https://fonts.gstatic.com"
+ crossOrigin="anonymous"
+ />
+ <link
+ href="https://fonts.googleapis.com/css2?family=Nunito:wght@800&display=swap"
+ rel="stylesheet"
+ />
+ </Head>
+);
diff --git a/web/apps/social/src/components/SocialRouteFallback.tsx b/web/apps/social/src/components/SocialRouteFallback.tsx
new file mode 100644
index 0000000000..fb129deb17
--- /dev/null
+++ b/web/apps/social/src/components/SocialRouteFallback.tsx
@@ -0,0 +1,16 @@
+import { Box } from "@mui/material";
+import { SocialPageMeta } from "components/SocialPageMeta";
+import React from "react";
+
+interface SocialRouteFallbackProps {
+ background: string;
+}
+
+export const SocialRouteFallback: React.FC<SocialRouteFallbackProps> = ({
+ background,
+}) => (
+ <>
+ <SocialPageMeta themeColor={background} />
+ <Box sx={{ bgcolor: background, minHeight: "100svh" }} />
+ </>
+);
diff --git a/web/apps/social/src/pages/_app.tsx b/web/apps/social/src/pages/_app.tsx
index 8ae288bc8d..becb6689db 100644
--- a/web/apps/social/src/pages/_app.tsx
+++ b/web/apps/social/src/pages/_app.tsx
@@ -7,6 +7,7 @@ import { shareTheme } from "ente-base/components/utils/theme";
import type { AppProps } from "next/app";
import "photoswipe/dist/photoswipe.css";
import React from "react";
+import { SocialAppStateProvider } from "state/SocialAppStateProvider";
import "styles/globals.css";
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
@@ -20,7 +21,9 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
>
<CustomHead title="Ente" />
<CssBaseline enableColorScheme />
- <Component {...pageProps} />
+ <SocialAppStateProvider>
+ <Component {...pageProps} />
+ </SocialAppStateProvider>
</ThemeProvider>
);
};
diff --git a/web/apps/social/src/pages/app/friend.tsx b/web/apps/social/src/pages/app/friend.tsx
new file mode 100644
index 0000000000..3de953c050
--- /dev/null
+++ b/web/apps/social/src/pages/app/friend.tsx
@@ -0,0 +1,70 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { sampleFriends } from "data/friends";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import { friendsBackground } from "screens/FriendsScreen";
+import { ProfileScreen } from "screens/ProfileScreen";
+import { useSocialAppState } from "state/socialAppState";
+import {
+ friendIDFromQuery,
+ friendProfileSourceFromQuery,
+ socialRoutes,
+} from "utils/socialRoutes";
+
+const backRouteForSource = (
+ source: ReturnType<typeof friendProfileSourceFromQuery>,
+) =>
+ source == "home"
+ ? socialRoutes.home
+ : source == "notifications"
+ ? socialRoutes.notifications
+ : source == "profile"
+ ? socialRoutes.profile
+ : socialRoutes.friends;
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { friends, profile } = useSocialAppState();
+ const friendID = friendIDFromQuery(router.query.friendID);
+ const backSource = friendProfileSourceFromQuery(router.query.from);
+ const selectedFriend =
+ friends.find((friend) => friend.id == friendID) ??
+ sampleFriends.find((friend) => friend.id == friendID);
+
+ useEffect(() => {
+ if (!router.isReady) return;
+ if (!profile) {
+ void router.replace(socialRoutes.onboarding);
+ return;
+ }
+ if (!selectedFriend) void router.replace(socialRoutes.friends);
+ }, [profile, router, selectedFriend]);
+
+ if (!router.isReady || !profile || !selectedFriend) {
+ return <SocialRouteFallback background={friendsBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={friendsBackground} />
+ <ProfileScreen
+ friendsCount={selectedFriend.friendsCount}
+ headerVariant="friend"
+ profile={{
+ avatarUrl: selectedFriend.avatarUrl,
+ fullName: selectedFriend.fullName,
+ username: selectedFriend.username,
+ }}
+ onBack={() => void router.push(backRouteForSource(backSource))}
+ onOpenFriend={(nextFriendID) =>
+ void router.push(
+ socialRoutes.friend(nextFriendID, backSource),
+ )
+ }
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/app/friends.tsx b/web/apps/social/src/pages/app/friends.tsx
new file mode 100644
index 0000000000..3894034ac4
--- /dev/null
+++ b/web/apps/social/src/pages/app/friends.tsx
@@ -0,0 +1,42 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import { FriendsScreen, friendsBackground } from "screens/FriendsScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { friends, profile, setFriends } = useSocialAppState();
+
+ useEffect(() => {
+ if (!profile) void router.replace(socialRoutes.onboarding);
+ }, [profile, router]);
+
+ if (!profile) {
+ return <SocialRouteFallback background={friendsBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={friendsBackground} />
+ <FriendsScreen
+ friends={friends}
+ onBack={() => void router.push(socialRoutes.profile)}
+ onOpenFriend={(friendID) =>
+ void router.push(socialRoutes.friend(friendID, "friends"))
+ }
+ onUnfriend={(friendID) =>
+ setFriends((currentFriends) =>
+ currentFriends.filter(
+ (friend) => friend.id != friendID,
+ ),
+ )
+ }
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/app/index.tsx b/web/apps/social/src/pages/app/index.tsx
new file mode 100644
index 0000000000..e456f6b3d7
--- /dev/null
+++ b/web/apps/social/src/pages/app/index.tsx
@@ -0,0 +1,39 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import { HomeScreen, homeBackground } from "screens/HomeScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { friends, profile } = useSocialAppState();
+
+ useEffect(() => {
+ if (!profile) void router.replace(socialRoutes.onboarding);
+ }, [profile, router]);
+
+ if (!profile) {
+ return <SocialRouteFallback background={homeBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={homeBackground} />
+ <HomeScreen
+ friendsCount={friends.length}
+ profile={profile}
+ onOpenFriend={(friendID) =>
+ void router.push(socialRoutes.friend(friendID, "home"))
+ }
+ onOpenNotifications={() =>
+ void router.push(socialRoutes.notifications)
+ }
+ onOpenProfile={() => void router.push(socialRoutes.profile)}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/app/notifications.tsx b/web/apps/social/src/pages/app/notifications.tsx
new file mode 100644
index 0000000000..e8c1ad1b0f
--- /dev/null
+++ b/web/apps/social/src/pages/app/notifications.tsx
@@ -0,0 +1,39 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import {
+ NotificationsScreen,
+ notificationsBackground,
+} from "screens/NotificationsScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { profile } = useSocialAppState();
+
+ useEffect(() => {
+ if (!profile) void router.replace(socialRoutes.onboarding);
+ }, [profile, router]);
+
+ if (!profile) {
+ return <SocialRouteFallback background={notificationsBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={notificationsBackground} />
+ <NotificationsScreen
+ onBack={() => void router.push(socialRoutes.home)}
+ onOpenFriend={(friendID) =>
+ void router.push(
+ socialRoutes.friend(friendID, "notifications"),
+ )
+ }
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/app/profile.tsx b/web/apps/social/src/pages/app/profile.tsx
new file mode 100644
index 0000000000..65efb74d5a
--- /dev/null
+++ b/web/apps/social/src/pages/app/profile.tsx
@@ -0,0 +1,38 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import { ProfileScreen, profileBackground } from "screens/ProfileScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { friends, profile } = useSocialAppState();
+
+ useEffect(() => {
+ if (!profile) void router.replace(socialRoutes.onboarding);
+ }, [profile, router]);
+
+ if (!profile) {
+ return <SocialRouteFallback background={profileBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={profileBackground} />
+ <ProfileScreen
+ friendsCount={friends.length}
+ profile={profile}
+ onBack={() => void router.push(socialRoutes.home)}
+ onOpenFriend={(friendID) =>
+ void router.push(socialRoutes.friend(friendID, "profile"))
+ }
+ onOpenFriends={() => void router.push(socialRoutes.friends)}
+ onOpenSettings={() => void router.push(socialRoutes.settings)}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/app/settings.tsx b/web/apps/social/src/pages/app/settings.tsx
new file mode 100644
index 0000000000..dd92c27960
--- /dev/null
+++ b/web/apps/social/src/pages/app/settings.tsx
@@ -0,0 +1,35 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import { SettingsScreen, settingsBackground } from "screens/SettingsScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { profile, resetAfterLogout } = useSocialAppState();
+
+ useEffect(() => {
+ if (!profile) void router.replace(socialRoutes.onboarding);
+ }, [profile, router]);
+
+ if (!profile) {
+ return <SocialRouteFallback background={settingsBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={settingsBackground} />
+ <SettingsScreen
+ onBack={() => void router.push(socialRoutes.profile)}
+ onLogout={() => {
+ resetAfterLogout();
+ void router.push(socialRoutes.onboarding);
+ }}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/index.tsx b/web/apps/social/src/pages/index.tsx
index 3f5380957a..7c9f034088 100644
--- a/web/apps/social/src/pages/index.tsx
+++ b/web/apps/social/src/pages/index.tsx
@@ -1,70 +1,25 @@
-import { Box } from "@mui/material";
-import { sampleFriends } from "data/friends";
-import Head from "next/head";
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
-import {
- CreateAccountScreen,
- createAccountBackground,
- type CreateAccountInput,
-} from "screens/CreateAccountScreen";
-import { FriendsScreen, friendsBackground } from "screens/FriendsScreen";
-import { HomeScreen, homeBackground } from "screens/HomeScreen";
-import { LoginScreen, loginBackground } from "screens/LoginScreen";
-import {
- NotificationsScreen,
- notificationsBackground,
-} from "screens/NotificationsScreen";
import {
OnboardingScreen,
addFriendOnboardingDescription,
addFriendOnboardingTitle,
- onboardingDescription,
onboardingGreen,
} from "screens/OnboardingScreen";
-import { ProfileScreen, profileBackground } from "screens/ProfileScreen";
+import { profileBackground } from "screens/ProfileScreen";
import { PublicProfileScreen } from "screens/PublicProfileScreen";
-import { SettingsScreen, settingsBackground } from "screens/SettingsScreen";
-import {
- SetupProfileScreen,
- setupProfileBackground,
- type SetupProfile,
-} from "screens/SetupProfileScreen";
+import type { SetupProfile } from "screens/SetupProfileScreen";
import {
- ShareProfileLinkScreen,
- shareProfileLinkBackground,
-} from "screens/ShareProfileLinkScreen";
+ type OnboardingEntrySource,
+ useSocialAppState,
+} from "state/socialAppState";
import {
- VerifyEmailScreen,
- verifyEmailBackground,
-} from "screens/VerifyEmailScreen";
-import {
- beginSocialSignup,
- completeSocialSignup,
- resendSocialSignupCode,
-} from "services/socialSignup";
-
-type Screen =
- | "onboarding"
- | "create-account"
- | "login"
- | "verify-email"
- | "setup-profile"
- | "share-profile-link"
- | "home"
- | "profile"
- | "friends"
- | "notifications"
- | "friend-profile"
- | "settings";
-
-type ProfileBackScreen = "login" | "verify-email";
-type FriendProfileBackScreen = "friends" | "home" | "notifications" | "profile";
-type OnboardingEntrySource = "direct" | "add-friend-link";
-
-const onboardingSourceSearchParam = "onboardingSource";
-const addFriendLinkOnboardingSource: OnboardingEntrySource = "add-friend-link";
-const showMockFriends =
- process.env.NEXT_PUBLIC_HIDE_SOCIAL_MOCK_FRIENDS != "true";
+ addFriendLinkOnboardingSource,
+ onboardingSourceSearchParam,
+ socialRoutes,
+} from "utils/socialRoutes";
const samplePublicProfileData = {
avatarUrl: "/images/sample-avatar.jpg",
@@ -122,38 +77,10 @@ const publicProfileFromLink = (): SetupProfile => ({
});
const Page: React.FC = () => {
+ const router = useRouter();
+ const { onboardingEntrySource, setOnboardingEntrySource } =
+ useSocialAppState();
const [routeMode, setRouteMode] = useState<RouteMode>({ kind: "checking" });
- const [screen, setScreen] = useState<Screen>("onboarding");
- const [email, setEmail] = useState("[email protected]");
- const [friends, setFriends] = useState(() =>
- showMockFriends ? sampleFriends : [],
- );
- const [onboardingEntrySource, setOnboardingEntrySource] =
- useState<OnboardingEntrySource>("direct");
- const [profile, setProfile] = useState<SetupProfile | null>(null);
- const [profileBackScreen, setProfileBackScreen] =
- useState<ProfileBackScreen>("verify-email");
- const [friendProfileBackScreen, setFriendProfileBackScreen] =
- useState<FriendProfileBackScreen>("friends");
- const [selectedFriendID, setSelectedFriendID] = useState<string | null>(
- null,
- );
- const [isLiveSignupVerification, setIsLiveSignupVerification] =
- useState(false);
-
- const openSetupProfile = (backScreen: ProfileBackScreen) => {
- setProfileBackScreen(backScreen);
- setScreen("setup-profile");
- };
-
- const openFriendProfile = (
- friendID: string,
- backScreen: FriendProfileBackScreen,
- ) => {
- setSelectedFriendID(friendID);
- setFriendProfileBackScreen(backScreen);
- setScreen("friend-profile");
- };
useEffect(() => {
const publicProfileLink = parsePublicProfileLink();
@@ -166,249 +93,49 @@ const Page: React.FC = () => {
? { kind: "public-profile", ...publicProfileLink }
: { kind: "app" },
);
- }, []);
-
- const createAccount = async (input: CreateAccountInput) => {
- try {
- await beginSocialSignup(input);
- setEmail(input.email || "[email protected]");
- setIsLiveSignupVerification(true);
- setScreen("verify-email");
- } catch (error) {
- console.error("Social signup failed", error);
- }
- };
-
- const verifySignupEmail = async (code: string) => {
- if (!isLiveSignupVerification) {
- openSetupProfile("verify-email");
- return;
- }
-
- try {
- await completeSocialSignup(email, code);
- setIsLiveSignupVerification(false);
- openSetupProfile("verify-email");
- } catch (error) {
- console.error("Social signup verification failed", error);
- }
- };
+ }, [setOnboardingEntrySource]);
- const selectedFriend = selectedFriendID
- ? (friends.find((friend) => friend.id == selectedFriendID) ??
- sampleFriends.find((friend) => friend.id == selectedFriendID))
- : undefined;
- const isAddFriendLinkOnboarding =
- onboardingEntrySource == "add-friend-link";
-
- const themeColor =
- routeMode.kind != "app"
- ? profileBackground
- : screen == "onboarding"
- ? onboardingGreen
- : screen == "verify-email"
- ? verifyEmailBackground
- : screen == "login"
- ? loginBackground
- : screen == "setup-profile"
- ? setupProfileBackground
- : screen == "share-profile-link"
- ? shareProfileLinkBackground
- : screen == "home"
- ? homeBackground
- : screen == "profile"
- ? profileBackground
- : screen == "friends" || screen == "friend-profile"
- ? friendsBackground
- : screen == "notifications"
- ? notificationsBackground
- : screen == "settings"
- ? settingsBackground
- : createAccountBackground;
+ if (routeMode.kind == "checking") {
+ return <SocialRouteFallback background={profileBackground} />;
+ }
- return (
- <>
- <Head>
- <meta name="theme-color" content={themeColor} />
- <meta name="description" content={onboardingDescription} />
- <link rel="preconnect" href="https://fonts.googleapis.com" />
- <link
- rel="preconnect"
- href="https://fonts.gstatic.com"
- crossOrigin="anonymous"
- />
- <link
- href="https://fonts.googleapis.com/css2?family=Nunito:wght@800&display=swap"
- rel="stylesheet"
- />
- </Head>
- {routeMode.kind == "checking" ? (
- <Box sx={{ bgcolor: profileBackground, minHeight: "100svh" }} />
- ) : routeMode.kind == "public-profile" ? (
+ if (routeMode.kind == "public-profile") {
+ return (
+ <>
+ <SocialPageMeta themeColor={profileBackground} />
<PublicProfileScreen
profile={publicProfileFromLink()}
onAddFriend={() => {
+ setOnboardingEntrySource("add-friend-link");
window.location.assign(
`/?${onboardingSourceSearchParam}=${addFriendLinkOnboardingSource}`,
);
}}
/>
- ) : (
- <>
- {screen == "onboarding" && (
- <OnboardingScreen
- description={
- isAddFriendLinkOnboarding
- ? addFriendOnboardingDescription
- : undefined
- }
- onCreateAccount={() => setScreen("create-account")}
- onLogin={() => setScreen("login")}
- title={
- isAddFriendLinkOnboarding
- ? addFriendOnboardingTitle
- : undefined
- }
- />
- )}
- {screen == "create-account" && (
- <CreateAccountScreen
- onBack={() => setScreen("onboarding")}
- onCreateAccount={(input) =>
- void createAccount(input)
- }
- onLogin={() => setScreen("login")}
- />
- )}
- {screen == "login" && (
- <LoginScreen
- onBack={() => setScreen("onboarding")}
- onContinue={() => openSetupProfile("login")}
- onSignup={() => setScreen("create-account")}
- />
- )}
- {screen == "verify-email" && (
- <VerifyEmailScreen
- email={email}
- initialCode={
- isLiveSignupVerification ? "" : undefined
- }
- onBack={() => setScreen("create-account")}
- onChangeEmail={() => setScreen("create-account")}
- onResendCode={
- isLiveSignupVerification
- ? () => void resendSocialSignupCode(email)
- : undefined
- }
- onVerify={(code) => void verifySignupEmail(code)}
- />
- )}
- {screen == "setup-profile" && (
- <SetupProfileScreen
- ctaLabel={
- isAddFriendLinkOnboarding ? "Done" : "Next"
- }
- onBack={() => setScreen(profileBackScreen)}
- onContinue={(nextProfile) => {
- setProfile(nextProfile);
- setScreen(
- isAddFriendLinkOnboarding
- ? "home"
- : "share-profile-link",
- );
- }}
- />
- )}
- {screen == "share-profile-link" && profile && (
- <ShareProfileLinkScreen
- profile={profile}
- onBack={() => setScreen("setup-profile")}
- onDone={() => setScreen("home")}
- />
- )}
- {screen == "home" && profile && (
- <HomeScreen
- friendsCount={friends.length}
- profile={profile}
- onOpenFriend={(friendID) =>
- openFriendProfile(friendID, "home")
- }
- onOpenNotifications={() =>
- setScreen("notifications")
- }
- onOpenProfile={() => setScreen("profile")}
- />
- )}
- {screen == "profile" && profile && (
- <ProfileScreen
- friendsCount={friends.length}
- profile={profile}
- onBack={() => setScreen("home")}
- onOpenFriend={(friendID) =>
- openFriendProfile(friendID, "profile")
- }
- onOpenFriends={() => setScreen("friends")}
- onOpenSettings={() => setScreen("settings")}
- />
- )}
- {screen == "friends" && (
- <FriendsScreen
- friends={friends}
- onBack={() => setScreen("profile")}
- onOpenFriend={(friendID) =>
- openFriendProfile(friendID, "friends")
- }
- onUnfriend={(friendID) =>
- setFriends((currentFriends) =>
- currentFriends.filter(
- (friend) => friend.id != friendID,
- ),
- )
- }
- />
- )}
- {screen == "notifications" && (
- <NotificationsScreen
- onBack={() => setScreen("home")}
- onOpenFriend={(friendID) =>
- openFriendProfile(friendID, "notifications")
- }
- />
- )}
- {screen == "friend-profile" && selectedFriend && (
- <ProfileScreen
- friendsCount={selectedFriend.friendsCount}
- headerVariant="friend"
- profile={{
- avatarUrl: selectedFriend.avatarUrl,
- fullName: selectedFriend.fullName,
- username: selectedFriend.username,
- }}
- onBack={() => setScreen(friendProfileBackScreen)}
- onOpenFriend={(friendID) =>
- openFriendProfile(
- friendID,
- friendProfileBackScreen,
- )
- }
- />
- )}
- {screen == "settings" && profile && (
- <SettingsScreen
- onBack={() => setScreen("profile")}
- onLogout={() => {
- setProfile(null);
- setOnboardingEntrySource("direct");
- setSelectedFriendID(null);
- setFriends(
- showMockFriends ? sampleFriends : [],
- );
- setScreen("onboarding");
- }}
- />
- )}
- </>
- )}
+ </>
+ );
+ }
+
+ const isAddFriendLinkOnboarding =
+ onboardingEntrySource == "add-friend-link";
+
+ return (
+ <>
+ <SocialPageMeta themeColor={onboardingGreen} />
+ <OnboardingScreen
+ description={
+ isAddFriendLinkOnboarding
+ ? addFriendOnboardingDescription
+ : undefined
+ }
+ onCreateAccount={() => void router.push(socialRoutes.signup)}
+ onLogin={() => void router.push(socialRoutes.login)}
+ title={
+ isAddFriendLinkOnboarding
+ ? addFriendOnboardingTitle
+ : undefined
+ }
+ />
</>
);
};
diff --git a/web/apps/social/src/pages/invite.tsx b/web/apps/social/src/pages/invite.tsx
new file mode 100644
index 0000000000..b179e125e3
--- /dev/null
+++ b/web/apps/social/src/pages/invite.tsx
@@ -0,0 +1,38 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import {
+ ShareProfileLinkScreen,
+ shareProfileLinkBackground,
+} from "screens/ShareProfileLinkScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { profile } = useSocialAppState();
+
+ useEffect(() => {
+ if (!profile) void router.replace(socialRoutes.setupProfile("verify"));
+ }, [profile, router]);
+
+ if (!profile) {
+ return <SocialRouteFallback background={shareProfileLinkBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={shareProfileLinkBackground} />
+ <ShareProfileLinkScreen
+ profile={profile}
+ onBack={() =>
+ void router.push(socialRoutes.setupProfile("verify"))
+ }
+ onDone={() => void router.push(socialRoutes.home)}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/login.tsx b/web/apps/social/src/pages/login.tsx
new file mode 100644
index 0000000000..4ac1ef2fa8
--- /dev/null
+++ b/web/apps/social/src/pages/login.tsx
@@ -0,0 +1,24 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { useRouter } from "next/router";
+import React from "react";
+import { LoginScreen, loginBackground } from "screens/LoginScreen";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+
+ return (
+ <>
+ <SocialPageMeta themeColor={loginBackground} />
+ <LoginScreen
+ onBack={() => void router.push(socialRoutes.onboarding)}
+ onContinue={() =>
+ void router.push(socialRoutes.setupProfile("login"))
+ }
+ onSignup={() => void router.push(socialRoutes.signup)}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/setup-profile.tsx b/web/apps/social/src/pages/setup-profile.tsx
new file mode 100644
index 0000000000..7aca0849c7
--- /dev/null
+++ b/web/apps/social/src/pages/setup-profile.tsx
@@ -0,0 +1,43 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { useRouter } from "next/router";
+import React from "react";
+import {
+ SetupProfileScreen,
+ setupProfileBackground,
+} from "screens/SetupProfileScreen";
+import { useSocialAppState } from "state/socialAppState";
+import { setupProfileSourceFromQuery, socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { onboardingEntrySource, setProfile } = useSocialAppState();
+ const backSource = setupProfileSourceFromQuery(router.query.from);
+ const isAddFriendLinkOnboarding =
+ onboardingEntrySource == "add-friend-link";
+
+ return (
+ <>
+ <SocialPageMeta themeColor={setupProfileBackground} />
+ <SetupProfileScreen
+ ctaLabel={isAddFriendLinkOnboarding ? "Done" : "Next"}
+ onBack={() =>
+ void router.push(
+ backSource == "login"
+ ? socialRoutes.login
+ : socialRoutes.verify,
+ )
+ }
+ onContinue={(nextProfile) => {
+ setProfile(nextProfile);
+ void router.push(
+ isAddFriendLinkOnboarding
+ ? socialRoutes.home
+ : socialRoutes.invite,
+ );
+ }}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/signup.tsx b/web/apps/social/src/pages/signup.tsx
new file mode 100644
index 0000000000..bc5b4e1a03
--- /dev/null
+++ b/web/apps/social/src/pages/signup.tsx
@@ -0,0 +1,40 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { useRouter } from "next/router";
+import React from "react";
+import {
+ CreateAccountScreen,
+ createAccountBackground,
+ type CreateAccountInput,
+} from "screens/CreateAccountScreen";
+import { beginSocialSignup } from "services/socialSignup";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const { setIsLiveSignupVerification, setSignupEmail } = useSocialAppState();
+
+ const createAccount = async (input: CreateAccountInput) => {
+ try {
+ await beginSocialSignup(input);
+ setSignupEmail(input.email);
+ setIsLiveSignupVerification(true);
+ void router.push(socialRoutes.verify);
+ } catch (error) {
+ console.error("Social signup failed", error);
+ }
+ };
+
+ return (
+ <>
+ <SocialPageMeta themeColor={createAccountBackground} />
+ <CreateAccountScreen
+ onBack={() => void router.push(socialRoutes.onboarding)}
+ onCreateAccount={(input) => void createAccount(input)}
+ onLogin={() => void router.push(socialRoutes.login)}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/pages/verify.tsx b/web/apps/social/src/pages/verify.tsx
new file mode 100644
index 0000000000..178169b0c7
--- /dev/null
+++ b/web/apps/social/src/pages/verify.tsx
@@ -0,0 +1,66 @@
+import { SocialPageMeta } from "components/SocialPageMeta";
+import { SocialRouteFallback } from "components/SocialRouteFallback";
+import { useRouter } from "next/router";
+import React, { useEffect } from "react";
+import {
+ VerifyEmailScreen,
+ verifyEmailBackground,
+} from "screens/VerifyEmailScreen";
+import {
+ completeSocialSignup,
+ resendSocialSignupCode,
+} from "services/socialSignup";
+import { useSocialAppState } from "state/socialAppState";
+import { socialRoutes } from "utils/socialRoutes";
+
+const Page: React.FC = () => {
+ const router = useRouter();
+ const {
+ isLiveSignupVerification,
+ setIsLiveSignupVerification,
+ signupEmail,
+ } = useSocialAppState();
+
+ useEffect(() => {
+ if (!signupEmail) void router.replace(socialRoutes.signup);
+ }, [router, signupEmail]);
+
+ const verifySignupEmail = async (code: string) => {
+ if (!isLiveSignupVerification) {
+ void router.push(socialRoutes.setupProfile("verify"));
+ return;
+ }
+
+ try {
+ await completeSocialSignup(signupEmail, code);
+ setIsLiveSignupVerification(false);
+ void router.push(socialRoutes.setupProfile("verify"));
+ } catch (error) {
+ console.error("Social signup verification failed", error);
+ }
+ };
+
+ if (!signupEmail) {
+ return <SocialRouteFallback background={verifyEmailBackground} />;
+ }
+
+ return (
+ <>
+ <SocialPageMeta themeColor={verifyEmailBackground} />
+ <VerifyEmailScreen
+ email={signupEmail}
+ initialCode={isLiveSignupVerification ? "" : undefined}
+ onBack={() => void router.push(socialRoutes.signup)}
+ onChangeEmail={() => void router.push(socialRoutes.signup)}
+ onResendCode={
+ isLiveSignupVerification
+ ? () => void resendSocialSignupCode(signupEmail)
+ : undefined
+ }
+ onVerify={(code) => void verifySignupEmail(code)}
+ />
+ </>
+ );
+};
+
+export default Page;
diff --git a/web/apps/social/src/state/SocialAppStateProvider.tsx b/web/apps/social/src/state/SocialAppStateProvider.tsx
new file mode 100644
index 0000000000..dbdbf03d3e
--- /dev/null
+++ b/web/apps/social/src/state/SocialAppStateProvider.tsx
@@ -0,0 +1,56 @@
+import React, { useCallback, useMemo, useState } from "react";
+import type { SetupProfile } from "screens/SetupProfileScreen";
+import {
+ type OnboardingEntrySource,
+ type SocialAppState,
+ SocialAppStateContext,
+ initialFriends,
+} from "state/socialAppState";
+
+export const SocialAppStateProvider: React.FC<React.PropsWithChildren> = ({
+ children,
+}) => {
+ const [friends, setFriends] = useState(initialFriends);
+ const [isLiveSignupVerification, setIsLiveSignupVerification] =
+ useState(false);
+ const [onboardingEntrySource, setOnboardingEntrySource] =
+ useState<OnboardingEntrySource>("direct");
+ const [profile, setProfile] = useState<SetupProfile | null>(null);
+ const [signupEmail, setSignupEmail] = useState("");
+
+ const resetAfterLogout = useCallback(() => {
+ setProfile(null);
+ setOnboardingEntrySource("direct");
+ setFriends(initialFriends());
+ }, []);
+
+ const value = useMemo<SocialAppState>(
+ () => ({
+ friends,
+ isLiveSignupVerification,
+ onboardingEntrySource,
+ profile,
+ resetAfterLogout,
+ setFriends,
+ setIsLiveSignupVerification,
+ setOnboardingEntrySource,
+ setProfile,
+ setSignupEmail,
+ signupEmail,
+ }),
+ [
+ friends,
+ isLiveSignupVerification,
+ onboardingEntrySource,
+ profile,
+ resetAfterLogout,
+ signupEmail,
+ ],
+ );
+
+ return (
+ <SocialAppStateContext.Provider value={value}>
+ {children}
+ </SocialAppStateContext.Provider>
+ );
+};
diff --git a/web/apps/social/src/state/socialAppState.tsx b/web/apps/social/src/state/socialAppState.tsx
new file mode 100644
index 0000000000..0863556a65
--- /dev/null
+++ b/web/apps/social/src/state/socialAppState.tsx
@@ -0,0 +1,38 @@
+import { sampleFriends, type FriendProfile } from "data/friends";
+import React, { createContext, useContext } from "react";
+import type { SetupProfile } from "screens/SetupProfileScreen";
+
+export type OnboardingEntrySource = "direct" | "add-friend-link";
+
+export interface SocialAppState {
+ friends: FriendProfile[];
+ isLiveSignupVerification: boolean;
+ onboardingEntrySource: OnboardingEntrySource;
+ profile: SetupProfile | null;
+ signupEmail: string;
+ resetAfterLogout: () => void;
+ setFriends: React.Dispatch<React.SetStateAction<FriendProfile[]>>;
+ setIsLiveSignupVerification: React.Dispatch<React.SetStateAction<boolean>>;
+ setOnboardingEntrySource: React.Dispatch<
+ React.SetStateAction<OnboardingEntrySource>
+ >;
+ setProfile: React.Dispatch<React.SetStateAction<SetupProfile | null>>;
+ setSignupEmail: React.Dispatch<React.SetStateAction<string>>;
+}
+
+export const showMockFriends =
+ process.env.NEXT_PUBLIC_HIDE_SOCIAL_MOCK_FRIENDS != "true";
+
+export const initialFriends = () => (showMockFriends ? sampleFriends : []);
+
+export const SocialAppStateContext = createContext<SocialAppState | null>(null);
+
+export const useSocialAppState = () => {
+ const context = useContext(SocialAppStateContext);
+ if (!context) {
+ throw new Error(
+ "useSocialAppState must be used within SocialAppStateProvider",
+ );
+ }
+ return context;
+};
diff --git a/web/apps/social/src/utils/socialRoutes.ts b/web/apps/social/src/utils/socialRoutes.ts
new file mode 100644
index 0000000000..5688a4c9af
--- /dev/null
+++ b/web/apps/social/src/utils/socialRoutes.ts
@@ -0,0 +1,49 @@
+export type SetupProfileSource = "login" | "verify";
+export type FriendProfileSource =
+ | "friends"
+ | "home"
+ | "notifications"
+ | "profile";
+
+export const onboardingSourceSearchParam = "onboardingSource";
+export const addFriendLinkOnboardingSource = "add-friend-link";
+
+const valueFromQuery = (value: string | string[] | undefined) =>
+ Array.isArray(value) ? value[0] : value;
+
+export const socialRoutes = {
+ friend: (friendID: string, from: FriendProfileSource) =>
+ `/app/friend?friendID=${encodeURIComponent(friendID)}&from=${from}`,
+ friends: "/app/friends",
+ home: "/app",
+ invite: "/invite",
+ login: "/login",
+ notifications: "/app/notifications",
+ onboarding: "/",
+ profile: "/app/profile",
+ settings: "/app/settings",
+ setupProfile: (from: SetupProfileSource = "verify") =>
+ `/setup-profile?from=${from}`,
+ signup: "/signup",
+ verify: "/verify",
+} as const;
+
+export const setupProfileSourceFromQuery = (
+ value: string | string[] | undefined,
+): SetupProfileSource =>
+ valueFromQuery(value) == "login" ? "login" : "verify";
+
+export const friendProfileSourceFromQuery = (
+ value: string | string[] | undefined,
+): FriendProfileSource => {
+ const from = valueFromQuery(value);
+ return from == "home" ||
+ from == "notifications" ||
+ from == "profile" ||
+ from == "friends"
+ ? from
+ : "friends";
+};
+
+export const friendIDFromQuery = (value: string | string[] | undefined) =>
+ valueFromQuery(value) ?? "";