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 #2697

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

Develop #2697

wants to merge 5 commits into from

Conversation

Jion353
Copy link

@Jion353 Jion353 commented Dec 17, 2024

Copy link

@alechsva alechsva left a comment

Choose a reason for hiding this comment

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

good job

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. State and Dependency Management: The useEffect hook in TodoModal.tsx should include todo as a dependency to ensure it runs correctly when todo changes. Additionally, the dependency array in App.tsx includes isLoad, which may lead to unnecessary re-renders. If the effect is meant to run only once, consider using an empty array [].

  2. Naming Conventions: Several variable names do not follow common conventions, which can impact code readability and maintainability:

    • isLoad should be renamed to isLoading.
    • isModalSee should be renamed to isModalVisible.
    • qwerty should be renamed to searchQuery.
    • curentTodos has a typo and should be corrected to currentTodos, or better yet, filteredTodos to reflect its purpose.
  3. Code Simplification: Consider using optional chaining and logical operators to simplify your code. For example, using todos?.map(...) and selectedTodo?.id === todo.id && 'has-background-info-light' can make your code more concise and easier to read.

Please address these issues to ensure the code is robust and maintainable. 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 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

export const App: React.FC = () => {
const [isLoad, setIsLoad] = useState(true);

Choose a reason for hiding this comment

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

The state variable isLoad is not named according to common conventions. Consider renaming it to isLoading for better readability and to follow the convention of using present participles for boolean state variables.

src/App.tsx Outdated

export const App: React.FC = () => {
const [isLoad, setIsLoad] = useState(true);
const [isModalSee, setIsModalSee] = useState(false);

Choose a reason for hiding this comment

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

The state variable isModalSee is not named according to common conventions. Consider renaming it to isModalVisible for better readability and to follow the convention of using present participles for boolean state variables.

src/App.tsx Outdated
setTimeout(() => {
setIsLoad(false);
}, 1000);
}, [isLoad]);

Choose a reason for hiding this comment

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

The dependency array for the useEffect hook includes isLoad. This means the effect will run every time isLoad changes, which might not be the intended behavior. If you want the effect to run only once when the component mounts, consider using an empty dependency array [].

};

export const TodoFilter: React.FC<Props> = ({ setTodos }) => {
const [qwerty, setQwerty] = useState('');

Choose a reason for hiding this comment

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

The variable name qwerty is not descriptive. Consider renaming it to something more meaningful, such as searchQuery, to better convey its purpose.


useEffect(() => {
getTodos().then(serverTodos => {
let curentTodos: Todo[] | null = serverTodos.filter(todo =>

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 curentTodos. It should be currentTodos to correctly spell 'current'.

</td>
</tr>
function mapTodos() {
if (todos) {

Choose a reason for hiding this comment

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

Consider using optional chaining to simplify the check for todos. For example, todos?.map(...) can be used to handle the case where todos is null or undefined.

<tr
data-cy="todo"
className={
selectedTodo !== null

Choose a reason for hiding this comment

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

The conditional rendering logic for class names can be simplified using optional chaining and logical operators. For example, selectedTodo?.id === todo.id && 'has-background-info-light' can be used to make the code more concise.

};

export const TodoModal: React.FC<Props> = ({ setVisible, todo, setTodo }) => {
const [isLoad, setIsLoad] = useState(true);

Choose a reason for hiding this comment

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

The state variable isLoad is not named according to common conventions. Consider renaming it to isLoading for better readability and to follow the convention of using present participles for boolean state variables.

if (todo) {
getUser(todo.userId).then(setUser);
}
}, []);

Choose a reason for hiding this comment

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

The useEffect hook should include todo as a dependency. This ensures that the effect runs whenever todo changes, which is important for fetching the correct user data when a different todo is selected.

}, []);

if (!todo) {
return;

Choose a reason for hiding this comment

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

The return statement here does not return any JSX or null, which may lead to unexpected behavior. Consider returning null explicitly if the todo is not available.

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 submission! 🎉 Your code is generally well-structured and follows good practices, but there are a few areas that could be improved to enhance readability and maintainability:

  1. State and Dependency Management:

    • In TodoModal.tsx, consider adding todo to the useEffect dependency array to ensure it re-runs when the todo prop changes. This will allow the component to fetch the correct user data for the new todo.
    • In App.tsx, verify that the useEffect hook is intended to run only once with an empty dependency array, as it will not react to changes in any state or props.
  2. Naming Conventions:

    • In TodoFilter.tsx, renaming the variable qwerty to searchQuery would better reflect its purpose and improve code readability.
  3. Code Simplification:

    • Consider using optional chaining when accessing properties of potentially null or undefined objects, such as serverTodos?.filter(...), todos?.map(...), and selectedTodo?.id === todo.id && 'has-background-info-light'.

These changes will help make your code more robust and maintainable. Keep up the great work, and continue to learn from these suggestions to improve your coding skills! 🚀

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

Comment on lines +18 to +22
useEffect(() => {
setTimeout(() => {
setIsLoading(false);
}, 1000);
}, []);

Choose a reason for hiding this comment

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

The useEffect hook is set to run only once with an empty dependency array. Ensure this is the intended behavior, as it will not react to changes in any state or props.

Comment on lines +42 to +43
todos={todos}
selectedTodo={todo}

Choose a reason for hiding this comment

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

Consider using optional chaining when accessing properties of potentially null or undefined objects, e.g., todos?.map(...) and selectedTodo?.id === todo.id && 'has-background-info-light'.

};

export const TodoFilter: React.FC<Props> = ({ setTodos }) => {
const [qwerty, setQwerty] = useState('');

Choose a reason for hiding this comment

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

Consider renaming qwerty to searchQuery to better reflect its purpose and improve code readability.

Comment on lines +15 to +17
let currentTodos: Todo[] | null = serverTodos.filter(todo =>
todo.title.toLocaleLowerCase().includes(qwerty.toLocaleLowerCase()),
);

Choose a reason for hiding this comment

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

Consider using optional chaining when accessing properties of potentially null or undefined objects, e.g., serverTodos?.filter(...).

Comment on lines +17 to +25
useEffect(() => {
setTimeout(() => {
setIsLoading(false);
}, 1000);

if (todo) {
getUser(todo.userId).then(setUser);
}
}, []);

Choose a reason for hiding this comment

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

Consider adding todo to the dependency array of the useEffect hook to ensure it re-runs when the todo prop changes. This will allow the component to fetch the correct user data for the new todo.

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.

3 participants