Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix space home empty feed skeleton flash

Anand Baburajan6991178c9ae2
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 9a81577cf8..74c0d712f6 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -39,6 +39,8 @@ const Page: React.FC = () => {
profileLoadStatus,
setFriends,
setLocalFeedPosts,
+ setSkipNextHomeFeedSkeleton,
+ skipNextHomeFeedSkeleton,
} = useSpaceAppState();
const [addedFriendToastName, setAddedFriendToastName] = useState<string>();
const [feedItems, setFeedItems] = useState<SpacePost[]>([]);
@@ -54,6 +56,10 @@ const Page: React.FC = () => {
isFeedLoading &&
feedItems.length == 0 &&
localFeedPosts.length == 0;
+ const shouldDelayInitialFeedSkeleton =
+ isInitialFeedLoading && !skipNextHomeFeedSkeleton;
+ const isSkippingInitialFeedSkeleton =
+ isInitialFeedLoading && skipNextHomeFeedSkeleton;
const closeAddedFriendToast = React.useCallback(
() => setAddedFriendToastName(undefined),
[],
@@ -86,6 +92,7 @@ const Page: React.FC = () => {
setHasUnreadMessages(false);
setIsFeedLoading(false);
setIsFeedLoadingMore(false);
+ setSkipNextHomeFeedSkeleton(false);
return;
}
@@ -111,16 +118,24 @@ const Page: React.FC = () => {
console.error("Failed to load space home", error),
)
.finally(() => {
- if (!cancelled) setIsFeedLoading(false);
+ if (!cancelled) {
+ setIsFeedLoading(false);
+ setSkipNextHomeFeedSkeleton(false);
+ }
});
return () => {
cancelled = true;
};
- }, [profile?.spaceId, profileLoadStatus, setFriends]);
+ }, [
+ profile?.spaceId,
+ profileLoadStatus,
+ setFriends,
+ setSkipNextHomeFeedSkeleton,
+ ]);
useEffect(() => {
- if (!isInitialFeedLoading) {
+ if (!shouldDelayInitialFeedSkeleton) {
setShowInitialFeedSkeleton(false);
return;
}
@@ -130,7 +145,7 @@ const Page: React.FC = () => {
initialFeedSkeletonDelayMs,
);
return () => window.clearTimeout(timeoutID);
- }, [isInitialFeedLoading]);
+ }, [shouldDelayInitialFeedSkeleton]);
const loadMoreFeedItems = React.useCallback(async () => {
if (!feedNextCursor || isFeedLoadingMore) return;
@@ -174,7 +189,7 @@ const Page: React.FC = () => {
if (
profileLoadStatus != "ready" ||
!profile ||
- (isInitialFeedLoading && !showInitialFeedSkeleton)
+ (shouldDelayInitialFeedSkeleton && !showInitialFeedSkeleton)
) {
return (
<SpaceRouteFallback
@@ -193,7 +208,9 @@ const Page: React.FC = () => {
addedFriendToastName={addedFriendToastName}
hasUnreadMessages={hasUnreadMessages}
hasMoreFeedItems={Boolean(feedNextCursor)}
- isFeedLoading={isFeedLoading}
+ isFeedLoading={
+ isSkippingInitialFeedSkeleton ? false : isFeedLoading
+ }
isFeedLoadingMore={isFeedLoadingMore}
localFeedPosts={localFeedPosts}
profile={profile}
diff --git a/web/apps/space/src/pages/setup-profile.tsx b/web/apps/space/src/pages/setup-profile.tsx
index d18f75b6f5..5f06426867 100644
--- a/web/apps/space/src/pages/setup-profile.tsx
+++ b/web/apps/space/src/pages/setup-profile.tsx
@@ -32,6 +32,7 @@ const Page: React.FC = () => {
profileLoadStatus,
refreshProfile,
setProfile,
+ setSkipNextHomeFeedSkeleton,
} = useSpaceAppState();
const backSource = setupProfileSourceFromQuery(router.query.from);
const isAddFriendLinkOnboarding =
@@ -52,7 +53,7 @@ const Page: React.FC = () => {
const acceptPendingInvite = useCallback(async () => {
const pendingInvite = savedPendingSpaceInvite();
- if (!pendingInvite) return;
+ if (!pendingInvite) return false;
const pendingFriend = savedPendingSpaceInviteFriend() ?? {
fullName: "",
@@ -62,6 +63,7 @@ const Page: React.FC = () => {
clearPendingSpaceInvite();
clearPendingSpaceInviteFriend();
saveAcceptedSpaceInviteFriend(pendingFriend);
+ return true;
}, []);
useEffect(() => {
@@ -153,8 +155,11 @@ const Page: React.FC = () => {
try {
const savedProfile =
await saveSpaceProfile(nextProfile);
- await acceptPendingInvite();
+ const acceptedInvite = await acceptPendingInvite();
setProfile(savedProfile);
+ if (!acceptedInvite) {
+ setSkipNextHomeFeedSkeleton(true);
+ }
void router.push(
isAddFriendLinkOnboarding
? spaceRoutes.home
diff --git a/web/apps/space/src/state/SpaceAppStateProvider.tsx b/web/apps/space/src/state/SpaceAppStateProvider.tsx
index ab5340541e..9ce97b03c6 100644
--- a/web/apps/space/src/state/SpaceAppStateProvider.tsx
+++ b/web/apps/space/src/state/SpaceAppStateProvider.tsx
@@ -50,6 +50,8 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
const [profileLoadError, setProfileLoadError] = useState<string>();
const [profileLoadStatus, setProfileLoadStatus] =
useState<SpaceProfileLoadStatus>("loading");
+ const [skipNextHomeFeedSkeleton, setSkipNextHomeFeedSkeleton] =
+ useState(false);
const [signupEmail, setSignupEmail] = useState("");
const avatarURLRef = useRef<string | null>(null);
const coverURLRef = useRef<string | null>(null);
@@ -191,6 +193,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
setPendingProfileAvatarFile(null);
setPendingProfileCoverFile(null);
setOnboardingEntrySource("direct");
+ setSkipNextHomeFeedSkeleton(false);
setLocalFeedPosts([]);
setFriends(initialFriends());
}, [applyProfile]);
@@ -243,6 +246,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
profile,
profileLoadError,
profileLoadStatus,
+ skipNextHomeFeedSkeleton,
refreshProfile,
resetAfterLogout,
setFriends,
@@ -254,6 +258,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
setPendingProfileAvatarFile,
setPendingProfileCoverFile,
setProfile: applyProfile,
+ setSkipNextHomeFeedSkeleton,
setSignupEmail,
signupEmail,
}),
@@ -269,6 +274,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
profile,
profileLoadError,
profileLoadStatus,
+ skipNextHomeFeedSkeleton,
refreshProfile,
resetAfterLogout,
signupEmail,
diff --git a/web/apps/space/src/state/spaceAppState.tsx b/web/apps/space/src/state/spaceAppState.tsx
index c2a2fe2144..61937c9063 100644
--- a/web/apps/space/src/state/spaceAppState.tsx
+++ b/web/apps/space/src/state/spaceAppState.tsx
@@ -56,6 +56,7 @@ export interface SpaceAppState {
profile: SetupProfile | null;
profileLoadError?: string;
profileLoadStatus: SpaceProfileLoadStatus;
+ skipNextHomeFeedSkeleton: boolean;
signupEmail: string;
refreshProfile: () => Promise<SetupProfile | null>;
resetAfterLogout: () => void;
@@ -80,6 +81,7 @@ export interface SpaceAppState {
React.SetStateAction<File | null>
>;
setProfile: (profile: SetupProfile | null) => void;
+ setSkipNextHomeFeedSkeleton: React.Dispatch<React.SetStateAction<boolean>>;
setSignupEmail: React.Dispatch<React.SetStateAction<string>>;
}