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

add task solution #1200

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

Conversation

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


Thank you for your hard work on this pull request! While your code is mostly well-structured and meets many of the task requirements, there are a few critical issues that need to be addressed before we can proceed:

  1. Typo in State Variable Names: The state variable writeCommen and its setter setWriteCommen should be corrected to writeComment and setWriteComment respectively. Consistency in naming is crucial for code readability and maintenance.

  2. Error Handling: The use of setInterval to reset error states is not ideal as it could lead to unexpected behavior. It's recommended to use setTimeout to clear the error after a specific duration.

  3. Function Naming: The function removeDelete should be renamed to removeComment to better reflect its purpose and improve code clarity.

  4. Type Safety: Ensure that functions like setPosts and setPost have explicit type definitions to enhance type safety and prevent potential runtime errors.

  5. PropTypes and Error Handling: The absence of propTypes and try-catch blocks for error handling are significant oversights. These are essential for maintaining robust and error-free code.

  6. State Initialization and Key Generation: Initializing state with props and generating keys on render can lead to issues and should be revised according to best practices.

Please address these issues to ensure the code meets the core requirements and functions as expected. Once these changes are made, we can move forward with the approval. Keep up the great work, and don't hesitate to reach out if you need any help! 😊

✨ 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
const [comments, setComments] = useState<Comment[]>([]);
const [loadingComments, setLoadingComments] = useState(false);
const [errorLoadComments, setErrorLoadComments] = useState<boolean>(false);
const [writeCommen, setWriteCommen] = useState<boolean>(false);

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 state variable name writeCommen. It should be writeComment to maintain consistency and clarity in your code.

src/App.tsx Outdated
Comment on lines 42 to 44
setInterval(() => {
setErrorLoadPosts(false);
}, 3000);

Choose a reason for hiding this comment

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

Using setInterval to reset the error state might not be the best approach. Consider using setTimeout instead to clear the error after a specific duration, as setInterval will repeatedly execute the callback function.

src/App.tsx Outdated
Comment on lines 55 to 57
setInterval(() => {
setErrorLoadComments(false);
}, 3000);

Choose a reason for hiding this comment

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

Similar to the previous comment, using setInterval to reset the error state might not be ideal. Consider using setTimeout to clear the error after a specific duration.

}

setLoadingNewComment(true);
if (postId) {

Choose a reason for hiding this comment

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

Consider handling the case where postId is undefined more explicitly. Currently, the function does nothing if postId is undefined, which might lead to confusion or unexpected behavior.

writeCommen,
setWriteCommen,
}) => {
function removeDelete(comment: Comment) {

Choose a reason for hiding this comment

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

Consider renaming the function removeDelete to removeComment for better clarity and to accurately reflect its functionality.

setComments: (comments: Comment[]) => void;
loadingComments: boolean;
errorLoadComments: boolean;
writeCommen: boolean;

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 state variable name writeCommen. It should be writeComment to maintain consistency and clarity in your code.

openPostDetails: number;
setOpenPostDetails: (openPostDetails: number) => void;
getCommentsPost: (post: Post) => void;
setWriteCommen: (writeCommen: boolean) => void;

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 state variable name setWriteCommen. It should be setWriteComment to maintain consistency and clarity in your code.

setUserSelected: (userSelected: User) => void;
getPostUser: (user: User) => void;
setOpenPostDetails: (openPostDetails: number) => void;
setWriteCommen: (writeCommen: boolean) => void;

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 state variable name setWriteCommen. It should be setWriteComment to maintain consistency and clarity in your code.

getPostUser: (user: User) => void;
setOpenPostDetails: (openPostDetails: number) => void;
setWriteCommen: (writeCommen: boolean) => void;
setPosts: ([]) => void;

Choose a reason for hiding this comment

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

The setPosts function should have a more explicit type definition, such as (posts: Post[]) => void, to ensure type safety.

setOpenPostDetails: (openPostDetails: number) => void;
setWriteCommen: (writeCommen: boolean) => void;
setPosts: ([]) => void;
setPost: (post: null) => void;

Choose a reason for hiding this comment

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

The setPost function should have a more explicit type definition, such as (post: Post | null) => void, to ensure type safety.

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.


Your Pull Request has been reviewed and approved! 🎉 While there are several areas for improvement, the decision to approve is made to help you move forward with your learning journey. Here are some key points to consider for future enhancements:

  1. Type Safety: Ensure that all functions, props, and state setters have explicit type definitions. This will enhance type safety and prevent potential runtime errors.

  2. Error Handling: Consider adding error handling for API requests across various functions (getUsers, getPosts, createComment, deleteComment, etc.). Implementing .catch() blocks with detailed error messages or logging will help manage potential errors gracefully and aid in debugging.

  3. Accessibility: Improve accessibility by adding aria-labels or other features to buttons and dropdowns, ensuring a better experience for users with assistive technologies.

  4. User Feedback: Enhance user experience by providing notifications or messages, especially in cases like comment deletion failures.

  5. Validation: Implement regex checks for email validation to ensure inputs are valid before form submission.

These improvements will not only enhance the functionality and robustness of your code but also provide a better user experience. Keep up the great work, and continue learning from these insights! 🚀

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

Comment on lines +40 to +42
.catch(() => {
setErrorLoadPosts(true);
})

Choose a reason for hiding this comment

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

Consider adding more detailed error messages or logging within the .catch() block to aid in debugging and provide more context about the error.

Comment on lines +50 to +52
.catch(() => {
setErrorLoadComments(true);
})

Choose a reason for hiding this comment

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

Similar to the previous comment, consider adding more detailed error messages or logging within the .catch() block to aid in debugging and provide more context about the error.

Comment on lines +20 to +30
const [users, setUsers] = useState<User[]>([]);
const [userSelected, setUserSelected] = useState<User | null>(null);
const [posts, setPosts] = useState<Post[]>([]);
const [post, setPost] = useState<Post | null>(null);
const [loadingPosts, setLoadingPosts] = useState(false);
const [errorLoadPosts, setErrorLoadPosts] = useState<boolean>(false);
const [openPostDetails, setOpenPostDetails] = useState<number>(0);
const [comments, setComments] = useState<Comment[]>([]);
const [loadingComments, setLoadingComments] = useState(false);
const [errorLoadComments, setErrorLoadComments] = useState<boolean>(false);
const [writeComment, setWriteComment] = useState<boolean>(false);

Choose a reason for hiding this comment

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

Ensure that all state setters have explicit type definitions to enhance type safety and prevent potential runtime errors.

Comment on lines +4 to +6
export const getComments = (postId: number) => {
return client.get<Comment[]>(`/comments?postId=${postId}`);
};

Choose a reason for hiding this comment

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

Consider adding error handling for the getComments function to manage potential errors gracefully.

Comment on lines +13 to +15
}: Omit<Comment, 'id'>) => {
return client.post<Comment>(`/comments`, { postId, name, email, body });
};

Choose a reason for hiding this comment

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

Consider adding error handling for the createComment function to manage potential errors gracefully.

}) => {
function removeComment(comment: Comment) {
setComments([...comments.filter(commentary => commentary !== comment)]);
deleteComment(comment.id).catch(() => setComments([...comments]));

Choose a reason for hiding this comment

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

Consider adding a notification or message to inform the user if the comment deletion fails. This will improve user experience by providing feedback on the action.

Comment on lines +27 to +30
function removeComment(comment: Comment) {
setComments([...comments.filter(commentary => commentary !== comment)]);
deleteComment(comment.id).catch(() => setComments([...comments]));
}

Choose a reason for hiding this comment

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

Ensure that the removeComment function has an explicit return type definition to enhance type safety and prevent potential runtime errors.

Comment on lines +45 to +69
<button
type="button"
data-cy="PostButton"
className="button is-link"
onClick={() => {
setOpenPostDetails(0);
setWriteComment(false);
}}
>
Close
</button>
) : (
<button
type="button"
data-cy="PostButton"
className="button is-link is-light"
onClick={() => {
setOpenPostDetails(id);
getCommentsPost(post);
setPost(post);
setWriteComment(false);
}}
>
Open
</button>

Choose a reason for hiding this comment

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

Consider adding aria-labels or other accessibility features to the buttons to improve accessibility for users with assistive technologies.

Comment on lines +12 to +19
export const PostsList: React.FC<Props> = ({
posts,
setPost,
openPostDetails,
setOpenPostDetails,
getCommentsPost,
setWriteComment,
}) => (

Choose a reason for hiding this comment

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

Ensure that all functions and props have explicit type definitions to enhance type safety and prevent potential runtime errors.

Comment on lines +17 to +26
export const UserSelector: React.FC<Props> = ({
users,
userSelected,
setUserSelected,
getPostUser,
setOpenPostDetails,
setWriteComment,
setPosts,
setPost,
}) => {

Choose a reason for hiding this comment

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

Ensure that all functions and props have explicit type definitions to enhance type safety and prevent potential runtime errors.

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