Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix space profile empty-state skeleton flash

Anand Baburajand69023faa558
diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index 245b80e162..8dd5b7fd07 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -23,6 +23,8 @@ import { profilePostGroupsFromPosts } from "utils/spacePostDisplay";
import { prepareSpacePostImageFromEdit } from "utils/spacePostImage";
import { spaceRoutes } from "utils/spaceRoutes";
+const initialPostSkeletonDelayMs = 350;
+
const Page: React.FC = () => {
const router = useRouter();
const { profile, profileLoadError, profileLoadStatus, setLocalFeedPosts } =
@@ -30,10 +32,17 @@ const Page: React.FC = () => {
const [friendsCount, setFriendsCount] = useState(0);
const [posts, setPosts] = useState<SpaceProfilePost[]>([]);
const [isPostsLoading, setIsPostsLoading] = useState(true);
+ const [showInitialPostSkeleton, setShowInitialPostSkeleton] =
+ useState(false);
const postGroups = useMemo(
() => profilePostGroupsFromPosts(posts),
[posts],
);
+ const isInitialPostsLoading =
+ profileLoadStatus == "ready" &&
+ Boolean(profile?.spaceId) &&
+ isPostsLoading &&
+ posts.length == 0;
useEffect(() => {
if (profileLoadStatus == "ready" && !profile) {
@@ -74,6 +83,19 @@ const Page: React.FC = () => {
};
}, [profile?.spaceId, profileLoadStatus]);
+ useEffect(() => {
+ if (!isInitialPostsLoading) {
+ setShowInitialPostSkeleton(false);
+ return;
+ }
+
+ const timeoutID = window.setTimeout(
+ () => setShowInitialPostSkeleton(true),
+ initialPostSkeletonDelayMs,
+ );
+ return () => window.clearTimeout(timeoutID);
+ }, [isInitialPostsLoading]);
+
if (profileLoadStatus != "ready" || !profile) {
return (
<SpaceRouteFallback
@@ -92,6 +114,7 @@ const Page: React.FC = () => {
isStatsLoading={isPostsLoading}
postGroups={postGroups}
profile={profile}
+ showPostLoadingSkeleton={showInitialPostSkeleton}
onBack={() => void router.push(spaceRoutes.home)}
onCreatePost={async (image, caption) => {
const spaceId = profile.spaceId;
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 7876bf1eab..253a279cdd 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -386,6 +386,7 @@ interface ProfileScreenProps {
isCoverLoading?: boolean;
isPostsLoading?: boolean;
isStatsLoading?: boolean;
+ showPostLoadingSkeleton?: boolean;
onAddFriend?: () => void;
onBack?: () => void;
onCreatePost?: (
@@ -427,6 +428,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
onShareProfileLink,
postGroups = [],
profile,
+ showPostLoadingSkeleton,
}) => {
const [selectedPost, setSelectedPost] =
useState<SelectedProfilePost | null>(null);
@@ -478,7 +480,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const canOpenProfileCover = isOwnerProfile && Boolean(onOpenProfileCover);
const canOpenProfilePhoto = isOwnerProfile && Boolean(onOpenProfilePhoto);
const hasProfilePosts = postsSharedCount > 0;
- const shouldShowPostGrid = hasProfilePosts || isPostsLoading;
+ const shouldShowPostLoadingSkeleton =
+ isPostsLoading && (showPostLoadingSkeleton ?? true);
+ const shouldShowPostGrid = hasProfilePosts || shouldShowPostLoadingSkeleton;
const isCoverImageLoading = Boolean(coverUrl && loadedCoverUrl != coverUrl);
const shouldShowCoverSkeleton =
isCoverLoading || isCoverURLPending || isCoverImageLoading;
@@ -1510,9 +1514,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
</Box>
);
})
- ) : isPostsLoading ? (
+ ) : shouldShowPostLoadingSkeleton ? (
<ProfilePostLoadingSkeletons />
- ) : (
+ ) : isPostsLoading ? null : (
<Box
sx={{
alignItems: "center",