π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add social friend toast
Anand Baburajan0a991ac16f31
diff --git a/web/apps/social/src/components/SocialRouteFallback.tsx b/web/apps/social/src/components/SocialRouteFallback.tsxindex ecb17a47e4..b64cd83216 100644--- a/web/apps/social/src/components/SocialRouteFallback.tsx+++ b/web/apps/social/src/components/SocialRouteFallback.tsx@@ -6,6 +6,31 @@ interface SocialRouteFallbackProps {background: string;}+interface SocialLoadingSpinnerProps {+ ariaLabel?: string;+}++export const SocialLoadingSpinner: React.FC<SocialLoadingSpinnerProps> = ({+ ariaLabel = "Loading",+}) => (+ <Box+ component="span"+ role="status"+ aria-label={ariaLabel}+ sx={{+ animation: "socialRouteFallbackSpin 800ms linear infinite",+ border: "3px solid rgba(8, 194, 37, 0.18)",+ borderRadius: "50%",+ borderTopColor: "#08C225",+ height: 32,+ width: 32,+ "@keyframes socialRouteFallbackSpin": {+ to: { transform: "rotate(360deg)" },+ },+ }}+ />+);+export const SocialRouteFallback: React.FC<SocialRouteFallbackProps> = ({background,}) => (@@ -19,22 +44,7 @@ export const SocialRouteFallback: React.FC<SocialRouteFallbackProps> = ({placeItems: "center",}}>- <Box- component="span"- role="status"- aria-label="Loading"- sx={{- animation: "socialRouteFallbackSpin 800ms linear infinite",- border: "3px solid rgba(8, 194, 37, 0.18)",- borderRadius: "50%",- borderTopColor: "#08C225",- height: 32,- width: 32,- "@keyframes socialRouteFallbackSpin": {- to: { transform: "rotate(360deg)" },- },- }}- />+ <SocialLoadingSpinner /></Box></>);diff --git a/web/apps/social/src/pages/app/index.tsx b/web/apps/social/src/pages/app/index.tsxindex 779894447b..83c89a51da 100644--- a/web/apps/social/src/pages/app/index.tsx+++ b/web/apps/social/src/pages/app/index.tsx@@ -3,6 +3,7 @@ import { SocialRouteFallback } from "components/SocialRouteFallback";import { useRouter } from "next/router";import React, { useEffect, useState } from "react";import { HomeScreen, homeBackground } from "screens/HomeScreen";+import { consumeAcceptedSocialInviteFriend } from "services/socialInvite";import {createCurrentPhotoPost,createCurrentProfileLink,@@ -13,6 +14,7 @@ import {type SocialWallPost,} from "services/socialWall";import { useSocialAppState } from "state/socialAppState";+import { firstNameFrom } from "utils/socialDisplay";import { socialRoutes } from "utils/socialRoutes";import { socialPostToViewerPhoto } from "utils/socialWallDisplay";@@ -20,8 +22,14 @@ const Page: React.FC = () => {const router = useRouter();const { friends, profile, profileLoadStatus, setFriends } =useSocialAppState();+ const [addedFriendToastName, setAddedFriendToastName] =+ useState<string>();const [feedItems, setFeedItems] = useState<SocialWallPost[]>([]);- const [isFeedLoading, setIsFeedLoading] = useState(false);+ const [isFeedLoading, setIsFeedLoading] = useState(true);+ const closeAddedFriendToast = React.useCallback(+ () => setAddedFriendToastName(undefined),+ [],+ );useEffect(() => {if (profileLoadStatus == "ready" && !profile) {@@ -30,13 +38,30 @@ const Page: React.FC = () => {}, [profile, profileLoadStatus, router]);useEffect(() => {- if (!profile?.wallId) return;+ if (!router.isReady) return;++ const acceptedFriend = consumeAcceptedSocialInviteFriend();+ if (!acceptedFriend) return;++ const displayName =+ acceptedFriend.fullName.trim() || acceptedFriend.username.trim();+ setAddedFriendToastName(firstNameFrom(displayName) || displayName);+ }, [router.isReady]);++ useEffect(() => {+ if (profileLoadStatus == "loading") return;++ const wallId = profile?.wallId;+ if (!wallId) {+ setIsFeedLoading(false);+ return;+ }let cancelled = false;setIsFeedLoading(true);void Promise.all([loadCurrentFeedPage(),- loadCurrentWallFriends(profile.wallId),+ loadCurrentWallFriends(wallId),]).then(([feed, nextFriends]) => {if (cancelled) return;@@ -53,9 +78,9 @@ const Page: React.FC = () => {return () => {cancelled = true;};- }, [profile?.wallId, setFriends]);+ }, [profile?.wallId, profileLoadStatus, setFriends]);- if (profileLoadStatus == "loading" || !profile) {+ if (profileLoadStatus == "loading" || !profile || isFeedLoading) {return <SocialRouteFallback background={homeBackground} />;}@@ -65,8 +90,10 @@ const Page: React.FC = () => {<HomeScreenfeedItems={feedItems}friendsCount={friends.length}+ addedFriendToastName={addedFriendToastName}isFeedLoading={isFeedLoading}profile={profile}+ onAddedFriendToastClose={closeAddedFriendToast}onCreatePost={async (file, caption) => {if (!profile.wallId) throw new Error("Missing wall.");const post = await createCurrentPhotoPost({diff --git a/web/apps/social/src/pages/index.tsx b/web/apps/social/src/pages/index.tsxindex e0a7cdf818..3189a26b9e 100644--- a/web/apps/social/src/pages/index.tsx+++ b/web/apps/social/src/pages/index.tsx@@ -14,7 +14,10 @@ import { PublicProfileScreen } from "screens/PublicProfileScreen";import type { SetupProfile } from "screens/SetupProfileScreen";import {clearPendingSocialInvite,+ clearPendingSocialInviteFriend,+ saveAcceptedSocialInviteFriend,savePendingSocialInvite,+ savePendingSocialInviteFriend,socialInviteFromLocation,type PendingSocialInvite,} from "services/socialInvite";@@ -24,8 +27,8 @@ import {type SocialWallPost,} from "services/socialWall";import {- type OnboardingEntrySource,useSocialAppState,+ type OnboardingEntrySource,} from "state/socialAppState";import {addFriendLinkOnboardingSource,@@ -210,12 +213,22 @@ const Page: React.FC = () => {postGroups={publicPostGroups}profile={publicProfile}onAddFriend={() => {+ const inviteFriend = {+ fullName: publicProfile.fullName,+ username: publicProfile.username,+ };+savePendingSocialInvite(routeMode);+ savePendingSocialInviteFriend(inviteFriend);setOnboardingEntrySource("add-friend-link");if (profile) {void joinSocialInvite(routeMode).then(() => {clearPendingSocialInvite();+ clearPendingSocialInviteFriend();+ saveAcceptedSocialInviteFriend(+ inviteFriend,+ );void router.push(socialRoutes.home);}).catch((error: unknown) =>diff --git a/web/apps/social/src/pages/setup-profile.tsx b/web/apps/social/src/pages/setup-profile.tsxindex eb7de30702..9d1282029d 100644--- a/web/apps/social/src/pages/setup-profile.tsx+++ b/web/apps/social/src/pages/setup-profile.tsx@@ -8,7 +8,10 @@ import {} from "screens/SetupProfileScreen";import {clearPendingSocialInvite,+ clearPendingSocialInviteFriend,+ saveAcceptedSocialInviteFriend,savedPendingSocialInvite,+ savedPendingSocialInviteFriend,} from "services/socialInvite";import {saveSocialProfile,@@ -50,8 +53,14 @@ const Page: React.FC = () => {const pendingInvite = savedPendingSocialInvite();if (!pendingInvite) return;+ const pendingFriend = savedPendingSocialInviteFriend() ?? {+ fullName: "",+ username: pendingInvite.wallUsername,+ };await joinSocialInvite(pendingInvite);clearPendingSocialInvite();+ clearPendingSocialInviteFriend();+ saveAcceptedSocialInviteFriend(pendingFriend);}, []);useEffect(() => {diff --git a/web/apps/social/src/screens/HomeScreen.tsx b/web/apps/social/src/screens/HomeScreen.tsxindex da13b9ccc5..f9ab2ebfb8 100644--- a/web/apps/social/src/screens/HomeScreen.tsx+++ b/web/apps/social/src/screens/HomeScreen.tsx@@ -1,7 +1,9 @@import {AddSquareIcon,FavouriteIcon,+ MultiplicationSignIcon,NotificationIcon,+ UserCheck01Icon,} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box } from "@mui/material";@@ -12,6 +14,7 @@ import {type SocialViewerPhoto,type SocialViewerPostActionMode,} from "components/SocialFileViewer";+import { SocialLoadingSpinner } from "components/SocialRouteFallback";import { EnteLogo } from "ente-base/components/EnteLogo";import React, { useState } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";@@ -43,11 +46,14 @@ const headerIconSize = 23;const headerSideWidth = headerActionSize * 2 + headerActionGap;const feedLikeActionInset = 4;const feedLikeActionSize = 40;+const emptyFeedItemGap = "22px";interface HomeScreenProps {+ addedFriendToastName?: string;feedItems: SocialWallPost[];friendsCount: number;isFeedLoading?: boolean;+ onAddedFriendToastClose?: () => void;onCreatePost?: (file: File, caption: string) => Promise<SocialViewerPhoto>;onOpenFriend?: (friendID: string) => void;onOpenNotifications?: () => void;@@ -89,6 +95,11 @@ interface FeedItemProps {viewerLiked: boolean;}+interface AddedFriendToastProps {+ name: string;+ onClose?: () => void;+}+const dimensionsFromAspectRatio = (aspectRatio: number,): FeedPhotoDimensions => {@@ -165,9 +176,7 @@ const FeedItem: React.FC<FeedItemProps> = ({setIsLikeButtonPopping(true);const nextLiked = !isLiked;setIsLiked(nextLiked);- setLocalLikeCount((count) =>- Math.max(0, count + (nextLiked ? 1 : -1)),- );+ setLocalLikeCount((count) => Math.max(0, count + (nextLiked ? 1 : -1)));void onSetPostLiked?.(postId, nextLiked).catch((error: unknown) => {console.error("Failed to update post like", error);setIsLiked(!nextLiked);@@ -420,10 +429,111 @@ const FeedItem: React.FC<FeedItemProps> = ({);};+const AddedFriendToast: React.FC<AddedFriendToastProps> = ({+ name,+ onClose,+}) => (+ <Box+ sx={{+ bottom: "calc(env(safe-area-inset-bottom) + 16px)",+ boxSizing: "border-box",+ left: "50%",+ maxWidth: 390,+ px: 2,+ pointerEvents: "none",+ position: "fixed",+ transform: "translateX(-50%)",+ width: "100%",+ zIndex: 20,+ }}+ >+ <Box+ className="green-bg"+ role="status"+ aria-live="polite"+ sx={{+ alignItems: "center",+ bgcolor: green,+ borderRadius: "18px",+ boxShadow: "0 12px 32px rgba(0, 0, 0, 0.18)",+ boxSizing: "border-box",+ color: "#FFFFFF",+ display: "flex",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 14,+ fontWeight: 650,+ gap: "10px",+ lineHeight: "20px",+ minHeight: 48,+ pointerEvents: "auto",+ pl: "16px",+ pr: "10px",+ py: "10px",+ width: "100%",+ }}+ >+ <Box component="span" sx={{ display: "flex", flexShrink: 0 }}>+ <HugeiconsIcon+ icon={UserCheck01Icon}+ size={20}+ strokeWidth={1.8}+ />+ </Box>+ <Box+ component="span"+ sx={{+ flex: "1 1 auto",+ minWidth: 0,+ overflow: "hidden",+ textOverflow: "ellipsis",+ whiteSpace: "nowrap",+ }}+ >+ You're now friends with {name}!+ </Box>+ <Box+ component="button"+ type="button"+ aria-label="Close"+ onClick={onClose}+ sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: "transparent",+ border: 0,+ borderRadius: "50%",+ color: "#FFFFFF",+ cursor: onClose ? "pointer" : "default",+ display: "flex",+ flexShrink: 0,+ height: 24,+ justifyContent: "center",+ opacity: 0.9,+ p: 0,+ width: 24,+ "&:focus-visible": {+ outline: "2px solid rgba(255 255 255 / 0.9)",+ outlineOffset: 2,+ },+ "&:hover": { bgcolor: "rgba(255, 255, 255, 0.12)" },+ }}+ >+ <HugeiconsIcon+ icon={MultiplicationSignIcon}+ size={16}+ strokeWidth={2}+ />+ </Box>+ </Box>+ </Box>+);+export const HomeScreen: React.FC<HomeScreenProps> = ({+ addedFriendToastName,feedItems,friendsCount,isFeedLoading = false,+ onAddedFriendToastClose,onCreatePost,onLoadPostLikers,onOpenFriend,@@ -439,12 +549,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());const selectedPhotoFriendID = selectedViewer?.photo.friendID;const hasFeedItems = feedItems.length > 0;+ const isEmptyFeedLoading = !hasFeedItems && isFeedLoading;const emptyFeedMessage =- isFeedLoading- ? "Loading posts..."- : friendsCount == 0- ? "When you add friends, their posts will appear here."- : "When your friends share posts, they'll appear here.";+ friendsCount == 0+ ? "When you add friends, their posts will appear here."+ : "When your friends share posts, they'll appear here.";const initialsSource = profile.fullName.trim() || profile.username.trim();const initials = initialsFor(initialsSource);const revokeLocalPostObjectUrl = React.useCallback((objectUrl?: string) => {@@ -786,6 +895,17 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({viewerLiked={item.viewerLiked}/>))+ ) : isEmptyFeedLoading ? (+ <Box+ sx={{+ alignItems: "center",+ display: "flex",+ justifyContent: "center",+ width: "100%",+ }}+ >+ <SocialLoadingSpinner ariaLabel="Loading posts" />+ </Box>) : (<Boxsx={{@@ -819,7 +939,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({fontWeight: 500,lineHeight: "20px",m: 0,- mt: "30px",+ mt: emptyFeedItemGap,maxWidth: 220,}}>@@ -846,7 +966,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({height: 36,justifyContent: "center",lineHeight: "18px",- mt: "30px",+ mt: emptyFeedItemGap,px: "14px",whiteSpace: "nowrap","&:focus-visible": {@@ -914,6 +1034,12 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({onSetPostLiked={onSetPostLiked}/>)}+ {addedFriendToastName && (+ <AddedFriendToast+ name={addedFriendToastName}+ onClose={onAddedFriendToastClose}+ />+ )}</Box></Box>);diff --git a/web/apps/social/src/screens/NotificationsScreen.tsx b/web/apps/social/src/screens/NotificationsScreen.tsxindex 77a4265320..ea8405372b 100644--- a/web/apps/social/src/screens/NotificationsScreen.tsx+++ b/web/apps/social/src/screens/NotificationsScreen.tsx@@ -516,7 +516,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({maxWidth: 240,}}>- Likes, replies and new friends will appear here.+ Likes and replies on your posts will appear here.</Box></Box>)}diff --git a/web/apps/social/src/services/socialInvite.ts b/web/apps/social/src/services/socialInvite.tsindex 520c9782b4..1e59118091 100644--- a/web/apps/social/src/services/socialInvite.ts+++ b/web/apps/social/src/services/socialInvite.ts@@ -3,10 +3,19 @@ export interface PendingSocialInvite {wallUsername: string;}+export interface SocialInviteFriendSummary {+ fullName: string;+ username: string;+}++const pendingSocialInviteFriendKey = "socialPendingInviteFriend";+const acceptedSocialInviteFriendKey = "socialAcceptedInviteFriend";const pendingSocialInviteKey = "socialPendingInvite";const socialInviteAccessKeyPattern = /^[0-9A-Za-z]{12}$/;-const isPendingSocialInvite = (value: unknown): value is PendingSocialInvite => {+const isPendingSocialInvite = (+ value: unknown,+): value is PendingSocialInvite => {if (!value || typeof value != "object") return false;const candidate = value as Record<string, unknown>;return (@@ -17,6 +26,38 @@ const isPendingSocialInvite = (value: unknown): value is PendingSocialInvite =>);};+const isSocialInviteFriendSummary = (+ value: unknown,+): value is SocialInviteFriendSummary => {+ if (!value || typeof value != "object") return false;+ const candidate = value as Record<string, unknown>;+ return (+ typeof candidate.fullName == "string" &&+ typeof candidate.username == "string" &&+ (candidate.fullName.trim().length > 0 ||+ candidate.username.trim().length > 0)+ );+};++const savedSocialInviteFriendSummary = (key: string) => {+ const saved = sessionStorage.getItem(key);+ if (!saved) return undefined;++ try {+ const parsed: unknown = JSON.parse(saved);+ return isSocialInviteFriendSummary(parsed) ? parsed : undefined;+ } catch {+ return undefined;+ }+};++const saveSocialInviteFriendSummary = (+ key: string,+ friend: SocialInviteFriendSummary,+) => {+ sessionStorage.setItem(key, JSON.stringify(friend));+};+export const savePendingSocialInvite = (invite: PendingSocialInvite) => {sessionStorage.setItem(pendingSocialInviteKey, JSON.stringify(invite));};@@ -37,6 +78,29 @@ export const clearPendingSocialInvite = () => {sessionStorage.removeItem(pendingSocialInviteKey);};+export const savePendingSocialInviteFriend = (+ friend: SocialInviteFriendSummary,+) => saveSocialInviteFriendSummary(pendingSocialInviteFriendKey, friend);++export const savedPendingSocialInviteFriend = () =>+ savedSocialInviteFriendSummary(pendingSocialInviteFriendKey);++export const clearPendingSocialInviteFriend = () => {+ sessionStorage.removeItem(pendingSocialInviteFriendKey);+};++export const saveAcceptedSocialInviteFriend = (+ friend: SocialInviteFriendSummary,+) => saveSocialInviteFriendSummary(acceptedSocialInviteFriendKey, friend);++export const consumeAcceptedSocialInviteFriend = () => {+ const friend = savedSocialInviteFriendSummary(+ acceptedSocialInviteFriendKey,+ );+ sessionStorage.removeItem(acceptedSocialInviteFriendKey);+ return friend;+};+export const socialInviteFromLocation = (): PendingSocialInvite | null => {const match = /^\/([^/]+)\/?$/.exec(window.location.pathname);const encodedAccessKey = window.location.hash.slice(1).trim();