Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
There are no files to review. Please make sure that you have added files to the pull request. Some files and directories may be ignored from the review or failed to load.
[CODE: NFR]
Additional info:
Ignored files list:
package-lock.jsonpackage.json
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
There are no files to review. Please make sure that you have added files to the pull request. Some files and directories may be ignored from the review or failed to load.
[CODE: NFR]
Additional info:
Ignored files list:
package-lock.jsonpackage.json
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Good effort on migrating the application to use Redux Toolkit. However, a few critical changes are needed before this can be approved.
The main issue is that the author and selectedPost states are still managed by useState in App.tsx. The task requires these to be moved into their own dedicated Redux slices. Additionally, your usersSlice has a logical bug: in the usersThunk.fulfilled case, hasError is incorrectly set to true when it should be false on a successful request.
Please also address the missing error handling in comentsSlice.ts by adding a rejected case for the fetch thunk to correctly set the hasError state. Once these requirements are met and the bug is fixed, your solution will be in great shape.
✨ 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
src/App.tsx
Outdated
| const [loaded, setLoaded] = useState(false); | ||
| const [hasError, setError] = useState(false); | ||
|
|
||
| const [author, setAuthor] = useState<User | null>(null); |
There was a problem hiding this comment.
According to the task requirements, the author state should be managed by its own Redux slice, not with useState in the App component.
src/App.tsx
Outdated
| const [hasError, setError] = useState(false); | ||
|
|
||
| const [author, setAuthor] = useState<User | null>(null); | ||
| const [selectedPost, setSelectedPost] = useState<Post | null>(null); |
There was a problem hiding this comment.
The task requires creating a Redux slice for selectedPost. This state should be moved from useState to the Redux store.
| @@ -0,0 +1,16 @@ | |||
| import { combineSlices, configureStore } from '@reduxjs/toolkit'; | |||
| import { commentsSlice } from '../slicers/comentsSlice'; | |||
There was a problem hiding this comment.
There seems to be a typo in the filename. It should probably be commentsSlice instead of comentsSlice to maintain consistency.
src/components/App/Store.ts
Outdated
|
|
||
|
|
||
| const rootReducer = combineSlices( | ||
| commentsSlice, usersSlice, postsSlice |
There was a problem hiding this comment.
According to the task description, you also need to create and include slices for author and selectedPost in the root reducer.
| extraReducers: (builder) => { | ||
| builder.addCase(commentsThunkCreate.fulfilled, (state, action) => { | ||
| state.items.push(action.payload)}, | ||
| ) | ||
| builder.addCase(commentsThunkGet.fulfilled, (state, action) => { | ||
| state.items = action.payload, | ||
| state.loaded = true; | ||
| }, | ||
| ) | ||
| builder.addCase(commentsThunkGet.pending, state => { | ||
| state.loaded = false; | ||
| state.hasError = false; | ||
| }) | ||
| builder.addCase(commentsThunkDelete.fulfilled, (state, action) => { | ||
| state.items = state.items.filter(item => item.id !== action.meta.arg); | ||
| }, | ||
| ) | ||
| } |
There was a problem hiding this comment.
The error handling for async operations is incomplete. You're missing a case for commentsThunkGet.rejected, which is necessary to set hasError: true when fetching comments fails. It's also good practice to add rejected handlers for commentsThunkCreate and commentsThunkDelete to handle potential errors during those operations.
| import { Comment, CommentData } from '../types/Comment'; | ||
| import { CommentData } from '../types/Comment'; | ||
| import { useAppDispatch, useAppSelector } from './App/hooks'; | ||
| import { commentsThunkCreate, commentsThunkDelete, commentsThunkGet } from './slicers/comentsSlice'; |
There was a problem hiding this comment.
There appears to be a typo in the import path. The file should likely be named commentsSlice.ts for consistency.
src/components/slicers/usersSlice.ts
Outdated
| builder.addCase(usersThunk.fulfilled, (state, action) => { | ||
| state.items = action.payload; | ||
| state.loaded = true; | ||
| state.hasError = true; |
There was a problem hiding this comment.
When the thunk is fulfilled, it means the request was successful. Therefore, hasError should be set to false here, not true.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on refactoring the application to use Redux and for fixing the bugs from the previous review! The state management is much cleaner now. However, a few changes are needed to fully align with the task requirements regarding the Redux store structure.
The task explicitly requires dedicated slices for the selected author and the selected post. Currently, this logic is mixed in with the users and posts slices.
Please make the following adjustments:
- Create a new
authorSlice.tsand move theselectedUserIdstate and its corresponding reducer logic out ofusersSlice. - Create a new
selectedPostSlice.tsand move theselectedPoststate and its reducer frompostsSlice.
Additionally, please correct the consistent typo in comentsSlice to commentsSlice in the filename and all related imports for consistency. Once these structural changes are complete, your solution will be perfect.
✨ 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
src/App.tsx
Outdated
| .finally(() => setLoaded(true)); | ||
| } | ||
| const dispatch = useAppDispatch(); | ||
| const { items: users, selectedUserId } = useAppSelector(state => state.users); |
There was a problem hiding this comment.
According to the task description, the state for the selected author (user) should be in its own dedicated author slice. Therefore, selectedUserId should be selected from state.author.
src/App.tsx
Outdated
| } | ||
| const dispatch = useAppDispatch(); | ||
| const { items: users, selectedUserId } = useAppSelector(state => state.users); | ||
| const { items: posts, loaded, hasError, selectedPost } = useAppSelector(state => state.posts) |
There was a problem hiding this comment.
The task requires a separate slice for the selected post. This means selectedPost should be managed in its own slice and selected from a different part of the state, for example state.selectedPost.
src/components/App/Store.ts
Outdated
| @@ -0,0 +1,16 @@ | |||
| import { combineSlices, configureStore } from '@reduxjs/toolkit'; | |||
| import { comentsSlice } from '../slicers/comentsSlice'; | |||
There was a problem hiding this comment.
There's a consistent typo in the naming of the comments slice. It should be commentsSlice here and in the corresponding filename.
src/components/App/Store.ts
Outdated
|
|
||
|
|
||
| const rootReducer = combineSlices( | ||
| comentsSlice, usersSlice, postsSlice |
There was a problem hiding this comment.
The task requires creating dedicated slices named author and selectedPost. While you've correctly moved this state into Redux, it needs to be in separate slices that are then combined here. Currently, this state is managed within the usersSlice and postsSlice.
| return deleteComment(commentId) | ||
| } | ||
| ) | ||
| export const comentsSlice = createSlice({ |
There was a problem hiding this comment.
There's a typo in the slice name. It should be commentsSlice to match the intended name 'comments'. This typo should also be corrected in the filename (commentsSlice.ts).
| import { Comment, CommentData } from '../types/Comment'; | ||
| import { CommentData } from '../types/Comment'; | ||
| import { useAppDispatch, useAppSelector } from './App/hooks'; | ||
| import { commentsThunkCreate, commentsThunkDelete, commentsThunkGet } from './slicers/comentsSlice'; |
There was a problem hiding this comment.
There's a consistent typo in the filename and slice name for comments. It should be commentsSlice, not comentsSlice. Please correct this here and in the slice file itself for consistency.
src/components/slicers/postsSlice.ts
Outdated
|
|
||
| export const postsSlice = createSlice({ | ||
| name: 'posts', | ||
| initialState: {items: [] as Post[], loaded: false, hasError: false, selectedPost: null as Post | null }, |
There was a problem hiding this comment.
According to the task description, the selectedPost state should be managed in a separate slice. This part of the state should be removed from the posts slice's initial state.
src/components/slicers/postsSlice.ts
Outdated
| setSelectedPost: (state, action: PayloadAction<Post | null>) => { | ||
| state.selectedPost = action.payload; | ||
| } |
There was a problem hiding this comment.
This reducer should be moved to the new, dedicated selectedPostSlice. The postsSlice should only be responsible for managing the list of posts (items, loaded, hasError).
src/components/slicers/usersSlice.ts
Outdated
|
|
||
| export const usersSlice = createSlice({ | ||
| name: 'users', | ||
| initialState: { items: [] as User[], loaded: false, hasError: false, selectedUserId: null as number | null }, |
There was a problem hiding this comment.
The task requires a dedicated author slice for the selected user's state. The selectedUserId property should be removed from this initial state and managed within its own author slice.
src/components/slicers/usersSlice.ts
Outdated
| setSelectedUser: (state, action: PayloadAction<number | null>) => { | ||
| state.selectedUserId = action.payload; | ||
| } |
There was a problem hiding this comment.
This reducer logic for setting the selected user should be moved to the new author slice, as per the task requirements. The users slice should only be responsible for the list of all users, their loading status, and any related errors.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job on refactoring the Redux store! You've done excellent work creating the dedicated authorSlice and selectedPostSlice, which significantly improves the application's structure. I am approving this submission as an educational override to help you move forward, but there are a few important things to address to finalize your solution.
Please remember to:
- Remove the leftover
selectedUserIdstate fromsrc/components/slicers/usersSlice.tsand theselectedPoststate fromsrc/components/slicers/postsSlice.ts. - Correct the persistent typo in the filename and imports from
comentsSlicetocommentsSlice. - Fix the build error by updating the store's import path in
src/index.tsxto point to./components/App/Store.
Addressing these points will resolve the failing checks and make your state management clean and efficient. Keep up the fantastic work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| @@ -0,0 +1,15 @@ | |||
| import { combineSlices, configureStore } from '@reduxjs/toolkit'; | |||
| import { commentsSlice } from '../slicers/comentsSlice'; | |||
There was a problem hiding this comment.
The filename in the import path still has a typo. Please correct comentsSlice to commentsSlice to match the corrected slice filename.
| import { Comment, CommentData } from '../types/Comment'; | ||
| import { CommentData } from '../types/Comment'; | ||
| import { useAppDispatch, useAppSelector } from './App/hooks'; | ||
| import { commentsThunkCreate, commentsThunkDelete, commentsThunkGet } from './slicers/comentsSlice'; |
There was a problem hiding this comment.
The filename in the import path still contains a typo. Please correct comentsSlice to commentsSlice to match the intended filename and maintain consistency with the rest of the application.
| items: [] as Post[], | ||
| loaded: false, | ||
| hasError: false, | ||
| selectedPost: null as Post | null, |
There was a problem hiding this comment.
The selectedPost property should be removed from this slice's initial state. Its state is now managed by the dedicated selectedPostSlice, and keeping it here creates a duplicate and unused piece of state.
| selectedUserId: null as number | null, | ||
| }, | ||
| reducers: { | ||
| setSelectedUser: (state, action: PayloadAction<number | null>) => { | ||
| state.selectedUserId = action.payload; | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Excellent work on creating the separate authorSlice! However, the state and reducer related to the selected user (selectedUserId and setSelectedUser) should now be completely removed from this usersSlice. This slice should only be responsible for managing the list of users (items), loaded, and hasError states.
No description provided.