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

add task solution #1025

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

Conversation

AndriiZakharenko
Copy link

@AndriiZakharenko
Copy link
Author

add tests
1

Copy link

@VolodymyrKirichenko VolodymyrKirichenko 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, but let's improve ur code a bit 🥹

src/api.ts Outdated
@@ -22,4 +22,4 @@ function get<T>(url: string): Promise<T> {

export const getTodos = () => get<Todo[]>('/todos');

export const getUser = (userId: number) => get<User>(`/users/${userId}`);
export const getUser = (userId: number) => get<User>(`/users/${userId}`);

Choose a reason for hiding this comment

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

I think it will be more readable)

Suggested change
export const getUser = (userId: number) => get<User>(`/users/${userId}`);
export const getUserById = (userId: number) => get<User>(`/users/${userId}`);

Choose a reason for hiding this comment

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

I think it will be more readable)

Not fixed

Comment on lines 11 to 13
const setStatus = (status: string) => {
dispatch(filterActions.setStatus(status as Status));
};

Choose a reason for hiding this comment

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

set? use handle prefix for such functions.
also handle functions receive event by default

Suggested change
const setStatus = (status: string) => {
dispatch(filterActions.setStatus(status as Status));
};
const handleChangeStatus = (event: React.ChangeEvent<HTMLSelectElement>) => {
dispatch(filterActions.setStatus(event.target.value));
};

do it for all the cases!

<select
data-cy="statusSelect"
value={currentStatus}
onChange={event => setStatus(event.target.value)}

Choose a reason for hiding this comment

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

Suggested change
onChange={event => setStatus(event.target.value)}
onChange={handleChangeStatus}

Comment on lines 4 to 21
// we use string literal as a type to avoid mistype in future
type RemoveTodoAction = { type: 'currentTodo/REMOVE' };

// payload is a typical name for an action data
type SetTodoAction = {
type: 'currentTodo/SET';
payload: Todo;
};

// Action creator return type protect us from a mistype
const removeTodo = (): RemoveTodoAction => ({ type: 'currentTodo/REMOVE' });

export const currentTodoSlice = createSlice({
name: 'currentTodo',
initialState,
reducers: {},
const setTodo = (todo: Todo): SetTodoAction => ({
type: 'currentTodo/SET',
payload: todo,
});

// These actions will be used in the application

Choose a reason for hiding this comment

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

why do I only see comments in this file?
GPT?

};

const setQuery = (inputValue: string) => {
dispatch(filterActions.setQuery(inputValue));

Choose a reason for hiding this comment

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

add trim method to ignore spaces

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 comments and suggestions

src/App.tsx Outdated
setIsLoading(true);
getTodos()
.then(result => {
dispatch(todosSlice.actions.addTodos(filteredTodo(result)));

Choose a reason for hiding this comment

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

You don't need to fetch todos every time when filters changes

src/App.tsx Outdated
<div className="block">
<TodoFilter />
</div>
const filteredTodo = useCallback(

Choose a reason for hiding this comment

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

Suggested change
const filteredTodo = useCallback(
const filteredTodos = useMemo(

Just filter the todos that you have in the state, store in a variable and then show only them

src/App.tsx Outdated
<div className="block">
<Loader />
<TodoList />
<div className="block">{isLoading ? <Loader /> : <TodoList />}</div>

Choose a reason for hiding this comment

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

Suggested change
<div className="block">{isLoading ? <Loader /> : <TodoList />}</div>
<div className="block">{isLoading ? <Loader /> : <TodoList todos={filteredTodos} />}</div>

Like this

src/api.ts Outdated
@@ -22,4 +22,4 @@ function get<T>(url: string): Promise<T> {

export const getTodos = () => get<Todo[]>('/todos');

export const getUser = (userId: number) => get<User>(`/users/${userId}`);
export const getUser = (userId: number) => get<User>(`/users/${userId}`);

Choose a reason for hiding this comment

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

I think it will be more readable)

Not fixed

return (
<tr
key={id}
data-cy="todo"

Choose a reason for hiding this comment

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

Create a todo component

}
>
<span className="icon">
{currentTodo?.id === id ? (

Choose a reason for hiding this comment

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

You compare ids twice, create a variable

Comment on lines 21 to 25
setTimeout(() => {
getUser(userId)
.then(setUser)
.finally(() => setIsLoading(false));
}, 1000);

Choose a reason for hiding this comment

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

Why do you need a timeout?

Comment on lines 18 to 21
status: (state: State, action: PayloadAction<string>) => ({
...state,
status: action.payload,
}),

Choose a reason for hiding this comment

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

Suggested change
status: (state: State, action: PayloadAction<string>) => ({
...state,
status: action.payload,
}),
status: (state: State, action: PayloadAction<string>) => {
state.status = action.payload,
},

In the redux toolkit you can mutate the state

Copy link

@DanilWeda DanilWeda 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.
Approved with a small comment.
Many thanks)

<div className="block">
<TodoFilter />
</div>
const filteredTodos = useMemo(() => {

Choose a reason for hiding this comment

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

You can move the function outside the file, and then use it as a helper func in this place.

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.

4 participants