Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
AvramenkoMarina committed Aug 29, 2024
1 parent 9eec5b8 commit c05b516
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/PostDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const PostDetails: React.FC<Props> = ({ post }) => {
</div>
)}

{!comments.length && !isError && isLoading && (
{!comments.length && !isError && !isLoading && (
<p className="title is-4" data-cy="NoCommentsMessage">
No comments yet
</p>
Expand Down
24 changes: 11 additions & 13 deletions src/components/UserSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ export const UserSelector: React.FC<Props> = ({
}) => {
const [focused, setFocused] = useState(false);

const onFocused = () => {
if (focused) {
setFocused(false);
} else {
setFocused(true);
}
const toggleDropdown = () => {
setFocused(prev => !prev);
};

const handleUserSelect = (user: User) => {
setSelectedUser(user);
setFocused(false);
setSelectedPost(null);
};

return (
<div
data-cy="UserSelector"
className={cn('dropdown', { 'is-active': focused })}
onBlur={() => setFocused(false)}
>
<div className="dropdown-trigger">
<button
type="button"
className="button"
aria-haspopup="true"
aria-controls="dropdown-menu"
onClick={onFocused}
onBlur={() => setFocused(false)}
onClick={toggleDropdown}
>
{selectedUser ? (
<span>{selectedUser.name}</span>
Expand All @@ -64,11 +66,7 @@ export const UserSelector: React.FC<Props> = ({
'is-active': selectedUser?.id === id,
})}
key={id}
onClick={() => {
setSelectedUser(user);
setFocused(false);
setSelectedPost(null);
}}
onClick={() => handleUserSelect(user)}
>
{name}
</a>
Expand Down

0 comments on commit c05b516

Please sign in to comment.