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

solution #1184

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

solution #1184

wants to merge 2 commits into from

Conversation

k-shestakov
Copy link

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 is mostly well-structured and 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. Critical Functionality Issue: The removeComment function is using the post's id instead of the comment's id for deletion. This is a critical issue as it affects the core functionality of your application. Please update the function to use comment.id for the deletion process.

  2. Typo in Prop Name: There is a consistent typo in the prop name choosenPost. It should be corrected to chosenPost to ensure consistency and avoid potential bugs.

  3. Email Input Type: The type for the email input should be email instead of text. This change will provide built-in validation for email format, enhancing user experience.

  4. Initialization of hasNoPosts: The hasNoPosts variable is not correctly initialized. Ensure it is assigned as a boolean expression to function correctly.

These issues are important to resolve to ensure the application functions correctly and maintains a high standard of code quality. Once these are addressed, your code will be in great shape! Keep up the good work, and feel free to reach out if you have any questions or need further guidance. 😊

✨ 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.

Comment on lines +24 to +25
const hasNoPosts =
selectedUser && !postsIsLoading && !hasPostsError && !posts.length;

Choose a reason for hiding this comment

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

The hasNoPosts variable is not correctly initialized. It should be a boolean expression, but currently, it is missing the assignment operator =. It should be const hasNoPosts = selectedUser && !postsIsLoading && !hasPostsError && !posts.length;.

src/App.tsx Outdated
{!postsIsLoading && posts.length > 0 && (
<PostsList
posts={posts}
choosenPost={chosenPost}

Choose a reason for hiding this comment

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

There is a typo in the prop name choosenPost. It should be chosenPost to match the state variable name and maintain consistency.

<input
value={email}
onChange={handleEmailChange}
type="text"

Choose a reason for hiding this comment

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

The type for the email input should be email instead of text. This will provide built-in validation for email format and improve user experience.

type="button"
className="delete is-small"
aria-label="delete"
onClick={() => removeComment(id)}

Choose a reason for hiding this comment

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

The removeComment function is using the post's id instead of the comment's id for deletion. This will cause incorrect behavior as it attempts to delete the post instead of the comment. Change onClick={() => removeComment(id)} to onClick={() => removeComment(comment.id)} to fix this issue.


type Props = {
posts: Post[];
choosenPost: Post | null;

Choose a reason for hiding this comment

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

There is a typo in the prop name choosenPost. It should be chosenPost to match the standard spelling and maintain consistency across the codebase.


export const PostsList: React.FC<Props> = ({
posts,
choosenPost,

Choose a reason for hiding this comment

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

The prop choosenPost is misspelled. It should be chosenPost to align with the correct spelling and ensure consistency with other parts of the application.

type="button"
data-cy="PostButton"
className={cn('button is-link', {
'is-light': choosenPost?.id !== post.id,

Choose a reason for hiding this comment

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

The usage of choosenPost here should be corrected to chosenPost to match the corrected prop name.

'is-light': choosenPost?.id !== post.id,
})}
onClick={() =>
onSelect(choosenPost?.id === post.id ? null : post)

Choose a reason for hiding this comment

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

Ensure to update choosenPost to chosenPost in this line to reflect the corrected prop name.

onSelect(choosenPost?.id === post.id ? null : post)
}
>
{choosenPost?.id === post.id ? 'Close' : 'Open'}

Choose a reason for hiding this comment

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

Update choosenPost to chosenPost in this line to maintain consistency with the corrected prop name.

const currentUser = e.target as HTMLAnchorElement;

if (currentUser.tagName === 'A') {
const userId = +currentUser.href.split('-').slice(-1)[0];

Choose a reason for hiding this comment

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

Parsing the user ID from the href attribute using split('-').slice(-1)[0] is fragile and depends on the URL structure. Consider using a data attribute to store the user ID directly on the element, which would be more reliable and easier to maintain.

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.


Great work on implementing the code! 🎉 While there are a few areas for improvement, the overall structure and functionality are solid. Here are some key points to consider:

  1. Type Safety: Ensure that variables like hasNoPosts and hasPostsError are initialized correctly as booleans or objects to enhance error handling flexibility.

  2. Error Handling: It's important to handle errors in functions like addComment and removeComment to prevent unhandled promise rejections. Consider using try...catch blocks for better error management.

  3. Form Validation: In the NewCommentForm.tsx, make sure the form is not reset if there are validation errors or if the addComment function fails.

  4. Event Handling: In the UserSelector.tsx, ensure that the handleUserChange function checks if the event target is an anchor element to avoid runtime errors.

  5. PropTypes: Consider adding propTypes to your components for better type-checking and to ensure that components receive the correct props.

These improvements will help you write more robust and maintainable code. Keep up the good work, and continue to learn and grow from these experiences! 🚀

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

const [selectedUser, setSelectedUser] = useState<User | null>(null);
const [posts, setPosts] = useState<Post[]>([]);
const [postsIsLoading, setPostsIsLoading] = useState(false);
const [hasPostsError, setHasPostsError] = useState('');

Choose a reason for hiding this comment

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

The hasPostsError state is initialized as a string. Consider initializing it as a boolean or an object to allow for more flexible error handling in the future.

Comment on lines +24 to +25
const hasNoPosts =
selectedUser && !postsIsLoading && !hasPostsError && !posts.length;

Choose a reason for hiding this comment

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

The hasNoPosts variable should be explicitly initialized as a boolean. Consider using const hasNoPosts = Boolean(selectedUser && !postsIsLoading && !hasPostsError && !posts.length); to ensure it is always a boolean value.

postId: post.id,
};

addComment(newComment).finally(() => setIsSending(false));

Choose a reason for hiding this comment

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

Consider handling errors in the addComment promise. Currently, errors from the addComment function are not caught, which might lead to unhandled promise rejections.

};

addComment(newComment).finally(() => setIsSending(false));
reset();

Choose a reason for hiding this comment

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

The reset() function is called immediately after addComment. Ensure that the form is not reset if there are validation errors or if the addComment function fails.

export const PostDetails: React.FC<Props> = ({ post }) => {
const [comments, setComments] = useState<Comment[]>([]);
const [loading, setLoading] = useState(false);
const [hasError, setHasError] = useState('');

Choose a reason for hiding this comment

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

Consider initializing hasError as a boolean or an object to allow for more flexible error handling in the future.

const addComment = (newComment: CommentData & { postId: number }) => {
return postComment(newComment).then(createdComment => {
setComments(curr => [...curr, createdComment]);
});

Choose a reason for hiding this comment

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

Consider adding error handling for the addComment function to manage potential errors from the postComment API call.

const removeComment = (commentId: number) => {
return deleteComment(commentId).then(() =>
setComments(curr => curr.filter(comment => comment.id !== commentId)),
);

Choose a reason for hiding this comment

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

Consider adding error handling for the removeComment function to manage potential errors from the deleteComment API call.

const handleUserChange = (
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => {
const currentUser = e.target as HTMLAnchorElement;

Choose a reason for hiding this comment

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

The handleUserChange function assumes that the event target is always an anchor element. Consider adding a check to ensure currentUser is an anchor element before accessing its attributes to prevent potential runtime errors.

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.

2 participants