Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine social loading states

Anand Baburajane6d79d992867
diff --git a/web/apps/social/src/components/SocialRouteFallback.tsx b/web/apps/social/src/components/SocialRouteFallback.tsx
index b64cd83216..cd341ce1c4 100644
--- a/web/apps/social/src/components/SocialRouteFallback.tsx
+++ b/web/apps/social/src/components/SocialRouteFallback.tsx
@@ -19,11 +19,11 @@ export const SocialLoadingSpinner: React.FC<SocialLoadingSpinnerProps> = ({
aria-label={ariaLabel}
sx={{
animation: "socialRouteFallbackSpin 800ms linear infinite",
- border: "3px solid rgba(8, 194, 37, 0.18)",
+ border: "2px solid rgba(8, 194, 37, 0.18)",
borderRadius: "50%",
borderTopColor: "#08C225",
- height: 32,
- width: 32,
+ height: 26,
+ width: 26,
"@keyframes socialRouteFallbackSpin": {
to: { transform: "rotate(360deg)" },
},
diff --git a/web/apps/social/src/pages/app/index.tsx b/web/apps/social/src/pages/app/index.tsx
index 83c89a51da..0460945e60 100644
--- a/web/apps/social/src/pages/app/index.tsx
+++ b/web/apps/social/src/pages/app/index.tsx
@@ -18,6 +18,12 @@ import { firstNameFrom } from "utils/socialDisplay";
import { socialRoutes } from "utils/socialRoutes";
import { socialPostToViewerPhoto } from "utils/socialWallDisplay";
+const loadingHomeProfile = {
+ avatarUrl: null,
+ fullName: "",
+ username: "",
+};
+
const Page: React.FC = () => {
const router = useRouter();
const { friends, profile, profileLoadStatus, setFriends } =
@@ -80,10 +86,12 @@ const Page: React.FC = () => {
};
}, [profile?.wallId, profileLoadStatus, setFriends]);
- if (profileLoadStatus == "loading" || !profile || isFeedLoading) {
+ if (profileLoadStatus == "ready" && !profile) {
return <SocialRouteFallback background={homeBackground} />;
}
+ const screenProfile = profile ?? loadingHomeProfile;
+
return (
<>
<SocialPageMeta themeColor={homeBackground} />
@@ -92,10 +100,10 @@ const Page: React.FC = () => {
friendsCount={friends.length}
addedFriendToastName={addedFriendToastName}
isFeedLoading={isFeedLoading}
- profile={profile}
+ profile={screenProfile}
onAddedFriendToastClose={closeAddedFriendToast}
onCreatePost={async (file, caption) => {
- if (!profile.wallId) throw new Error("Missing wall.");
+ if (!profile?.wallId) throw new Error("Missing wall.");
const post = await createCurrentPhotoPost({
caption,
file,
@@ -115,7 +123,7 @@ const Page: React.FC = () => {
onLoadPostLikers={loadCurrentPostLikers}
onSetPostLiked={setCurrentPostLiked}
onShareProfileLink={async () => {
- if (!profile.wallId) throw new Error("Missing wall.");
+ if (!profile?.wallId) throw new Error("Missing wall.");
return (await createCurrentProfileLink(profile.wallId)).url;
}}
/>
diff --git a/web/apps/social/src/pages/app/notifications.tsx b/web/apps/social/src/pages/app/notifications.tsx
index 944424dc64..6a857acc26 100644
--- a/web/apps/social/src/pages/app/notifications.tsx
+++ b/web/apps/social/src/pages/app/notifications.tsx
@@ -22,6 +22,7 @@ const Page: React.FC = () => {
const [notifications, setNotifications] = useState<
SocialWallNotification[]
>([]);
+ const [isNotificationsLoading, setIsNotificationsLoading] = useState(true);
const screenNotifications = useMemo(
() => notifications.map(notificationForScreen),
[notifications],
@@ -36,11 +37,23 @@ const Page: React.FC = () => {
useEffect(() => {
if (!profile) return;
+ let cancelled = false;
+ setIsNotificationsLoading(true);
void loadCurrentNotificationsPage()
- .then((page) => setNotifications(page.items))
+ .then((page) => {
+ if (cancelled) return;
+ setNotifications(page.items);
+ })
.catch((error: unknown) =>
console.error("Failed to load notifications", error),
- );
+ )
+ .finally(() => {
+ if (!cancelled) setIsNotificationsLoading(false);
+ });
+
+ return () => {
+ cancelled = true;
+ };
}, [profile]);
if (profileLoadStatus == "loading" || !profile) {
@@ -51,6 +64,7 @@ const Page: React.FC = () => {
<>
<SocialPageMeta themeColor={notificationsBackground} />
<NotificationsScreen
+ isNotificationsLoading={isNotificationsLoading}
notifications={screenNotifications}
onBack={() => void router.push(socialRoutes.home)}
onOpenFriend={(friendID) =>
diff --git a/web/apps/social/src/pages/app/profile.tsx b/web/apps/social/src/pages/app/profile.tsx
index f031f66f9a..22fe1b4518 100644
--- a/web/apps/social/src/pages/app/profile.tsx
+++ b/web/apps/social/src/pages/app/profile.tsx
@@ -25,7 +25,7 @@ const Page: React.FC = () => {
const { friends, profile, profileLoadStatus, setFriends } =
useSocialAppState();
const [posts, setPosts] = useState<SocialWallPost[]>([]);
- const [isPostsLoading, setIsPostsLoading] = useState(false);
+ const [isPostsLoading, setIsPostsLoading] = useState(true);
const postGroups = useMemo(() => profilePostGroupsFromPosts(posts), [posts]);
useEffect(() => {
@@ -35,13 +35,19 @@ const Page: React.FC = () => {
}, [profile, profileLoadStatus, router]);
useEffect(() => {
- if (!profile?.wallId) return;
+ if (profileLoadStatus == "loading") return;
+
+ const wallId = profile?.wallId;
+ if (!wallId) {
+ setIsPostsLoading(false);
+ return;
+ }
let cancelled = false;
setIsPostsLoading(true);
void Promise.all([
- loadCurrentWallPostsPage(profile.wallId),
- loadCurrentWallFriends(profile.wallId),
+ loadCurrentWallPostsPage(wallId),
+ loadCurrentWallFriends(wallId),
])
.then(([page, nextFriends]) => {
if (cancelled) return;
@@ -58,7 +64,7 @@ const Page: React.FC = () => {
return () => {
cancelled = true;
};
- }, [profile?.wallId, setFriends]);
+ }, [profile?.wallId, profileLoadStatus, setFriends]);
if (profileLoadStatus == "loading" || !profile) {
return <SocialRouteFallback background={profileBackground} />;
diff --git a/web/apps/social/src/screens/NotificationsScreen.tsx b/web/apps/social/src/screens/NotificationsScreen.tsx
index ea8405372b..ebb44e0372 100644
--- a/web/apps/social/src/screens/NotificationsScreen.tsx
+++ b/web/apps/social/src/screens/NotificationsScreen.tsx
@@ -6,6 +6,7 @@ import {
type SocialLiker,
type SocialViewerPhoto,
} from "components/SocialFileViewer";
+import { SocialLoadingSpinner } from "components/SocialRouteFallback";
import type { FriendProfile } from "data/friends";
import { formatTimeAgo } from "ente-base/date";
import React from "react";
@@ -39,6 +40,7 @@ interface SocialNotification {
}
interface NotificationsScreenProps {
+ isNotificationsLoading?: boolean;
onBack?: () => void;
onOpenFriend?: (friendID: string) => void;
profile: SetupProfile;
@@ -341,6 +343,7 @@ const NotificationRow: React.FC<NotificationRowProps> = ({
};
export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({
+ isNotificationsLoading = false,
notifications,
onBack,
onLoadPostLikers,
@@ -472,6 +475,22 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({
/>
))}
</Box>
+ ) : isNotificationsLoading ? (
+ <Box
+ sx={{
+ alignItems: "center",
+ boxSizing: "border-box",
+ display: "flex",
+ inset: 0,
+ justifyContent: "center",
+ pointerEvents: "none",
+ position: "absolute",
+ px: 3,
+ textAlign: "center",
+ }}
+ >
+ <SocialLoadingSpinner ariaLabel="Loading notifications" />
+ </Box>
) : (
<Box
sx={{
@@ -516,7 +535,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({
maxWidth: 240,
}}
>
- Likes and replies on your posts will appear here.
+ Likes, replies and new friends will appear here.
</Box>
</Box>
)}
diff --git a/web/apps/social/src/screens/ProfileScreen.tsx b/web/apps/social/src/screens/ProfileScreen.tsx
index 39852e53b6..8f2c9e3e95 100644
--- a/web/apps/social/src/screens/ProfileScreen.tsx
+++ b/web/apps/social/src/screens/ProfileScreen.tsx
@@ -13,6 +13,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";
@@ -1118,78 +1119,84 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
width: "100%",
}}
>
- {isOwnerProfile && (
- <Box
- component="img"
- alt=""
- src="/images/ducky-camera.svg"
- sx={{
- display: "block",
- height: "auto",
- mt: "28px",
- width: 160,
- }}
- />
- )}
- <Box
- component="p"
- sx={{
- color: textSoft,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 500,
- lineHeight: "20px",
- m: 0,
- mt: isOwnerProfile ? "30px" : 0,
- maxWidth: isOwnerProfile ? 230 : 250,
- }}
- >
- {isPostsLoading
- ? "Loading posts..."
- : isOwnerProfile
- ? "Your profile is looking empty. Share something with your friends."
- : `${firstName} hasn't posted anything yet.`}
- </Box>
- {isOwnerProfile && !isPostsLoading && (
- <Box
- component="button"
- type="button"
- aria-label="Post photo"
- onClick={openPostPhotoPicker}
- sx={{
- appearance: "none",
- alignItems: "center",
- bgcolor: "transparent",
- border: 0,
- boxSizing: "border-box",
- color: textBase,
- cursor: "pointer",
- display: "flex",
- fontSize: 0,
- height: 32,
- justifyContent: "center",
- lineHeight: 0,
- mt: "26px",
- p: 0,
- pointerEvents: "auto",
- placeSelf: "center",
- placeItems: "center",
- width: 32,
- "& svg": { display: "block" },
- "&:focus-visible": {
- borderRadius: "6px",
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- }}
- >
- <HugeiconsIcon
- icon={AddSquareIcon}
- size={28}
- strokeWidth={1.8}
- />
- </Box>
+ {isPostsLoading ? (
+ <SocialLoadingSpinner ariaLabel="Loading posts" />
+ ) : (
+ <>
+ {isOwnerProfile && (
+ <Box
+ component="img"
+ alt=""
+ src="/images/ducky-camera.svg"
+ sx={{
+ display: "block",
+ height: "auto",
+ mt: "28px",
+ width: 160,
+ }}
+ />
+ )}
+ <Box
+ component="p"
+ sx={{
+ color: textSoft,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ m: 0,
+ mt: isOwnerProfile ? "30px" : 0,
+ maxWidth: isOwnerProfile
+ ? 230
+ : 250,
+ }}
+ >
+ {isOwnerProfile
+ ? "Your profile is looking empty. Share something with your friends."
+ : `${firstName} hasn't posted anything yet.`}
+ </Box>
+ {isOwnerProfile && (
+ <Box
+ component="button"
+ type="button"
+ aria-label="Post photo"
+ onClick={openPostPhotoPicker}
+ sx={{
+ appearance: "none",
+ alignItems: "center",
+ bgcolor: "transparent",
+ border: 0,
+ boxSizing: "border-box",
+ color: textBase,
+ cursor: "pointer",
+ display: "flex",
+ fontSize: 0,
+ height: 32,
+ justifyContent: "center",
+ lineHeight: 0,
+ mt: "26px",
+ p: 0,
+ pointerEvents: "auto",
+ placeSelf: "center",
+ placeItems: "center",
+ width: 32,
+ "& svg": { display: "block" },
+ "&:focus-visible": {
+ borderRadius: "6px",
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ }}
+ >
+ <HugeiconsIcon
+ icon={AddSquareIcon}
+ size={28}
+ strokeWidth={1.8}
+ />
+ </Box>
+ )}
+ </>
)}
</Box>
)}