Skip to content

task solution#1117

Open
iryna-knyzh wants to merge 1 commit intomate-academy:masterfrom
iryna-knyzh:develop
Open

task solution#1117
iryna-knyzh wants to merge 1 commit intomate-academy:masterfrom
iryna-knyzh:develop

Conversation

@iryna-knyzh
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.

Review Summary

Great work on refactoring the application to use Redux Toolkit! You've successfully met all the core requirements for this task, and the overall structure is solid. I am approving your solution. As you continue to develop your skills, I have a couple of suggestions for improvement:

  • In src/features/commentsSlice.ts, the loaded state is modified during the pending state for creating and deleting comments. It's better to only manage this flag during the initial data fetch (loadPostComments) to avoid inconsistent UI loading states.
  • To make your code more robust and leverage TypeScript's full potential, consider adding explicit types to function and async thunk arguments, for example, for the post parameter in App.tsx and the postId in commentsSlice.ts.

These are not blockers, but applying these practices will enhance the quality and maintainability of your code. Keep up the excellent work!


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

Footnotes

  1. Rate AI review example

// We disable the spinner in any case
.finally(() => setLoaded(true));
}
const setSelectedPost = post => {

Choose a reason for hiding this comment

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

It's a good practice to provide an explicit type for function parameters. In this case, based on how setSelectedPost is used, the post parameter should be of type Post | null. You'll need to import the Post type as well.


export const loadPostComments = createAsyncThunk(
'comments/getPostComments',
async postId => {

Choose a reason for hiding this comment

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

It's a good practice to add an explicit type for the postId parameter to leverage TypeScript's type safety. Based on its usage, it should be a number.

);
export const createCommentAsync = createAsyncThunk(
'comments/createComment',
async data => {

Choose a reason for hiding this comment

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

The data parameter should have an explicit type. You could define a type for the new comment data, for example Omit<Comment, 'id'>, to ensure type safety when creating a comment.


export const deleteCommentAsync = createAsyncThunk(
'comments/deleteComment',
async id => {

Choose a reason for hiding this comment

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

The id parameter should have an explicit type, which should be number in this case.

Comment on lines +67 to +68
.addCase(createCommentAsync.pending, state => {
state.loaded = true;

Choose a reason for hiding this comment

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

Setting state.loaded = true during the pending state for creating a comment is inconsistent with the loadPostComments.pending case which sets it to false. The loaded flag should typically indicate whether the list of comments has been fetched. During a creation or deletion, the list is already loaded, so this state probably shouldn't be modified here.

Comment on lines +78 to +79
.addCase(deleteCommentAsync.pending, state => {
state.loaded = true;

Choose a reason for hiding this comment

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

Similar to the createCommentAsync.pending case, setting state.loaded = true here is inconsistent. The list of comments is still considered loaded while one is being deleted, so modifying the loaded state is likely unnecessary.

const users = useAppSelector(selectUsers);
const author = useAppSelector(selectAuthor);

const onChange = a => {

Choose a reason for hiding this comment

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

To leverage the full power of TypeScript, it's a good practice to provide an explicit type for the a parameter. Based on its usage, what type should it be? You might need to import the User type.

hasError: false,
};

export const loadUserPosts = createAsyncThunk('posts/getPosts', async id => {

Choose a reason for hiding this comment

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

To improve type safety, it's a good practice to explicitly type the arguments of your async thunks. Based on the getUserPosts function, what type should the id parameter be?

Comment on lines +36 to +37
.addCase(loadUserPosts.pending, state => {
state.loaded = false;

Choose a reason for hiding this comment

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

When a new data loading process starts, it's a good idea to also reset any previous error state. Consider setting hasError to false here to ensure the UI doesn't show a stale error message from a previous failed request.

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