Skip to content

Develop#1124

Open
MaksOther wants to merge 3 commits intomate-academy:masterfrom
MaksOther:develop
Open

Develop#1124
MaksOther wants to merge 3 commits intomate-academy:masterfrom
MaksOther:develop

Conversation

@MaksOther
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

Excellent work on implementing Redux and connecting the components! The application functions well, but I'm requesting changes because a core architectural requirement hasn't been met. The task specifies creating separate Redux slices for features like users, posts, and comments, but the current code uses a single monolithic slice (appSlice). Please refactor this into multiple, more focused slices and combine them in src/app/store.ts to align with the requirements.

Additionally, while not a blocker, the optimistic comment deletion in PostDetails.tsx could be improved. Consider adding error handling in the catch block to revert the UI change if the API call fails. Looking forward to seeing the updated slice structure!


✨ 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/store.ts Outdated
export const store = configureStore({
reducer: {
counter: counterReducer,
app: AppSlice,

Choose a reason for hiding this comment

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

The task requires creating separate slices for users, author, posts, selectedPost, and comments. Instead, a single large slice (AppSlice) has been created for the entire application state under the app key. You should refactor your Redux state into multiple, more focused slices and combine their reducers here.

Comment on lines 62 to 68
dispatch(removeCommentAction(commentId));

try {
await commentsApi.deleteComment(commentId);
} catch {
dispatch(setCommentsError());
}

Choose a reason for hiding this comment

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

This is a good use of an optimistic update for a better user experience. However, consider what happens if the API call in the try block fails. The comment is already removed from the UI by the action on line 62, but it still exists on the server. A more robust implementation would handle this inconsistency, for example, by re-fetching the comments in the catch block to synchronize the UI with the server state.

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 refactoring the Redux state! You've successfully broken down the monolithic slice into feature-specific slices for users, posts, and comments, which was the main goal here. The new structure is clean, scalable, and follows best practices perfectly. All the requirements for this task have been met, so I am approving your solution. As a final cleanup step, you can delete the old src/app/appSlice.ts file, as it's no longer used. 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

Comment on lines +1 to +114
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { User } from '../types/User';
import { Post } from '../types/Post';
import { Comment } from '../types/Comment';

export interface AppState {
users: User[];
author: number | null;
posts: {
loaded: boolean;
hasError: boolean;
items: Post[];
};

selectedPost: number | null;

comments: {
loaded: boolean;
hasError: boolean;
items: Comment[];
};
}

const initialState: AppState = {
users: [],
author: null,
posts: {
loaded: false,
hasError: false,
items: [],
},

selectedPost: null,

comments: {
loaded: false,
hasError: false,
items: [],
},
};

const appSlice = createSlice({
name: 'app',
initialState,
reducers: {
setUsers(state, action: PayloadAction<User[]>) {
state.users = action.payload;
},
setAuthor(state, action: PayloadAction<number>) {
state.author = action.payload;
},
setPosts(state, action: PayloadAction<Post[]>) {
state.posts.hasError = false;
state.posts.loaded = true;
state.posts.items = action.payload;
},
setSelectedPost(state, action: PayloadAction<number>) {
state.selectedPost = action.payload;
},
clearAuthor(state) {
state.author = null;
},
setPostsLoading(state) {
state.posts.loaded = false;
state.posts.hasError = false;
},
setPostsError(state) {
state.posts.hasError = true;
state.posts.loaded = true;
},
clearSelectedPost(state) {
state.selectedPost = null;
},
setCommentsLoading(state) {
state.comments.loaded = false;
state.comments.hasError = false;
},
setComments(state, action: PayloadAction<Comment[]>) {
state.comments.hasError = false;
state.comments.loaded = true;
state.comments.items = action.payload;
},
setCommentsError(state) {
state.comments.hasError = true;
state.comments.loaded = true;
},
addComment(state, action: PayloadAction<Comment>) {
state.comments.items.push(action.payload);
},
removeComment(state, action: PayloadAction<number>) {
state.comments.items = state.comments.items.filter(
comment => comment.id !== action.payload,
);
},
},
});

export const {
setUsers,
setAuthor,
setPosts,
setSelectedPost,
clearAuthor,
setPostsLoading,
setPostsError,
clearSelectedPost,
setCommentsLoading,
setComments,
setCommentsError,
addComment,
removeComment,
} = appSlice.actions;

export default appSlice.reducer;

Choose a reason for hiding this comment

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

Great job refactoring the Redux state into separate slices for users, posts, and comments! This file appears to be a leftover from the previous implementation. Since it's no longer used anywhere in the application, it should be deleted to remove the dead code.

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