Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add task solution #859

wants to merge 2 commits into from

Conversation

ollavka
Copy link

@ollavka ollavka commented Jul 19, 2023

src/App.scss Outdated
@@ -1,3 +1,7 @@
iframe {
Copy link

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
Copy link

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) && (
Copy link

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

Comment on lines 7 to 8
import { useCommentsContext } from '../../hooks/useCommentsContext';
import { useGlobalContext } from '../../hooks/useGlobalContext';
Copy link

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

Comment on lines +11 to +12
export const CommentList: FC<Props> = (props) => {
const { writingNewPost, onWritingNewPost } = props;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const CommentList: FC<Props> = (props) => {
const { writingNewPost, onWritingNewPost } = props;
export const CommentList: FC<Props> = ({ writingNewPost, onWritingNewPost }) => {

Comment on lines 15 to 28
if (posts.length === 0 && !isPostsLoading) {
if (error) {
return (
<Notification type={NotificationType.PostsError} />
);
}

return (
<Notification
type={NotificationType.PostsWarning}
warningText="No posts yet"
/>
);
}
Copy link

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const dropdownRef = useRef<HTMLDivElement | null>(null);
const dropdownRef = useRef<HTMLDivElement>(null);

Comment on lines 22 to 36
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);
};
}, []);
Copy link

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

Suggested change
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);
};
}, []);

});
};

const globalValue: IGlobalContext = {
Copy link

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

setError(false);
setIsUsersLoading(true);

getUsers()
Copy link

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

@ollavka ollavka requested a review from OlEzhA0 August 14, 2023 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants