From 72553e429b5233f1bb52e3f905d08091fe906a44 Mon Sep 17 00:00:00 2001 From: Rodrigo <56604262+rodrigo-fm@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:25:49 -0300 Subject: [PATCH] Adds a loading skeleton to posts, comments and trending communities (#2311) * creates the initial loading skeleton for the home page * initial setup for the trending communities loading skeleton * adds posts loading skeleton to the community page * finishes the creation of all loading skeletons for large devices * finishes loading skeleton for smaller screens * removes unecessary code for the loading skeleton * [loading skeleton] removes unecessary mock code * [loading skeleton] removes custom css classes and adds more bootstrap css classes on the skeleton loading * replaces custom styles with bootstrap classes * rendes only one component for desktop and mobile screens Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> * fixes lint's indentation problems * transforms span tags into self-closing tags * removes every inline style from the loading-skeleton.tsx file --------- Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> --- lemmy-translations | 2 +- .../components/common/loading-skeleton.tsx | 118 ++++++++++++++++++ src/shared/components/community/community.tsx | 16 +-- src/shared/components/home/home.tsx | 25 ++-- src/shared/components/person/inbox.tsx | 25 +--- 5 files changed, 139 insertions(+), 47 deletions(-) create mode 100644 src/shared/components/common/loading-skeleton.tsx diff --git a/lemmy-translations b/lemmy-translations index b4c63029e..62c841802 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit b4c63029e598c022a04fc21acb45855645bd6794 +Subproject commit 62c8418021bc39543c87b4ae3dcf2419d13f61e0 diff --git a/src/shared/components/common/loading-skeleton.tsx b/src/shared/components/common/loading-skeleton.tsx new file mode 100644 index 000000000..ab146b8a9 --- /dev/null +++ b/src/shared/components/common/loading-skeleton.tsx @@ -0,0 +1,118 @@ +import { Component } from "inferno"; + +interface LoadingSkeletonProps { + itemCount?: number; +} + +interface LoadingSkeletonLineProps { + size: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; +} + +class LoadingSkeletonLine extends Component { + render() { + const className = "placeholder placeholder-lg col-" + this.props.size; + return ( +

+ +

+ ); + } +} + +export class PostsLoadingSkeleton extends Component { + render() { + return Array.from({ length: this.props.itemCount ?? 10 }, (_, index) => ( + + )); + } +} + +class PostThumbnailLoadingSkeleton extends Component { + render() { + return ( +
+ +
+ ); + } +} + +class PostsLoadingSkeletonItem extends Component { + render() { + return ( +
+
+
+
+ +
+
+ + + +
+
+
+
+ ); + } +} + +export class TrendingCommunitiesLoadingSkeleton extends Component< + LoadingSkeletonProps, + any +> { + render() { + return ( +
+ {Array.from({ length: this.props.itemCount ?? 10 }, (_, index) => ( + + ))} +
+ ); + } +} + +class TrendingCommunitiesLoadingSkeletonItem extends Component { + render() { + return ( +
+
+
+
+ +
+
+
+ +
+
+
+ ); + } +} + +export class CommentsLoadingSkeleton extends Component { + render() { + return Array.from({ length: this.props.itemCount ?? 10 }, (_, index) => ( + + )); + } +} + +class CommentsLoadingSkeletonItem extends Component { + render() { + return ( +
+
+
+ + + + +
+
+
+ ); + } +} diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 195de1fec..8f9c87648 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -100,6 +100,10 @@ import { PostListings } from "../post/post-listings"; import { CommunityLink } from "./community-link"; import { PaginatorCursor } from "../common/paginator-cursor"; import { getHttpBaseInternal } from "../../utils/env"; +import { + CommentsLoadingSkeleton, + PostsLoadingSkeleton, +} from "../common/loading-skeleton"; import { Sidebar } from "./sidebar"; import { IRoutePropsWithFetch } from "../../routes"; @@ -435,11 +439,7 @@ export class Community extends Component { if (dataType === DataType.Post) { switch (this.state.postsRes.state) { case "loading": - return ( -
- -
- ); + return ; case "success": return ( { } else { switch (this.state.commentsRes.state) { case "loading": - return ( -
- -
- ); + return ; case "success": return ( { trendingCommunities() { switch (this.state.trendingCommunitiesRes?.state) { case "loading": - return ( -
- -
- ); + return ; case "success": { const trending = this.state.trendingCommunitiesRes.data.communities; return ( @@ -704,11 +705,7 @@ export class Home extends Component { case "empty": return
; case "loading": - return ( -
- -
- ); + return ; case "success": { const posts = this.state.postsRes.data.posts; return ( @@ -744,11 +741,7 @@ export class Home extends Component { } else { switch (this.state.commentsRes.state) { case "loading": - return ( -
- -
- ); + return ; case "success": { const comments = this.state.commentsRes.data.comments; return ( diff --git a/src/shared/components/person/inbox.tsx b/src/shared/components/person/inbox.tsx index 26b8a7e09..239e33407 100644 --- a/src/shared/components/person/inbox.tsx +++ b/src/shared/components/person/inbox.tsx @@ -80,6 +80,7 @@ import { Icon, Spinner } from "../common/icon"; import { Paginator } from "../common/paginator"; import { PrivateMessage } from "../private_message/private-message"; import { getHttpBaseInternal } from "../../utils/env"; +import { CommentsLoadingSkeleton } from "../common/loading-skeleton"; import { RouteComponentProps } from "inferno-router/dist/Route"; import { IRoutePropsWithFetch } from "../../routes"; @@ -583,11 +584,7 @@ export class Inbox extends Component { this.state.mentionsRes.state === "loading" || this.state.messagesRes.state === "loading" ) { - return ( -

- -

- ); + return ; } else { return (
{this.buildCombined().map(r => this.renderReplyType(r))}
@@ -598,11 +595,7 @@ export class Inbox extends Component { replies() { switch (this.state.repliesRes.state) { case "loading": - return ( -

- -

- ); + return ; case "success": { const replies = this.state.repliesRes.data.replies; return ( @@ -645,11 +638,7 @@ export class Inbox extends Component { mentions() { switch (this.state.mentionsRes.state) { case "loading": - return ( -

- -

- ); + return ; case "success": { const mentions = this.state.mentionsRes.data.mentions; return ( @@ -695,11 +684,7 @@ export class Inbox extends Component { messages() { switch (this.state.messagesRes.state) { case "loading": - return ( -

- -

- ); + return ; case "success": { const messages = this.state.messagesRes.data.private_messages; return (