-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Solution #2707
base: master
Are you sure you want to change the base?
Solution #2707
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
There was a problem hiding this 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 to ensure the application functions correctly:
-
Filter Initialization Consistency: The
filter
state inApp.tsx
is initialized with'All'
, but the filtering logic uses lowercase values like'all'
,'active'
, and'completed'
. This inconsistency can lead to unexpected behavior in the filtering functionality. Please ensure that the filter values are consistent throughout the application. -
select
State Management: Theselect
state variable is used to manage the selection of todos, but its purpose and initialization with0
are not clear. It's crucial to ensure that this state is used consistently and its role is well-defined across the application to avoid issues with displaying the correct todo in the modal.
These issues are critical as they directly impact the application's functionality. Once these are resolved, your code will be in great shape! Keep up the great work, and I'm confident you'll address these points swiftly. 🚀
✨ 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.
if (filter) { | ||
switch (filter) { | ||
case 'all': | ||
result = list; | ||
break; | ||
|
||
case 'active': | ||
result = list.filter((todo: Todo) => !todo.completed); | ||
break; | ||
|
||
case 'completed': | ||
result = list.filter((todo: Todo) => todo.completed); | ||
break; | ||
|
||
default: | ||
result = list; | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter
state is initialized with 'All', but the switch cases use lowercase 'all'. This inconsistency can lead to the default case being executed unintentionally. Ensure the filter values are consistent.
src/App.tsx
Outdated
|
||
const [select, setSelect] = useState(0); | ||
|
||
const [filter, setFilter] = useState('All'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial value of filter
is 'All', which should match the case used in the filterTodos
function ('all'). Consider changing it to 'all' to ensure consistency.
src/App.tsx
Outdated
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const [select, setSelect] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The select
state variable is initialized with 0, but its purpose is not clear. Ensure that this variable is used appropriately and its role is well-defined in the application.
<option value="all">All</option> | ||
<option value="active">Active</option> | ||
<option value="completed">Completed</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the filter values ('all', 'active', 'completed') are consistent with the values used in the App.tsx
file. This will prevent any mismatches in filtering logic.
{todos.map(todo => ( | ||
<tr | ||
data-cy="todo" | ||
className={cn(select === todo.id && 'has-background-info-light')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the select
state variable is used consistently across the application. This line highlights the selected todo, so make sure the logic for setting and using select
is clear and consistent.
const selectedTodo = todos.find(todo => todo.id === select); | ||
const foundedUserId = selectedTodo?.userId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The selectedTodo
and foundedUserId
variables are used to determine the selected todo and its associated user. Ensure that the select
state is managed consistently across the application to avoid any issues with displaying the correct todo in the modal.
return ( | ||
<div className="modal is-active" data-cy="modal"> | ||
<div className="modal-background" /> | ||
{select !== 0 && <div className="modal-background" />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition select !== 0
is used to render the modal background. Ensure that the select
state is correctly updated to reflect the current selection status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on your project! 🎉 Your code is well-structured and aligns with React best practices. Here are some key points to consider for improvement:
-
Filter Initialization Consistency: You've ensured that the
filter
state is consistently initialized with'all'
, matching the lowercase values used in the filtering logic. This resolves previous inconsistencies. Keep this consistency throughout your application. -
select
State Management: Theselect
state is now clearly defined and used consistently across the application. However, remember to handle cases whereselect
might be undefined to prevent potential issues, especially in theTodoModal
component. -
Loading State Management: Consider setting the loading state to false when
foundedUserId
is undefined to prevent the loader from displaying indefinitely.
Your attention to these details will enhance the functionality and reliability of your application. Keep up the great work, and continue learning from these experiences to refine your skills further! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
|
||
if (filter) { | ||
switch (filter) { | ||
case 'all': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter value here is 'all'
, which is consistent with the initialization in the useState
hook. Ensure that all filter values are consistently used in lowercase throughout the application.
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const [select, setSelect] = useState<number | undefined>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The select
state is initialized with undefined
. Ensure that this state is used consistently and its role is well-defined across the application to avoid issues with displaying the correct todo in the modal.
|
||
const [select, setSelect] = useState<number | undefined>(); | ||
|
||
const [filter, setFilter] = useState('all'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter
state is initialized with 'all'
. Ensure that this value is consistent with the values used in the filtering logic (e.g., 'all'
, 'active'
, 'completed'
).
</thead> | ||
type Props = { | ||
todos: Todo[]; | ||
select?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The select
prop is marked as optional, but it is used in the component without a default value. Consider providing a default value or handling the case where select
is undefined to avoid potential issues.
|
||
type Props = { | ||
todos: Todo[]; | ||
select?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The select
prop is optional, but the component logic assumes it will always have a valid value. Consider handling the case where select
is undefined to avoid potential issues.
setLoading(true); | ||
|
||
if (foundedUserId) { | ||
getUser(foundedUserId) | ||
.then(userFromServer => setUser(userFromServer)) | ||
.finally(() => setLoading(false)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loading state is set to true at the beginning of the useEffect
, but it is only set to false if a user is fetched. If foundedUserId
is undefined, the loading state remains true, which could cause the loader to display indefinitely. Consider setting the loading state to false when foundedUserId
is undefined.
DEMO LINK