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

Develop #1192

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

Develop #1192

wants to merge 8 commits into from

Conversation

Mariana-VV
Copy link

@Mariana-VV Mariana-VV commented Nov 3, 2024

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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


Thank you for your hard work on this project! While your code meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. State Management: The handling of setIsPostLoaded in App.tsx is misleading and could cause incorrect UI behavior. It should accurately reflect the loading status of posts.

  2. Function Defaults: Assigning default empty functions to openForm and deleteComment can lead to unexpected behavior. Ensure these functions are always provided when components are used.

  3. API Defaults: The use of default parameters like userId = 0 and postId = 0 in users.ts might lead to unintended API calls. Verify these defaults are intentional and handled correctly.

  4. Unrelated Code: The deleteTodos function in users.ts seems unrelated to the current context and should be removed if unnecessary.

  5. PropTypes and Error Handling: The absence of propTypes and lack of try-catch error handling are significant omissions that affect code robustness and documentation.

Please address these issues to enhance the functionality and reliability of your code. Keep up the great work, and I'm confident you'll tackle these challenges successfully! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.


const getPostsByCurrentUser = (user: User | null | undefined) => {
setIsPostLoadError(false);
setIsPostLoaded(true);

Choose a reason for hiding this comment

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

Setting setIsPostLoaded(true) here might be misleading as it indicates that posts are already loaded. Consider setting this state to true only when the posts have successfully loaded.

.getPostsByUser(user?.id)
.then(setPosts)
.catch(() => setIsPostLoadError(true))
.finally(() => setIsPostLoaded(false));

Choose a reason for hiding this comment

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

Setting setIsPostLoaded(false) in the finally block might not accurately reflect the loading status. Consider setting this state to false only after the posts have been successfully loaded or if an error occurs.

src/api/users.ts Outdated
Comment on lines 32 to 34
export const deleteTodos = (todoId: number) => {
return client.delete(`/todos/${todoId}`);
};

Choose a reason for hiding this comment

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

The function deleteTodos appears to be unrelated to the current context of users, posts, and comments. Consider removing it if it's not needed.

src/api/users.ts Outdated
Comment on lines 10 to 11
export const getPostsByUser = (userId = 0) => {
return client.get<Post[]>(`/posts?userId=${userId}`);

Choose a reason for hiding this comment

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

The default parameter userId = 0 might lead to unintended API calls if not handled properly. Ensure that this default value is intentional and that the API can handle requests with userId = 0 appropriately.

src/api/users.ts Outdated
Comment on lines 14 to 15
export const getCommentsByPost = (postId = 0) => {
return client.get<Comment[]>(`/comments?postId=${postId}`);

Choose a reason for hiding this comment

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

The default parameter postId = 0 might lead to unintended API calls if not handled properly. Ensure that this default value is intentional and that the API can handle requests with postId = 0 appropriately.

setCurrentPost,
currentPost,
getCommentsByCurrentPost,
openForm = () => {},

Choose a reason for hiding this comment

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

Assigning a default empty function to openForm might lead to unexpected behavior if not properly handled. Ensure that this function is always provided when the component is used.


type Props = {
post: Post;
key?: number;

Choose a reason for hiding this comment

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

The key prop is defined in the Props type but not used in the component. Consider removing it if it's not needed to avoid confusion.

setCurrentPost: (post: Post | null) => void;
currentPost?: Post | null;
getCommentsByCurrentPost: (post: Post) => void;
openForm?: (isOpen: boolean) => void;

Choose a reason for hiding this comment

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

The openForm prop is optional, but there is no default value provided in the PostItem component. Ensure that this function is always provided when the component is used to avoid unexpected behavior.

<div className="dropdown-trigger">
<button
type="button"
className="button"
aria-haspopup="true"
aria-controls="dropdown-menu"
onClick={handleDropdownClick}
onBlur={() => setIsMenuShown(false)}

Choose a reason for hiding this comment

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

Using onBlur to close the dropdown might cause it to close unexpectedly if the user interacts with the dropdown items. Consider using a different approach, such as closing the dropdown when clicking outside of it.

Comment on lines +71 to +73
onMouseDown={() => {
handleUserClick(user);
}}

Choose a reason for hiding this comment

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

Using onMouseDown to handle user selection might not be the best choice for accessibility. Consider using onClick instead to ensure better accessibility and consistency with user expectations.

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

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

Great work! Almost done!


const handleFormSubmit = (event: FormEvent) => {
event.preventDefault();
if (!name) {

Choose a reason for hiding this comment

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

Suggested change
if (!name) {
if (!name.trim()) {

setNameError(true);
}

if (!email) {

Choose a reason for hiding this comment

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

Suggested change
if (!email) {
if (!email.trim()) {

setEmailError(true);
}

if (!message) {

Choose a reason for hiding this comment

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

Suggested change
if (!message) {
if (!message.trim()) {

setMessageError(true);
}

if (name && email && message) {

Choose a reason for hiding this comment

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

Suggested change
if (name && email && message) {
if (name.trim() && email.trim() && message.trim()) {

currentUser?: User | null;
setCurrentPost: (post: Post | null) => void;
setPosts: (posts: Post[]) => void;
// setComments: (comments: Comment[]) => void;

Choose a reason for hiding this comment

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

Suggested change
// setComments: (comments: Comment[]) => void;

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Almost done!

src/App.tsx Outdated
dataFromServer.getUsers().then(setUsers);
}, []);

function addComment(comment: Comment) {

Choose a reason for hiding this comment

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

It is important to stick to one way of creating functions, fix it everywhere

Suggested change
function addComment(comment: Comment) {
const addComment = (comment: Comment) => {

<article className="message is-small" data-cy="Comment">
<div className="message-header">
<a href={`mailto:${comment?.email}`} data-cy="CommentAuthor">
{comment?.name}

Choose a reason for hiding this comment

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

Use destructuring for comment

Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

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

good job, but you need and you can try to remove the comment that user tries to delete immediately from the screen

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.

5 participants