Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
VadymTsyndra committed Jul 17, 2023
1 parent 4e03549 commit 2112987
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const App: React.FC = () => {
</div>
)}

{posts && posts.length === 0 && (
{posts && !posts.length && (
<div className="notification is-warning" data-cy="NoPostsYet">
No posts yet
</div>
Expand Down
26 changes: 18 additions & 8 deletions src/components/PostsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export const PostsList: React.FC<Props> = ({
loadComments,
setIsCommentFormOpened,
}) => {
const [id, setId] = useState<number | null>(null);
const [currentId, setCurrentId] = useState<number | null>(null);

const openClick = (post?: Post, postId?: number) => {
setSideBarOpened(true);
setIsCommentFormOpened(false);

if (postId && post) {
setId(postId);
setCurrentId(postId);
loadComments(post);
} else {
setSideBarOpened(!isSideBarOpened);
Expand All @@ -44,16 +44,21 @@ export const PostsList: React.FC<Props> = ({
</thead>

<tbody>
{posts && posts.map(post => (
<tr data-cy="Post" key={post.id}>
<td data-cy="PostId">{post.id}</td>
{posts && posts.map(({
id,
userId,
title,
body,
}) => (
<tr data-cy="Post" key={id}>
<td data-cy="PostId">{id}</td>

<td data-cy="PostTitle">
{post.title}
{title}
</td>

<td className="has-text-right is-vcentered">
{isSideBarOpened && post.id === id ? (
{isSideBarOpened && id === currentId ? (
<button
type="button"
data-cy="PostButton"
Expand All @@ -67,7 +72,12 @@ export const PostsList: React.FC<Props> = ({
type="button"
data-cy="PostButton"
className="button is-link is-light"
onClick={() => openClick(post, post.id)}
onClick={() => openClick({
id,
userId,
title,
body,
}, id)}
>
Open
</button>
Expand Down

0 comments on commit 2112987

Please sign in to comment.