Skip to content

Commit

Permalink
ue loader component
Browse files Browse the repository at this point in the history
  • Loading branch information
KRRISH96 committed Feb 25, 2021
1 parent e52532a commit c067f61
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/components/PostDetails/Comments.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { useFetch } from '../../hooks/useFetch';
import Loader from '../Loader/Loader';

interface Props {
postId: number;
Expand All @@ -26,8 +27,8 @@ function Comments({ postId }: Props) {

return (
<div className="comments-container">
<h4>Comments ({comments?.length ?? 0})</h4>
{loading && <h4>Fetching Comments... Hang Tight!</h4>}
<h4>Comments</h4>
{comments != null && (
<ul className="comments-list">
{comments.map(({ postId, id, name, body }) => (
Expand All @@ -36,7 +37,7 @@ function Comments({ postId }: Props) {
<p className="comment">{body}</p>
</li>
))}
{!comments.length && <li>No Comments Yet</li>}
{!loading && !comments.length && <li>No Comments Yet</li>}
</ul>
)}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/PostDetails/PostDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useParams, useHistory, Link } from 'react-router-dom';
import { API_BASE_URL } from '../../constants';
import { useFetch } from '../../hooks/useFetch';
import BackButton from '../BackButton';
import Loader from '../Loader/Loader';
import { PostData } from '../Posts/Posts';
import TextHighlighter from '../TextHighlighter';
import Comments from './Comments';
Expand Down Expand Up @@ -70,7 +71,7 @@ function PostDetails() {
<button onClick={() => setSearchText('')}>x clear search term</button>
)}
</div>
{loading && <h2>Fetching Post Details... Hang Tight!</h2>}
{loading && <Loader statusText="Fetching Post Details..." />}
<article className="post-content card">
<h2 className="post-content__title">
<TextHighlighter
Expand Down
3 changes: 2 additions & 1 deletion src/components/Posts/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DEFAULT_COUNT_PER_PAGE, DEFAULT_PAGE } from '../../constants';
import Pagination from '../Pagination/Pagination';
import PostsList from './PostsList';
import './postsStyles.scss';
import Loader from '../Loader/Loader';

export interface PostData {
userId: number;
Expand Down Expand Up @@ -122,7 +123,7 @@ function Posts() {
<button onClick={clearFilters}>x clear filters</button>
)}
</div>
{loading && <h2>Fetching Posts... Sit Tight!</h2>}
{loading && <Loader statusText="Fetching Posts..." />}
<PostsList posts={filteredPosts} titleFilter={titleFilter} />
<Pagination
page={Number(paginationQueryParams.page)}
Expand Down

0 comments on commit c067f61

Please sign in to comment.