Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
hma-3 committed Oct 22, 2024
1 parent 8b7ce12 commit b4d934b
Show file tree
Hide file tree
Showing 24 changed files with 627 additions and 389 deletions.
4 changes: 0 additions & 4 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@
}
}
}

.message-body {
white-space: pre-line;
}
120 changes: 79 additions & 41 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,98 @@
import classNames from 'classnames';

import 'bulma/css/bulma.css';
import '@fortawesome/fontawesome-free/css/all.css';
import { useState } from 'react';
import cn from 'classnames';
import './App.scss';

import { User, Post } from './types';
import { getPosts } from './services';

import { PostsList } from './components/PostsList';
import { PostDetails } from './components/PostDetails';
import { UserSelector } from './components/UserSelector';
import { Loader } from './components/Loader';

export const App = () => (
<main className="section">
<div className="container">
<div className="tile is-ancestor">
<div className="tile is-parent">
<div className="tile is-child box is-success">
<div className="block">
<UserSelector />
</div>
export const App = () => {
const [selectedUser, setSelectedUser] = useState<User | null>(null);
const [posts, setPosts] = useState<Post[]>([]);
const [hasPostsLoadingError, setHasPostsLoadingError] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [selectedPost, setSelectedPost] = useState<Post | null>(null);

<div className="block" data-cy="MainContent">
<p data-cy="NoSelectedUser">No user selected</p>
const showNoPostsYet =
!!selectedUser && !isLoading && !hasPostsLoadingError && !posts.length;

<Loader />
const showPostList =
!!selectedUser && !isLoading && !hasPostsLoadingError && !!posts.length;

<div
className="notification is-danger"
data-cy="PostsLoadingError"
>
Something went wrong!
</div>
const handleLoadPosts = (userId: User['id']) => {
setIsLoading(true);
setHasPostsLoadingError(false);
setSelectedPost(null);

getPosts(userId)
.then(setPosts)
.catch(() => setHasPostsLoadingError(true))
.finally(() => setIsLoading(false));
};

<div className="notification is-warning" data-cy="NoPostsYet">
No posts yet
return (
<main className="section">
<div className="container">
<div className="tile is-ancestor">
<div className="tile is-parent">
<div className="tile is-child box is-success">
<div className="block">
<UserSelector
selectedUser={selectedUser}
onSelectedUser={setSelectedUser}
onLoadPosts={handleLoadPosts}
/>
</div>

<PostsList />
<div className="block" data-cy="MainContent">
{!selectedUser && (
<p data-cy="NoSelectedUser">No user selected</p>
)}

{isLoading && <Loader />}

{hasPostsLoadingError && (
<div
className="notification is-danger"
data-cy="PostsLoadingError"
>
Something went wrong!
</div>
)}

{showNoPostsYet && (
<div className="notification is-warning" data-cy="NoPostsYet">
No posts yet
</div>
)}

{showPostList && (
<PostsList
posts={posts}
selectedPost={selectedPost}
onSelectedPost={setSelectedPost}
/>
)}
</div>
</div>
</div>
</div>

<div
data-cy="Sidebar"
className={classNames(
'tile',
'is-parent',
'is-8-desktop',
'Sidebar',
'Sidebar--open',
)}
>
<div className="tile is-child box is-success ">
<PostDetails />
<div
data-cy="Sidebar"
className={cn('tile is-parent is-8-desktop Sidebar', {
'Sidebar--open': !!selectedPost,
})}
>
<div className="tile is-child box is-success ">
{!!selectedPost && <PostDetails post={selectedPost} />}
</div>
</div>
</div>
</div>
</div>
</main>
);
</main>
);
};
37 changes: 37 additions & 0 deletions src/components/CommentsList/CommentsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FC } from 'react';
import { Comment } from '../../types';

interface Props {
comments: Comment[];
onDeleteComment: (commentId: Comment['id']) => void;
}

export const CommentsList: FC<Props> = ({ comments, onDeleteComment }) => {
return (
<>
<p className="title is-4">Comments:</p>

{comments.map(({ id, email, name, body }) => (
<article key={id} className="message is-small" data-cy="Comment">
<div className="message-header">
<a href={`mailto:${email}`} data-cy="CommentAuthor">
{name}
</a>

<button
data-cy="CommentDelete"
type="button"
className="delete is-small"
aria-label="delete"
onClick={() => onDeleteComment(id)}
/>
</div>

<div className="message-body" data-cy="CommentBody">
{body}
</div>
</article>
))}
</>
);
};
1 change: 1 addition & 0 deletions src/components/CommentsList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CommentsList';
103 changes: 0 additions & 103 deletions src/components/NewCommentForm.tsx

This file was deleted.

Loading

0 comments on commit b4d934b

Please sign in to comment.