Skip to content

Commit

Permalink
some edits were fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
2pasha committed Aug 10, 2023
1 parent 0aba08c commit d1e4b7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 18 additions & 12 deletions src/components/NewCommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ export const NewCommentForm: React.FC<Props> = ({
setHasBodyError(false);
}

const handleNameInput = (event: React.ChangeEvent<HTMLInputElement>) => {
setName(event.target.value);
setHasNameError(false);
};

const handleEmailInput = (event: React.ChangeEvent<HTMLInputElement>) => {
setEmail(event.target.value);
setHasEmailError(false);
};

const handleBodyInput = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
setBody(event.target.value);
setHasBodyError(false);
};

return (
<form
data-cy="NewCommentForm"
Expand All @@ -63,10 +78,7 @@ export const NewCommentForm: React.FC<Props> = ({
placeholder="Name Surname"
className={cn('input', { 'is-danger': hasNameError })}
value={name}
onChange={event => {
setName(event.target.value);
setHasNameError(false);
}}
onChange={handleNameInput}
/>

<span className="icon is-small is-left">
Expand Down Expand Up @@ -103,10 +115,7 @@ export const NewCommentForm: React.FC<Props> = ({
placeholder="email@test.com"
className={cn('input', { 'is-danger': hasEmailError })}
value={email}
onChange={event => {
setEmail(event.target.value);
setHasEmailError(false);
}}
onChange={handleEmailInput}
/>

<span className="icon is-small is-left">
Expand Down Expand Up @@ -142,10 +151,7 @@ export const NewCommentForm: React.FC<Props> = ({
placeholder="Type comment here"
className={cn('input', { 'is-danger': hasBodyError })}
value={body}
onChange={event => {
setBody(event.target.value);
setHasBodyError(false);
}}
onChange={handleBodyInput}
/>
</div>

Expand Down
6 changes: 3 additions & 3 deletions src/components/PostsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const PostsList: React.FC<Props> = ({
selectedPost,
setSelectedPost,
}) => {
function onButtonClick(post: Post) {
const onButtonClick = (post: Post) => () => {
if (post.id === selectedPost?.id) {
setSelectedPost(null);
} else {
setSelectedPost(post);
}
}
};

return (
<div data-cy="PostsList">
Expand Down Expand Up @@ -51,7 +51,7 @@ export const PostsList: React.FC<Props> = ({
className={cn('button is-link', {
'is-light': post.id !== selectedPost?.id,
})}
onClick={() => onButtonClick(post)}
onClick={onButtonClick(post)}
>
{post.id === selectedPost?.id ? 'Close' : 'Open'}
</button>
Expand Down

0 comments on commit d1e4b7f

Please sign in to comment.