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 0.01` #1208

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

Conversation

StanislavKapytsia
Copy link

DEMO LINK

Implement the App with ability to show posts of a selected user. Each post can
be opened in the sidebar with its comments. There should delete a comment and a
form to add new comments.
Install Prettier Extention and use this VSCode settings to enable format on save.

Here is the working version

  1. Learn the utils/fetchClient.ts and use it to interact with the API (tests expect that you each API request is sent after 300 ms delay);
  2. Initially the App shows the UserSelector and a paragraph No user selected in the main content block.
    • load users from the API on page load;
    • implement the UserSelector as a dropdown using the given markup;
  3. When a user is selected load the user's posts form the API and show them using a table in the main content clock;
    • show the <Loader> while waiting for the API response;
    • show an error notification if posts loading fails;
    • if the user has no posts show the No posts yet notification.
  4. Add the Sidebar--open class to the sidebar when a post is selected;
    • the post details should appear there immediately;
    • the post commnets should be loaded from the API;
    • the Loader is shown before comments are loaded;
    • CommentsError notification is show on loading error;
    • NoComments message is shown if the post does not have comments yet;
  5. Show the Write a comment button below the comments
    • after click hide the button and show the form to add new comment;
    • the form stays visible until the other post is opened;
    • the form should be implemented as a separate component;
  6. The form requires an author's name and email and a comment text.
    • show errors only after the form is submitted;
    • remove an error on the field change;
    • keep the name and email after the successful submit but clear a comment text;
    • The Clear button should also clear all errors;
    • Add the is-loading class to the submit button while waiting for a response;
    • Add the new comment received as a response from the API to the end of the list;
  7. Implement comment deletion
    • Delete the commnet immediately not waiting for the server response to improve the UX.
  8. (*) Handle Add and Delete errors so the user can retry

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 you've made great progress, there are a few critical issues that need to be addressed to ensure the application functions correctly and meets the task requirements:

  1. Typographical Errors: There are several typos in function and variable names, such as setSelectedpost, addCommetns, and updatedCommnets. These should be corrected to setSelectedPost, addComments, and updatedComments respectively, to maintain consistency and avoid potential bugs.

  2. State Management: The emptyPosts state is not reset when posts are successfully fetched, which could lead to incorrect UI behavior. Ensure to reset this state appropriately.

  3. Form Validation Logic: The logic for checking empty form inputs in the hasEmptyForm function is incorrect. It should use logical OR (||) instead of logical AND (&&) to ensure proper validation.

  4. Error Handling: Setting setComments([]) in the catch block will clear all comments on error, which might not be the intended behavior. Consider revising this logic to preserve existing comments.

  5. PropTypes and Key Generation: The code lacks propTypes definitions for components, and keys are generated on render using comment.id. These should be addressed to follow best practices.

Please address these issues to ensure the code meets the specified requirements and functions as expected. Keep up the great work, and don't hesitate to reach out if you need further assistance! 😊

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

src/App.tsx Outdated

<Loader />
const [posts, setPosts] = useState<Post[]>([]);
const [selectedPost, setSelectedpost] = useState<Post | null>(null);

Choose a reason for hiding this comment

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

The state setter function setSelectedpost is inconsistently named. It should be setSelectedPost to match the naming convention of selectedPost and avoid potential bugs.

src/App.tsx Outdated
users={users}
userId={userId}
setUserId={setUserId}
setSelectedpost={setSelectedpost}

Choose a reason for hiding this comment

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

The prop setSelectedpost should be renamed to setSelectedPost to maintain consistency with the state variable naming.

src/App.tsx Outdated
<PostsList
posts={posts}
selectedPost={selectedPost}
setSelectedpost={setSelectedpost}

Choose a reason for hiding this comment

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

The prop setSelectedpost should be renamed to setSelectedPost to maintain consistency with the state variable naming.

<Loader />
const [posts, setPosts] = useState<Post[]>([]);
const [selectedPost, setSelectedpost] = useState<Post | null>(null);
const [emptyPosts, setEmptyPosts] = useState(false);

Choose a reason for hiding this comment

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

The emptyPosts state is not reset when posts are successfully fetched. Consider setting setEmptyPosts(false) after setting posts to ensure the UI reflects the correct state.

return doesEmpty;
};

const addCommetns = async () => {

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 function name addCommetns. It should be corrected to addComments to reflect its purpose accurately.

}) => {
const handleButtonSwitch = (currentPost: Post) => {
if (selectedPost && selectedPost.id === currentPost.id) {
setSelectedpost(null);

Choose a reason for hiding this comment

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

The function setSelectedpost should be renamed to setSelectedPost to maintain consistency with the naming convention used for state variables and props.

if (selectedPost && selectedPost.id === currentPost.id) {
setSelectedpost(null);
} else {
setSelectedpost(currentPost);

Choose a reason for hiding this comment

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

The function setSelectedpost should be renamed to setSelectedPost to maintain consistency with the naming convention used for state variables and props.

users: User[];
userId: number | null;
setUserId: React.Dispatch<React.SetStateAction<number | null>>;
setSelectedpost: React.Dispatch<React.SetStateAction<Post | null>>;

Choose a reason for hiding this comment

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

The prop setSelectedpost should be renamed to setSelectedPost to maintain consistency with the naming convention used for state variables and props.

users,
userId,
setUserId,
setSelectedpost,

Choose a reason for hiding this comment

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

The prop setSelectedpost should be renamed to setSelectedPost to maintain consistency with the naming convention used for state variables and props.

setUserId(user.id);
setUserName(user.name);
setShowList(false);
setSelectedpost(null);

Choose a reason for hiding this comment

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

The function setSelectedpost should be renamed to setSelectedPost to maintain consistency with the naming convention used for state variables and props.

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.



Review Summary

Great effort on addressing several issues from the previous review! 🎉 Here are some key points and areas for improvement:

  1. Typographical Errors: You've successfully corrected typographical errors in function and variable names, such as setSelectedPost, addComments, and updatedComments. This is crucial for maintaining code readability and functionality.

  2. State Management: The emptyPosts state is now reset when posts are successfully fetched, aligning with the task requirements. However, ensure that the condition emptyPosts && posts.length === 0 && userId is necessary and correctly managed.

  3. Form Validation Logic: The logic for checking empty form inputs should use logical OR (||) instead of logical AND (&&) to ensure proper validation. This change will prevent form submission if any input is empty.

  4. Error Handling: While you've revised the error handling logic in the addComments function, setting setComments([]) in the catch block might not be the intended behavior. Consider preserving existing comments and providing more context-specific error messages to enhance user experience.

  5. PropTypes and Key Generation: The code lacks propTypes definitions for components, which is essential for type-checking and maintaining robust code. Additionally, avoid generating keys on render using comment.id.

  6. Unused Comments: Remember to remove any unused comments in the code to keep it clean and maintainable.

The decision to approve this pull request is made to help you move forward with your learning journey. Please review the comments and address these issues in future iterations to improve your code quality and functionality. Keep up the good work and continue learning from these experiences! 🚀

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

<Loader />
const [posts, setPosts] = useState<Post[]>([]);
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
const [emptyPosts, setEmptyPosts] = useState(false);

Choose a reason for hiding this comment

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

The emptyPosts state is not reset when posts are successfully fetched. Ensure to reset this state appropriately to avoid incorrect UI behavior.


<Loader />
const [posts, setPosts] = useState<Post[]>([]);
const [selectedPost, setSelectedPost] = useState<Post | null>(null);

Choose a reason for hiding this comment

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

Ensure that the function name setSelectedPost is correctly spelled and matches its usage throughout the code.

setPosts(currentPosts);
}
} catch {
setCatchError(true);

Choose a reason for hiding this comment

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

Setting setCatchError(true) in the catch block will trigger an error notification, but consider revising this logic to preserve existing comments or provide more context-specific error handling.

</div>
)}

{emptyPosts && posts.length === 0 && userId && (

Choose a reason for hiding this comment

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

The condition emptyPosts && posts.length === 0 && userId might not be necessary if emptyPosts is managed correctly. Ensure that the logic for displaying this message aligns with the application's requirements.

saveInputDataOnSuccess();
} catch {
setLoadingError(true);
setComments([]);

Choose a reason for hiding this comment

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

Setting setComments([]) in the catch block will clear all comments on error, which might not be the intended behavior. Consider revising this logic to preserve existing comments or handle errors more gracefully.

{ value: commentText, setError: setCommentTextError },
];

const allEmpty = inputs.every(input => !validateInput(input.value));

Choose a reason for hiding this comment

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

The logic for checking empty form inputs in the allEmpty variable is incorrect. It should use logical OR (||) instead of logical AND (&&) to ensure proper validation. This will ensure that the form is not submitted if any input is empty.

setComments(currentComments);
}
} catch {
setLoadingError(true);

Choose a reason for hiding this comment

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

Ensure that the error handling logic here does not inadvertently clear important data or state. Consider providing more context-specific error messages or handling.

if (deletedComment) {
setTimeout(() => {
setComments([...updatedComments, deletedComment]);
setLoadingError(true);

Choose a reason for hiding this comment

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

Setting setLoadingError(true) after attempting to restore a deleted comment might not be the intended behavior. Ensure that the error handling logic aligns with the application's requirements.

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