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

Everything works outside of escape. Would love some advice on that. #772

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

Conversation

szymonpachucki
Copy link

Copy link

@domalewski domalewski left a 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

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

}

// eslint-disable-next-line max-len
export const Footer: React.FC<Props> = ({ handleSetFilter, todos, setTodos }) => {

Choose a reason for hiding this comment

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

Suggested change
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

Copy link

@domalewski domalewski left a 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

Copy link

@choeqq choeqq left a 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

Copy link

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
Comment on lines 57 to 59
useEffect(() => {
// You can perform any additional actions here when the todos state changes.
}, [todos]);
Copy link

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 && (
Copy link

Choose a reason for hiding this comment

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

Suggested change
{error !== null && (
{error && (


return (
<header className="todoapp__header">
{todos.length !== 0 && (
Copy link

Choose a reason for hiding this comment

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

Suggested change
{todos.length !== 0 && (
{todos.length && (

Comment on lines 101 to 111
<input
ref={inputRef}
type="text"
className="todoapp__new"
placeholder="Empty todo will be deleted"
value={inputValue}
onChange={handleInputChange}
onKeyPress={handleInputKeyPress}
onBlur={handleInputBlur}
/>
)}
Copy link

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


return (
<section className="todoapp__main">
{visibleTodos().map((todo) => (
Copy link

Choose a reason for hiding this comment

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

Suggested change
{visibleTodos().map((todo) => (
{visibleTodos.map((todo) => (

this should be a value instead of a function call

Copy link

@mbruhler mbruhler left a 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:

  1. 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
  2. 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');

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.

@@ -0,0 +1 @@
export type FilterOption = 'All' | 'Active' | 'Completed';

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.

const visibleTodos = (() => {
let filteredTodos = todos;

if (filterTodos === 'Active') {

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.


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 */}

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

Copy link

@pawel-peksa pawel-peksa 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! 💪 Almost done!
-> Added one minor comment regarding the performance optimization. (Try to avoid unnecessary itarations in your code)

{todos.length > 0 && (
<button
type="button"
className={`todoapp__toggle-all ${todos.every((t) => t.completed) ? 'active' : ''}`}

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.

Copy link

@choeqq choeqq left a comment

Choose a reason for hiding this comment

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

LGTM ✅

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.

5 participants