-
Notifications
You must be signed in to change notification settings - Fork 1.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
Everything works outside of escape. Would love some advice on that. #772
base: master
Are you sure you want to change the base?
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.
It's working so I guess it's ok
Removed the unnecessary comments
src/App.tsx
Outdated
return <UserWarning />; | ||
} | ||
const [todos, setTodos] = useState<Todo[]>([ | ||
// Initialize with some example todos |
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.
please remove comment, code it's simple to understand
src/components/footer.tsx
Outdated
} | ||
|
||
// eslint-disable-next-line max-len | ||
export const Footer: React.FC<Props> = ({ handleSetFilter, todos, setTodos }) => { |
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.
export const Footer: React.FC<Props> = ({ handleSetFilter, todos, setTodos }) => { | |
export const Footer: React.FC<Props> = ({ | |
handleSetFilter, | |
todos, | |
setTodos }) => { |
I know it's looks worst but then you don't have to disabling eslint
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 working so I guess it's ok
Removed the unnecessary comments
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.
please add comments to your code only when you want to implement some normally unexpected behaviour
consider using context in your app
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.
current filter should have different styles, when picked, as a user I want to know what kind of todos the app is displaying
src/App.tsx
Outdated
useEffect(() => { | ||
// You can perform any additional actions here when the todos state changes. | ||
}, [todos]); |
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.
empty effect?
src/App.tsx
Outdated
|
||
{/* Notification is shown in case of any error */} | ||
{/* Add the 'hidden' class to hide the message smoothly */} | ||
{error !== null && ( |
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.
{error !== null && ( | |
{error && ( |
src/components/inputOfTodos.tsx
Outdated
|
||
return ( | ||
<header className="todoapp__header"> | ||
{todos.length !== 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.
{todos.length !== 0 && ( | |
{todos.length && ( |
src/components/task.tsx
Outdated
<input | ||
ref={inputRef} | ||
type="text" | ||
className="todoapp__new" | ||
placeholder="Empty todo will be deleted" | ||
value={inputValue} | ||
onChange={handleInputChange} | ||
onKeyPress={handleInputKeyPress} | ||
onBlur={handleInputBlur} | ||
/> | ||
)} |
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.
make sure to apply correct styles to editing input - it should look the same as Todo styles
src/components/todoList.tsx
Outdated
|
||
return ( | ||
<section className="todoapp__main"> | ||
{visibleTodos().map((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.
{visibleTodos().map((todo) => ( | |
{visibleTodos.map((todo) => ( |
this should be a value instead of a function call
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.
For the problem with cancel edit when Esc key is up
, you can do this in two ways:
- register a listener for this button in
useEffect
and remove it on component unmount. If escape is pressed then trigger a function that changes the edit state - register an event listener on the input using
onKeyUp
and handling it there, similar to what you did with Enter.
I think 2. is better, because the scope of the event handler is just for the input, but I wanted to show you that there is also a possibility to register such event globally for component, not just input :)
src/App.tsx
Outdated
} | ||
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [error, setError] = useState<Errors | null>(null); | ||
const [filterTodos, setFilterTodos] = useState<FilterOption>('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.
It's perfect that you created a type for the filter, but it shouldn't be a string value, rather an enum or JSON with only possible values.
To do so:
Change FilterOptions
type to const enum
and provide the possible values:
export const enum FilterOption {
ALL = 'all',
ACTIVE = 'active',
COMPLETED = 'completed',
}
Then you can use it as a type and as a value to compare
const [filterTodos, setFilterTodos] = useState<FilterOption>(FilterOption.ALL);
You can also use a JSON value here rather than const enum
and type it accordingly, but I think the const enum
is simpler and is nice to know about them, especially in such cases.
src/types/filterOption.ts
Outdated
@@ -0,0 +1 @@ | |||
export type FilterOption = 'All' | 'Active' | 'Completed'; |
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.
Change type according to const enum
change request.
src/components/todoList.tsx
Outdated
const visibleTodos = (() => { | ||
let filteredTodos = todos; | ||
|
||
if (filterTodos === 'Active') { |
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.
With the const enum
change, you should do:
if (filterTodos === FilterOption.ACTIVE) { ... }
Change others too.
src/components/inputOfTodos.tsx
Outdated
|
||
return ( | ||
<header className="todoapp__header"> | ||
{/* i can not write it as {todos.lenght && as when its value is 0 it will display '0' on the screen */} |
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.
yeah, the condition you've provided is fine, please clear the comment
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 job! 💪 Almost done!
-> Added one minor comment regarding the performance optimization. (Try to avoid unnecessary itarations in your code)
src/components/inputOfTodos.tsx
Outdated
{todos.length > 0 && ( | ||
<button | ||
type="button" | ||
className={`todoapp__toggle-all ${todos.every((t) => t.completed) ? 'active' : ''}`} |
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.
You itarate over the array of Todos in two places to get the same information (see line 38). This is not the best performance optimization. Let's try to do this only once and use the result in both places.
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 ✅
DEMO LINK