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 #1219

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

Develop #1219

wants to merge 4 commits into from

Conversation

DmytroHoncharuk
Copy link

No description provided.

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 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. Error Handling: The fetchUsers function lacks error handling, which is crucial for robustness. Please ensure that errors are properly managed, possibly by setting an error state or logging them.

  2. Unused State: The postError state is initialized but not utilized. Consider integrating it into your error handling logic or removing it if it's unnecessary.

  3. Prop Type Handling: The users prop is typed as User[] | null, but the component assumes it can always be mapped over. Please handle the null case to prevent potential runtime errors.

These issues impact the functionality and robustness of the application. Once addressed, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you need any help. 😊

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

<p data-cy="NoSelectedUser">No user selected</p>
const [chosenUser, setChosenUser] = React.useState<User | null>(null);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [postError, setPostError] = React.useState(false);

Choose a reason for hiding this comment

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

The postError state is initialized but not used in the component logic. Consider using it to handle errors related to fetching posts or remove it if it's unnecessary.

src/App.tsx Outdated
Comment on lines 32 to 34
} catch (err) {
} finally {
}

Choose a reason for hiding this comment

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

The error handling block in the fetchUsers function is empty. Consider adding logic to handle errors, such as setting an error state or logging the error, to improve the robustness of the application.

}

if (!email.trim() || !/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/.test(email)) {
newErrors.email = 'Email is required';

Choose a reason for hiding this comment

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

The error message for email validation states 'Email is required', but the validation logic also checks for a valid email format. Consider updating the message to reflect both conditions, such as 'Valid email is required'.

newErrors.name = 'Name is required';
}

if (!email.trim() || !/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/.test(email)) {

Choose a reason for hiding this comment

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

The email validation regex is quite basic and might not cover all valid email formats. Consider using a more comprehensive regex for email validation to ensure better accuracy.

const [error, setError] = useState<string | null>(null);
const [commentsFromServer, setCommentsFromServer] = useState<Comment[]>([]);
const [isFormVisible, setIsFormVisible] = useState<boolean>(false);
const [currentPostId, setCurrentPostId] = useState<number | null>(null);

Choose a reason for hiding this comment

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

The currentPostId state appears to be redundant since it mirrors the post?.id prop. Consider removing it and directly using post?.id to simplify the logic.

try {
await deleteComment(commentId);
} catch {
setError('Failed to delete comment. Please try again.');

Choose a reason for hiding this comment

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

The error message for failed comment deletion is generic. Consider including more specific information, such as the comment ID or reason for failure, to provide better feedback to the user.

Comment on lines +15 to +26
function handleClickToChoosePost(post: Post) {
if (!activePost) {
choosePost(post);
}

<table className="table is-fullwidth is-striped is-hoverable is-narrow">
<thead>
<tr className="has-background-link-light">
<th>#</th>
<th>Title</th>
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
<th> </th>
</tr>
</thead>
if (activePost?.id === post.id) {
choosePost(null);
}

<tbody>
<tr data-cy="Post">
<td data-cy="PostId">17</td>
if (activePost?.id !== post.id) {
choosePost(post);
}

Choose a reason for hiding this comment

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

The handleClickToChoosePost function can be simplified. The current logic checks three conditions, but it can be reduced to two: if activePost?.id === post.id, set choosePost(null); otherwise, set choosePost(post). This will make the function more concise and easier to read.

Comment on lines +60 to +74
{users?.map(user => (
<a
key={user.id}
href={`#${user.id}`}
className={classNames('dropdown-item', {
'is-active': user.id === chosenUser?.id,
})}
onClick={() => {
setIsActive(false);
chooseUser(user);
}}
>
{user.name}
</a>
))}

Choose a reason for hiding this comment

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

The users prop is typed as User[] | null, but the component maps over users without checking for null. Consider providing a default value or handling the null case to prevent potential runtime errors.

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 Pull Request! 🎉 The code has improved significantly, addressing many of the previous concerns. However, there are still a few areas to enhance:

  1. Unused State: The postError state should be utilized effectively to display an error message or take necessary actions when a post fetch error occurs.

  2. Email Validation Message: Update the email validation message to 'Valid email is required' to cover both missing and invalid formats.

  3. Error Message Specificity: Provide a more specific error message for failed comment loads, such as 'Failed to load comments. Please try again later.'

  4. Prop Type Handling: Ensure the users prop is always an array to prevent runtime errors.

  5. Redundant Conditional Checks: Simplify the logic in the handleClickToChoosePost function for better readability.

These improvements will enhance the robustness and user experience of your application. Keep up the great work, and continue learning from these insights! 🚀

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

<div className="block" data-cy="MainContent">
<p data-cy="NoSelectedUser">No user selected</p>
const [chosenUser, setChosenUser] = React.useState<User | null>(null);
const [postError, setPostError] = React.useState(false);

Choose a reason for hiding this comment

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

The postError state is set to true when an error occurs while fetching posts, but it is not utilized effectively in the component's logic. Ensure that this state is used to display an appropriate error message or take necessary actions when a post fetch error occurs.

}

if (!email.trim() || !/^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/.test(email)) {
newErrors.email = 'Email is required';

Choose a reason for hiding this comment

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

The error message for email validation is misleading. It currently states 'Email is required' even when the email format is incorrect. Consider updating the message to something like 'Valid email is required' to cover both missing and invalid email formats.

<Loader />
) : error ? (
<div className="notification is-danger" data-cy="CommentsError">
Something went wrong

Choose a reason for hiding this comment

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

The error message 'Something went wrong' is too generic. Consider providing a more specific message, such as 'Failed to load comments. Please try again later.' to give users clearer feedback.

Comment on lines +15 to +26
function handleClickToChoosePost(post: Post) {
if (!activePost) {
choosePost(post);
}

<table className="table is-fullwidth is-striped is-hoverable is-narrow">
<thead>
<tr className="has-background-link-light">
<th>#</th>
<th>Title</th>
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
<th> </th>
</tr>
</thead>
if (activePost?.id === post.id) {
choosePost(null);
}

<tbody>
<tr data-cy="Post">
<td data-cy="PostId">17</td>
if (activePost?.id !== post.id) {
choosePost(post);
}

Choose a reason for hiding this comment

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

The handleClickToChoosePost function contains redundant conditional checks. You can simplify the logic by combining the conditions into a single check. For example, you can directly toggle the post selection based on whether the clicked post is the active one or not.

import classNames from 'classnames';

type Props = {
users: User[] | null;

Choose a reason for hiding this comment

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

The users prop is typed as User[] | null, but the component assumes it can always be mapped over. Consider providing an empty array instead of null to prevent potential runtime errors. This can be done by ensuring the parent component passes an empty array when there are no users.

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