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

Solution #2671

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

Solution #2671

wants to merge 3 commits into from

Conversation

nataliia2211
Copy link

Copy link

@MakksymSly MakksymSly left a 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
Comment on lines 20 to 30
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;
}

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

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}

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.

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

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 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) => {

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}

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.

Copy link

@BudnikOleksii BudnikOleksii left a 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);

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');

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
Comment on lines 20 to 30
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;
}

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
Comment on lines 35 to 37
const filteredTodos = preparedTodos.filter(todo => {
if (query) {
return todo.title.toLowerCase().includes(query.toLowerCase());

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}

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

Comment on lines 42 to 47
<span className="icon">
<i className="far fa-eye-slash" />
</span>
) : (
<span className="icon">
<i className="far fa-eye" />

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' }}>

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

Copy link

@StasSokolov1 StasSokolov1 left a 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;

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Suggested change
return todo.completed === false;
return !todo.completed;

src/App.tsx Outdated
.finally(() => setIsLoading(false));
}, []);

const handelTodo = (todo: Todo) => {

Choose a reason for hiding this comment

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

Suggested change
const handelTodo = (todo: Todo) => {
const handleTodo = (todo: Todo) => {

typo in word

<span className="icon">
<i
className={classNames({
'far fa-eye-slash': todo.id === selectedTodo?.id,

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

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