-
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 #2671
base: master
Are you sure you want to change the base?
Solution #2671
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.
Keep it up 🔥
src/App.tsx
Outdated
const [filteredField, setFilteredField] = useState<string>('All'); | ||
const [query, setQuery] = useState<string>(''); | ||
|
||
const preparedTodos = todos.filter(todo => { | ||
if (filteredField === 'completed') { | ||
return todo.completed === true; | ||
} | ||
|
||
if (filteredField === 'active') { | ||
return todo.completed === 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.
Recommendation:
Consider using Enum for limited options eg.
Enum Field {
All = 'all',
Active = 'active',
Completed = 'completed',
}
And replace 'All' with Field.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.
Recommendation: Consider using Enum for limited options eg. Enum Field { All = 'all', Active = 'active', Completed = 'completed', } And replace 'All' with Field.All
Good point
And use switch case instead
src/App.tsx
Outdated
<TodoModal | ||
user={user} | ||
todo={selectedTodo} | ||
loading={loading} |
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.
Recommendation: The TodoModal component should have a personal loading state. When you click on the Todo button, the loadings duplicate.
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.
Recommendation: The TodoModal component should have a personal loading state. When you click on the Todo button, the loadings duplicate.
Good point
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 job on implementing the task! 🎉 The code meets all the core requirements and functions as expected. There's just a minor typo in the function name handelTodo
, which should be corrected to handleTodo
for consistency. Keep up the good work and happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
src/App.tsx
Outdated
.finally(() => setLoading(false)); | ||
}, []); | ||
|
||
const handelTodo = (todo: Todo) => { |
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.
There is a typo in the function name handelTodo
. It should be handleTodo
to maintain consistency and avoid confusion.
src/App.tsx
Outdated
{loading && <Loader />} | ||
<TodoList | ||
todos={filteredTodos} | ||
showSelectedTodo={handelTodo} |
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 function handelTodo
is used here, but it contains a typo. It should be handleTodo
to match the corrected function name.
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.
Good work 👍
Let's improve your solution slightly
src/App.tsx
Outdated
|
||
export const App: React.FC = () => { | ||
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [loading, setLoading] = useState(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.
Boolean variables should start from is
or has
src/App.tsx
Outdated
const [loading, setLoading] = useState(false); | ||
const [selectedTodo, setSelectedTodo] = useState<Todo | null>(null); | ||
const [user, setUser] = useState<User | null>(null); | ||
const [filteredField, setFilteredField] = useState<string>('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.
all/active/completed are magic values
src/App.tsx
Outdated
const [filteredField, setFilteredField] = useState<string>('All'); | ||
const [query, setQuery] = useState<string>(''); | ||
|
||
const preparedTodos = todos.filter(todo => { | ||
if (filteredField === 'completed') { | ||
return todo.completed === true; | ||
} | ||
|
||
if (filteredField === 'active') { | ||
return todo.completed === 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.
Recommendation: Consider using Enum for limited options eg. Enum Field { All = 'all', Active = 'active', Completed = 'completed', } And replace 'All' with Field.All
Good point
And use switch case instead
src/App.tsx
Outdated
const filteredTodos = preparedTodos.filter(todo => { | ||
if (query) { | ||
return todo.title.toLowerCase().includes(query.toLowerCase()); |
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.
If you don't have query you don't need to filter at all
src/App.tsx
Outdated
<TodoModal | ||
user={user} | ||
todo={selectedTodo} | ||
loading={loading} |
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.
Recommendation: The TodoModal component should have a personal loading state. When you click on the Todo button, the loadings duplicate.
Good point
src/components/Todo/Todo.tsx
Outdated
<span className="icon"> | ||
<i className="far fa-eye-slash" /> | ||
</span> | ||
) : ( | ||
<span className="icon"> | ||
<i className="far fa-eye" /> |
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.
It's almost the same in both cases, only one class is different
<button data-cy="clearSearchButton" type="button" className="delete" /> | ||
</span> | ||
{query && ( | ||
<span className="icon is-right" style={{ pointerEvents: '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.
Avoid inline styles, use classes instead
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.
Almost done, let's improve your code a bit more!
src/App.tsx
Outdated
const filteredByField = (() => { | ||
switch (filteredField) { | ||
case Field.Completed: | ||
return todo.completed === true; |
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.
return todo.completed === true; | |
return todo.completed; |
src/App.tsx
Outdated
case Field.Completed: | ||
return todo.completed === true; | ||
case Field.Active: | ||
return todo.completed === 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.
return todo.completed === false; | |
return !todo.completed; |
src/App.tsx
Outdated
.finally(() => setIsLoading(false)); | ||
}, []); | ||
|
||
const handelTodo = (todo: Todo) => { |
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.
const handelTodo = (todo: Todo) => { | |
const handleTodo = (todo: Todo) => { |
typo in word
src/components/Todo/Todo.tsx
Outdated
<span className="icon"> | ||
<i | ||
className={classNames({ | ||
'far fa-eye-slash': todo.id === selectedTodo?.id, |
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.
let's create isSelectedTodo
const and reuse
DEMO LINK