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 #2600

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

Solution #2600

wants to merge 4 commits into from

Conversation

Sholudyvyy
Copy link

Copy link

@igorkruz igorkruz 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 👍
let's improve your solution

src/App.tsx Outdated
Comment on lines 26 to 33
useEffect(() => {
getTodos()
.then(setTodos)
.finally(() => {
setVisibleTodos(todos);
setLoading(false);
});
}, []);

Choose a reason for hiding this comment

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

It's better to move the logic inside the useEffect hook to a separate function, as it improves code readability, reusability, and makes testing easier. It also helps keep useEffect focused on side effects.

src/App.tsx Outdated
Comment on lines 35 to 39
useEffect(() => {
setVisibleTodos(() => {
return filterTodos(todos, todoCategory, query);
});
}, [todos, query, todoCategory]);

Choose a reason for hiding this comment

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

Create a handle function for this logic instead of using useEffect

Comment on lines 16 to 22
useEffect(() => {
getUser(todo.userId)
.then(setUser)
.finally(() => {
setLoading(false);
});
}, []);

Choose a reason for hiding this comment

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

Create a handle function for this logic.
React Hook useEffect has a missing dependency

Comment on lines 55 to 59
{todo.completed ? (
<strong className="has-text-success">Done</strong>
) : (
<strong className="has-text-danger">Planned</strong>
)}

Choose a reason for hiding this comment

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

You can render a single tag and conditionally add a className based on a certain condition.

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 👍
Left some suggestions, check them

src/App.tsx Outdated

export const App: React.FC = () => {
const [todos, setTodos] = useState<Todo[]>([]);
const [visibleTodos, setVisibleTodos] = useState<Todo[]>([]);
const [electTodoId, setElectTodoId] = useState<number>(0);

Choose a reason for hiding this comment

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

What is elect?) Probably it should be selectedTodoId

src/App.tsx Outdated
const [todos, setTodos] = useState<Todo[]>([]);
const [visibleTodos, setVisibleTodos] = useState<Todo[]>([]);
const [electTodoId, setElectTodoId] = useState<number>(0);
const [loading, setLoading] = useState<boolean>(true);

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
  • You should show loader only when you actually loading something

import classNames from 'classnames';

type Props = {
TodoElement: Todo;

Choose a reason for hiding this comment

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

Suggested change
TodoElement: Todo;
todo: Todo;

Names should be in camelCase, in PascalCase only component names and classes


export const TodoModal: React.FC<Props> = ({ todo, onElectTodoId }) => {
const [user, setUser] = useState<User>();
const [loading, setLoading] = useState(true);

Choose a reason for hiding this comment

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

The same regarding loading state

Comment on lines 51 to 61
{todo.completed ? (
<strong className="has-text-success">Done</strong>
) : (
<strong
className={
todo.completed ? 'has-text-success' : 'has-text-danger'
}
>
{todo.completed ? 'Done' : 'Planned'}
</strong>
)}

Choose a reason for hiding this comment

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

Suggested change
{todo.completed ? (
<strong className="has-text-success">Done</strong>
) : (
<strong
className={
todo.completed ? 'has-text-success' : 'has-text-danger'
}
>
{todo.completed ? 'Done' : 'Planned'}
</strong>
)}
<strong
className={
todo.completed ? 'has-text-success' : 'has-text-danger'
}
>
{todo.completed ? 'Done' : 'Planned'}
</strong>


{' by '}

<a href="mailto:[email protected]">Leanne Graham</a>
<a href={`mailto:${user?.email}`}>
{user !== undefined ? user.name : ''}

Choose a reason for hiding this comment

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

Suggested change
{user !== undefined ? user.name : ''}
{user?.name}

It would be the same result


function filterTodos(
todos: Todo[],
todoCategory: string,

Choose a reason for hiding this comment

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

Category is not a string, you have a corresponding type TodoCompletedCategory

Comment on lines 9 to 15
if (todoCategory === 'active') {
return todos.filter(
todo => !todo.completed && todo.title.toLowerCase().includes(query),
);
}

if (todoCategory === 'completed') {

Choose a reason for hiding this comment

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

Use switch case instead

Comment on lines 24 to 32
export function filterTodosByQuery(
todos: Todo[],
setTodos: React.Dispatch<React.SetStateAction<Todo[]>>,
todoCategory: TodoCompletedCategory,
query: string,
) {
setTodos(() => {
return filterTodos(todos, todoCategory, query);
});

Choose a reason for hiding this comment

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

You can do it directly in the component

import { getTodos } from '../api';
import { Todo } from '../types/Todo';

export function setTodosFromApi(

Choose a reason for hiding this comment

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

The same

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.

3 participants