Skip to content

Solution#1110

Open
BadOfficer wants to merge 2 commits intomate-academy:masterfrom
BadOfficer:develop
Open

Solution#1110
BadOfficer wants to merge 2 commits intomate-academy:masterfrom
BadOfficer:develop

Conversation

@BadOfficer
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.

Review Summary

Great job migrating the application state to Redux! The new structure with separate slices is well-organized and follows best practices. I'm requesting a few changes to address some critical issues before we can merge this.

Here are the key points to address:

  • Broken Comment Creation: In src/components/PostDetails.tsx, the new comment object is created without an id and then asserted as a Comment. This will cause a runtime error because the key prop in the rendered list will be undefined. To fix this, the addComment thunk should use the complete comment object returned from the API (which includes the id) when dispatching the add action.

  • Missing Error Handling: The removeComment thunk in src/app/comments.ts lacks a try...catch block. If the deleteComment API call fails, it will cause an unhandled promise rejection. Please add error handling here to ensure the app remains stable.

  • UI Flicker: In src/app/posts.ts, when a new author is selected, the loaded state is set to true before the new posts are fetched. This causes a brief "No posts yet" message to flash on the screen. Consider setting loaded to false in this case to show the loading indicator immediately.

These fixes will make the application more robust and improve the user experience. You're doing great work!


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

Important

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

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/app/posts.ts Outdated
extraReducers: builder => {
builder.addCase(set.type, state => {
state.items = [];
state.loaded = true;

Choose a reason for hiding this comment

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

When a new author is selected, their posts have not yet been loaded. Setting loaded to true here will cause the UI to briefly show a "No posts yet" message before the loader appears. Consider what the loaded state should be to indicate that a data fetch is about to begin.

Comment on lines 91 to 96
export function removeComment(commentId: Comment['id']) {
return async (dispatch: Dispatch) => {
await deleteComment(commentId);

dispatch(remove(commentId));
};

Choose a reason for hiding this comment

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

The removeComment function is missing error handling. If the deleteComment API call fails, it will result in an unhandled promise rejection. It's good practice to wrap asynchronous operations that can fail in a try...catch block, similar to how you've done it in the addComment function.

Comment on lines 34 to 39
const newComment = {
name,
email,
body,
postId: post.id,
} as Comment;

Choose a reason for hiding this comment

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

The type assertion as Comment is incorrect here. The newComment object is missing the id property, which is required by the Comment type. This will cause an issue when the new comment is added to the list, as the key={comment.id} in the render method will be using an undefined id.

To fix this, the addComment thunk should wait for the createComment API response (which presumably returns the created comment with its new ID) and then dispatch the add action with the complete comment object returned from the server.

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

Excellent work on this pull request! I am approving your solution as you have successfully addressed all the feedback from the previous review. The migration to Redux is well-executed, and the fixes for comment creation, error handling, and the UI flicker have significantly improved the application's robustness. All requirements have been met, and the code is clean and well-structured. Great job!


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

Footnotes

  1. Rate AI review example

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