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

Develop #1247

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

Develop #1247

wants to merge 4 commits into from

Conversation

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

Thank you for your hard work on this project! While your code generally meets the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Asynchronous Data Fetching: The use of useMemo for asynchronous data fetching is not appropriate. Please switch to using useEffect for fetching data to ensure proper side effect management.

  2. Return Type Errors: The getUserById function has an incorrect return type. It should return Promise<User> instead of Promise<Post[]>. Additionally, the deletePostComment function should specify a return type for consistency.

  3. Validation Logic: There are issues with the validation logic for commentTextIsValid, emailIsValid, and nameIsValid. These should be corrected to ensure proper validation.

  4. Error Handling: Improve error handling by providing specific error messages or retry options to the user, rather than just setting a generic error state.

  5. Typographical Errors: There are several typos in function names, variable names, and parameters (e.g., hendlClick, changeSlelectedPost, commemtId, etc.). Correcting these will improve readability and maintain consistency.

Please address these issues to ensure the code functions correctly and adheres to best practices. Once these changes are made, we can proceed with the approval. Keep up the great work! 🌟

✨ 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
>
Something went wrong!
</div>
useMemo(async () => {

Choose a reason for hiding this comment

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

Using useMemo for asynchronous data fetching is not appropriate. useMemo is intended for memoizing values, not for side effects like data fetching. Consider using useEffect instead to fetch users when the component mounts.

src/App.tsx Outdated
</div>
useMemo(async () => {
try {
const loadedUsers: User[] = await getAllUsers();

Choose a reason for hiding this comment

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

The getAllUsers function is called inside useMemo, which is not the correct hook for side effects. Move this logic to a useEffect hook to ensure it runs correctly when the component mounts.

src/App.tsx Outdated

setAllUsers(loadedUsers);
} catch {
setError(true);

Choose a reason for hiding this comment

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

Consider providing more detailed error feedback to the user. Currently, the error state is set to true, but no specific error message is displayed. This could be improved by setting an error message and displaying it in the UI.

return client.post('/comments', data);
};

export const deletePostComment = (id: number) => {

Choose a reason for hiding this comment

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

The deletePostComment function does not specify a return type. For consistency and clarity, consider specifying the return type, such as Promise<void> or Promise<Response>, depending on what the client.delete method returns.

import { User } from '../types/User';
import { client } from '../utils/fetchClient';

export const getUserById = (userId: number): Promise<Post[]> => {

Choose a reason for hiding this comment

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

The return type of getUserById is incorrectly specified as Promise<Post[]>. It should be Promise<User> since the function is fetching a single user by ID.


async function addNewComment(comm: Omit<Comment, 'id' | 'postId'>) {
try {
const promis = await client.addNewComment({ ...comm, postId: id });

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 variable name promis. It should be promise for consistency and to avoid confusion.

}
}

useMemo(async () => {

Choose a reason for hiding this comment

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

Using useMemo for asynchronous data fetching is not appropriate. useMemo is intended for memoizing values, not for side effects like data fetching. Consider using useEffect instead to fetch comments when the post ID changes.

{postComments.length > 0 && (
<CommentsList
comments={postComments}
onDeleteComment={commemtId => deleteComent(commemtId)}

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 parameter name commemtId. It should be commentId for consistency and to avoid confusion.

selectedPost,
onChangeSelectedPost,
}) => {
const changeSlelectedPost = (post: Post) => {

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 function name changeSlelectedPost. It should be changeSelectedPost for consistency and to avoid confusion.

}

useEffect(() => {
const hendlClick = (e: MouseEvent) => {

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 function name hendlClick. It should be handleClick for consistency and to avoid confusion.

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 project! While your code meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Incorrect Use of useMemo: You've used useMemo for data fetching, which is not appropriate as useMemo is meant for memoizing values, not for side effects like fetching data. Please switch to using useEffect for fetching data when the component mounts or when dependencies change.

  2. Error Handling: The current error handling is quite generic. It would be beneficial to provide more detailed error messages to the user or log them for debugging purposes, especially for actions like adding and deleting comments.

  3. Typographical Errors: There are several typos in function names, variable names, and parameter names (e.g., hendlClick, changeSlelectedPost, commemtId, promis, deleteComent, formIsSHow, commentTextIsValidt, coment). These should be corrected to maintain consistency and avoid confusion.

  4. Validation Logic: The validation logic for checking empty fields is inverted. Ensure that conditions check for non-empty values to determine validity.

  5. Return Type Mismatch: The return type of getUserById is incorrectly specified as Promise<Post[]>. It should be Promise<User> to accurately reflect the data being fetched.

Please address these issues to ensure the code fully meets the task requirements. Once these changes are made, we can proceed with the approval. Keep up the great work, and don't hesitate to reach out if you have any questions! 😊

✨ 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
>
Something went wrong!
</div>
useMemo(async () => {

Choose a reason for hiding this comment

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

Using useMemo for data fetching is not appropriate. useMemo is meant for memoizing values, not for side effects like fetching data. Consider using useEffect instead to fetch the users when the component mounts.

src/App.tsx Outdated

setAllUsers(loadedUsers);
} catch {
setError(true);

Choose a reason for hiding this comment

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

The error handling here sets a generic error state. It might be beneficial to provide more detailed error messages to the user or log the error for debugging purposes.

import { User } from '../types/User';
import { client } from '../utils/fetchClient';

export const getUserById = (userId: number): Promise<Post[]> => {

Choose a reason for hiding this comment

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

The return type of getUserById is incorrectly specified as Promise<Post[]>. It should be Promise<User> to match the expected response of fetching a single user by ID.

<>
<p className="title is-4">Comments:</p>

{comments.map(coment => (

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 map function. The variable coment should be comment to match the type and improve code readability.

Comment on lines 34 to 36
const nameIsValid = authorName.trim().length === 0;
const emailIsValid = authorEmail.trim().length === 0;
const commentTextIsValidt = commentText.trim().length === 0;

Choose a reason for hiding this comment

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

The validation logic is inverted. The conditions should check for non-empty values to determine validity. For example, const nameIsValid = authorName.trim().length > 0; should be used to set nameIsValid to true when the name is valid.

}
}

useMemo(async () => {

Choose a reason for hiding this comment

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

Using useMemo for data fetching is not appropriate. useMemo is meant for memoizing values, not for side effects like fetching data. Consider using useEffect instead to fetch comments when the post ID changes.

{postComments.length > 0 && (
<CommentsList
comments={postComments}
onDeleteComment={commemtId => deleteComent(commemtId)}

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 parameter name commemtId. It should be commentId to maintain consistency and avoid confusion.

selectedPost,
onChangeSelectedPost,
}) => {
const changeSlelectedPost = (post: Post) => {

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 function name changeSlelectedPost. It should be changeSelectedPost to maintain consistency and avoid confusion.

}

useEffect(() => {
const hendlClick = (e: MouseEvent) => {

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 function name hendlClick. It should be handleClick to maintain consistency and avoid confusion.

document.addEventListener('click', hendlClick);

return () => {
document.removeEventListener('click', hendlClick);

Choose a reason for hiding this comment

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

Ensure that the event listener is properly cleaned up by using the same function reference for both addEventListener and removeEventListener. This is currently correct, but it's important to maintain this practice to avoid memory leaks.

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.


Great job on implementing the main application logic and structuring your components effectively! 🎉 While there are several areas for improvement, such as enhancing error handling, correcting typographical errors, and improving accessibility, your code is on the right track.

Here are some key points to focus on:

  • Error Handling: Ensure that all API functions include error handling to manage potential request failures. This will help in providing feedback or logging for debugging purposes. Consider making error messages more descriptive to aid in troubleshooting.

  • Typographical Errors: Correct variable names like formIsShow to formIsShown and loadingAddComm to loadingAddComment for clarity and consistency.

  • Accessibility: Enhance accessibility by adding tabIndex and aria attributes to dropdown items and accessible labels to buttons. This will improve usability for users relying on assistive technologies.

  • Validation: Implement robust email validation to ensure the correct format, not just checking for empty fields.

  • State Management: Initialize the error state as null instead of an empty string to avoid unnecessary rendering of error messages.

These improvements will enhance the robustness, clarity, and usability of your application. Keep up the good work, and continue learning from these experiences to refine your skills! 🚀

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


<Loader />
const [loadingData, setLoadingData] = useState(false);
const [error, setError] = useState('');

Choose a reason for hiding this comment

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

Consider initializing the error state as null instead of an empty string. This will help in conditionally rendering error messages more effectively and avoid rendering an empty error message when there is no error.


setAllUsers(loadedUsers);
} catch {
setError('Failed to get a list of users');

Choose a reason for hiding this comment

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

The error message 'Failed to get a list of users' is quite generic. Consider providing more detailed error information or logging the error for debugging purposes.


setUserPosts(loadedUserPosts);
} catch {
setError('Failed to get a list of user posts');

Choose a reason for hiding this comment

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

The error message 'Failed to get a list of user posts' is quite generic. Consider providing more detailed error information or logging the error for debugging purposes.

Comment on lines +4 to +6
export const getPostComments = (postId: number): Promise<Comment[]> => {
return client.get(`/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 getPostComments function to manage potential request failures and provide feedback or logging.

Comment on lines +8 to +10
export const addNewComment = (data: Omit<Comment, 'id'>): Promise<Comment> => {
return client.post('/comments', data);
};

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 addNewComment function to manage potential request failures and provide feedback or logging.

export const PostDetails: React.FC<Props> = ({ post }) => {
const [loadingComments, setLoadingComments] = useState(false);
const [postComments, setPostComments] = useState<Comment[] | null>(null);
const [formIsShow, setFormIsShow] = useState(false);

Choose a reason for hiding this comment

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

Consider renaming formIsShow to formIsShown for grammatical correctness.

const [loadingComments, setLoadingComments] = useState(false);
const [postComments, setPostComments] = useState<Comment[] | null>(null);
const [formIsShow, setFormIsShow] = useState(false);
const [error, setError] = useState('');

Choose a reason for hiding this comment

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

Consider initializing the error state as null instead of an empty string. This will help in conditionally rendering error messages more effectively and avoid rendering an empty error message when there is no error.

const { id, title, body } = post;

async function deleteComment(commId: number) {
setError('');

Choose a reason for hiding this comment

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

Ensure that the error state is consistently reset or cleared when appropriate to avoid displaying outdated error messages.

<tr className="has-background-link-light">
<th>#</th>
<th>Title</th>
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}

Choose a reason for hiding this comment

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

Consider adding accessible labels to buttons to improve accessibility for screen readers. This will help users who rely on assistive technologies to understand the purpose of the buttons.

Comment on lines +66 to +75
<a
key={user.id}
href={`#user-${user.id}`}
className={classNames('dropdown-item', {
'is-active': user.id === activeUser?.id,
})}
onClick={() => clickOnUser(user)}
>
{user.name}
</a>

Choose a reason for hiding this comment

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

Ensure that the dropdown items are accessible by keyboard and screen readers. Consider adding tabIndex and aria attributes to improve accessibility.

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