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

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

Add task solution #2606

wants to merge 2 commits into from

Conversation

WatarJoy
Copy link

Copy link

@mbulchak mbulchak 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. Just fix some moments.
Check your demo, your todos are highlighted at the beggining. Change it for SelectedTodoId, instead of todo.completed

const [selectedTodo, setSelectedTodo] = useState<Todo | null>(null);
const [userDetails, setUserDetails] = useState<User | null>(null);
const [filterStatus, setFilterStatus] = useState('all');
const [query, setQuery] = useState('');

Choose a reason for hiding this comment

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

Suggestion: states userDetails and isLoadingUser are needed only in TodoModal. You can create useEffect for them as you do for todos

<tr
key={todo.id}
data-cy="todo"
className={todo.completed ? 'has-background-info-light' : ''}

Choose a reason for hiding this comment

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

This is causing a problem. You don't need to highlight completed todos. You should highlight when it is your selectedTodo. But in your case it SelectedTodoId

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 this pull request! Your code is clean and well-structured. There are a few minor issues, but they don't significantly impact the functionality of your code. Keep up the good work! 🎉 Remember to consider the provided feedback for your future tasks. Happy coding! 😄

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

Comment on lines +49 to +51
const handleSelectTodo = (todoId: number | null) => {
setSelectedTodoId(todoId);
};

Choose a reason for hiding this comment

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

The naming convention for the method is not followed. It should be 'onSelectTodo' instead of 'handleSelectTodo'. Please refer to the checklist link for naming conventions.

Comment on lines +53 to +55
const closeModal = () => {
setSelectedTodoId(null);
};

Choose a reason for hiding this comment

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

The naming convention for the method is not followed. It should be 'onCloseModal' instead of 'closeModal'. Please refer to the checklist link for naming conventions.

Comment on lines +14 to +19
const [todos, setTodos] = useState<Todo[]>([]);
const [filteredTodos, setFilteredTodos] = useState<Todo[]>([]);
const [isLoadingTodos, setIsLoadingTodos] = useState(false);
const [selectedTodoId, setSelectedTodoId] = useState<number | null>(null);
const [filterStatus, setFilterStatus] = useState('all');
const [query, setQuery] = useState('');

Choose a reason for hiding this comment

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

You are initializing your state with props. This can lead to bugs since the state will not update when the props change. Always use props directly or make sure to update the state when the props change.

Comment on lines +35 to +37
className={
todo.id === selectedTodo ? 'has-background-info-light' : ''
}

Choose a reason for hiding this comment

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

Consider using the classnames library to conditionally apply classes. It allows for cleaner and more readable code. You can find the library here.

data-cy="selectButton"
className="button"
type="button"
onClick={() => setSelectedTodo(null)}

Choose a reason for hiding this comment

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

The naming convention for event handlers could be improved. Instead of setSelectedTodo, consider using handleSelectedTodo or onSelectTodo. This makes it clear that this function is an event handler. You can find more information on naming conventions here.

data-cy="selectButton"
className="button"
type="button"
onClick={() => setSelectedTodo(todo.id)}

Choose a reason for hiding this comment

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

The same naming convention issue is present here. Consider using handleSelectedTodo or onSelectTodo instead of setSelectedTodo.


export const TodoModal: React.FC<Props> = ({ todo, closeModal }) => {
const [user, setUser] = useState<User | null>(null);
const [isLoadingUser, setIsLoadingUser] = useState(true);

Choose a reason for hiding this comment

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

It seems that you are initializing the state with props (todo.userId in this case). This is generally considered an anti-pattern in React. This is because the constructor or useState hook runs only once when the component is created, and then never runs again. This means that even if the prop updates, the state will not update. You should avoid copying props into state and instead use the prop directly.

Comment on lines +16 to +21
useEffect(() => {
setIsLoadingUser(true);
getUser(todo.userId)
.then(userData => setUser(userData))
.finally(() => setIsLoadingUser(false));
}, [todo.userId]);

Choose a reason for hiding this comment

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

You are directly interacting with the API inside the component. This could lead to performance issues and make the component less reusable. Consider moving the API calls outside of the component, for instance using custom hooks. This way, you could separate the data-fetching logic from the component, making your code cleaner and easier to test.

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