-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add task solution #859
base: master
Are you sure you want to change the base?
add task solution #859
Conversation
src/App.scss
Outdated
@@ -1,3 +1,7 @@ | |||
iframe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain why do we need this?
aria-label="delete" | ||
onClick={() => onDeleteComment(comment.id)} | ||
> | ||
delete button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to add this text?
|
||
return ( | ||
<> | ||
{(comments.length > 0 && !error) && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you move this conditions to constants
import { useCommentsContext } from '../../hooks/useCommentsContext'; | ||
import { useGlobalContext } from '../../hooks/useGlobalContext'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add index.ts
file to hooks
folder. exports all hooks and import here with 1 import. The same for api
export const CommentList: FC<Props> = (props) => { | ||
const { writingNewPost, onWritingNewPost } = props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const CommentList: FC<Props> = (props) => { | |
const { writingNewPost, onWritingNewPost } = props; | |
export const CommentList: FC<Props> = ({ writingNewPost, onWritingNewPost }) => { | |
src/components/Posts/PostList.tsx
Outdated
if (posts.length === 0 && !isPostsLoading) { | ||
if (error) { | ||
return ( | ||
<Notification type={NotificationType.PostsError} /> | ||
); | ||
} | ||
|
||
return ( | ||
<Notification | ||
type={NotificationType.PostsWarning} | ||
warningText="No posts yet" | ||
/> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const noPosts = posts.length === 0 && !isPostsLoading
if (noPosts && error) {
return (
<Notification type={NotificationType.PostsError} />
);
}
if (noPosts) {
return (
<Notification
type={NotificationType.PostsWarning}
warningText="No posts yet"
/>
);
}
|
||
const [dropdownIsActive, setDropdownIsActive] = useState(false); | ||
|
||
const dropdownRef = useRef<HTMLDivElement | null>(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const dropdownRef = useRef<HTMLDivElement | null>(null); | |
const dropdownRef = useRef<HTMLDivElement>(null); |
const handleClickOutsideDropdown = (event: MouseEvent) => { | ||
const dropdown = dropdownRef.current; | ||
|
||
if (dropdown && !dropdown.contains(event.target as Node)) { | ||
closeDropdown(); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener('click', handleClickOutsideDropdown); | ||
|
||
return () => { | ||
document.removeEventListener('click', handleClickOutsideDropdown); | ||
}; | ||
}, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid recreations of this fn
on each rendering
const handleClickOutsideDropdown = (event: MouseEvent) => { | |
const dropdown = dropdownRef.current; | |
if (dropdown && !dropdown.contains(event.target as Node)) { | |
closeDropdown(); | |
} | |
}; | |
useEffect(() => { | |
document.addEventListener('click', handleClickOutsideDropdown); | |
return () => { | |
document.removeEventListener('click', handleClickOutsideDropdown); | |
}; | |
}, []); | |
useEffect(() => { | |
const handleClickOutsideDropdown = (event: MouseEvent) => { | |
const dropdown = dropdownRef.current; | |
if (dropdown && !dropdown.contains(event.target as Node)) { | |
closeDropdown(); | |
} | |
}; | |
document.addEventListener('click', handleClickOutsideDropdown); | |
return () => { | |
document.removeEventListener('click', handleClickOutsideDropdown); | |
}; | |
}, []); |
src/context/ListContext.tsx
Outdated
}); | ||
}; | ||
|
||
const globalValue: IGlobalContext = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap each your values with useMemo
src/context/ListContext.tsx
Outdated
setError(false); | ||
setIsUsersLoading(true); | ||
|
||
getUsers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better to use async await
DEMO LINK
TESTS LINK