Skip to content

Commit

Permalink
fix mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
igor.polianskyi committed Oct 7, 2024
1 parent ee54bbf commit 1ce43cf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEffect, useState } from 'react';
import { getTodos } from './api';
import { useDispatch } from 'react-redux';
import { useAppSelector } from './app/hooks';
import { todosSlice } from './features/todos';
import { setTodos } from './features/todos';

export const App = () => {
const [listLoading, setListLoading] = useState(false);
Expand All @@ -17,10 +17,10 @@ export const App = () => {
setListLoading(true);
getTodos()
.then(array => {
dispatch(todosSlice.actions.setTodos(array));
dispatch(setTodos(array));
})
.finally(() => setListLoading(false));
}, []);
}, [dispatch]);

return (
<>
Expand Down
8 changes: 4 additions & 4 deletions src/components/TodoFilter/TodoFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import { filterSlice } from '../../features/filter';
import { useAppSelector } from '../../app/hooks';
import { setStatus, setQuery } from '../../features/filter';

export const TodoFilter: React.FC = () => {
const { query, status } = useAppSelector(state => state.filter);

const dispatch = useDispatch();

const handleStatus = (event: React.ChangeEvent<HTMLSelectElement>) => {
dispatch(filterSlice.actions.setStatus(event.target.value));
dispatch(setStatus(event.target.value));
};

const handleQuery = (event: React.ChangeEvent<HTMLInputElement>) => {
dispatch(filterSlice.actions.setQuery(event.target.value.toLowerCase()));
dispatch(setQuery(event.target.value.toLowerCase()));
};

return (
Expand Down Expand Up @@ -51,7 +51,7 @@ export const TodoFilter: React.FC = () => {
data-cy="clearSearchButton"
type="button"
className="delete"
onClick={() => dispatch(filterSlice.actions.setQuery(''))}
onClick={() => dispatch(setQuery(''))}
/>
)}
</span>
Expand Down
10 changes: 6 additions & 4 deletions src/components/TodoList/TodoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useAppSelector } from '../../app/hooks';
import classNames from 'classnames';
import { useDispatch } from 'react-redux';
import { currentTodoSlice } from '../../features/currentTodo';
import { setCurrentTodo } from '../../features/currentTodo';

export const TodoList: React.FC = () => {
const todos = useAppSelector(state => state.todos);
Expand Down Expand Up @@ -73,7 +73,7 @@ export const TodoList: React.FC = () => {
<button
onClick={() =>
dispatch(
currentTodoSlice.actions.setCurrentTodo({
setCurrentTodo({
id,
title,
completed,
Expand All @@ -88,8 +88,10 @@ export const TodoList: React.FC = () => {
<span className="icon">
<i
className={classNames('far', {
'fa-eye': currentTodo === null,
'fa-eye-slash': currentTodo !== null,
'fa-eye':
currentTodo === null || currentTodo.id !== id,
'fa-eye-slash':
currentTodo !== null && currentTodo.id === id,
})}
/>
</span>
Expand Down
6 changes: 3 additions & 3 deletions src/components/TodoModal/TodoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getUser } from '../../api';
import { useAppSelector } from '../../app/hooks';
import classNames from 'classnames';
import { useDispatch } from 'react-redux';
import { currentTodoSlice } from '../../features/currentTodo';
import { setCurrentTodo } from '../../features/currentTodo';

export const TodoModal: React.FC = () => {
const [modalLoading, setModalLoading] = useState(false);
Expand All @@ -25,10 +25,10 @@ export const TodoModal: React.FC = () => {
getUser(currentTodo.userId)
.then(data => setUser({ ...data }))
.finally(() => setModalLoading(false));
}, []);
}, [currentTodo]);

const closeModal = () => {
dispatch(currentTodoSlice.actions.setCurrentTodo(null));
dispatch(setCurrentTodo(null));
};

return (
Expand Down
2 changes: 2 additions & 0 deletions src/features/currentTodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export const currentTodoSlice = createSlice({
setCurrentTodo: (_, { payload }: PayloadAction<Todo | null>) => payload,
},
});

export const { setCurrentTodo } = currentTodoSlice.actions;
7 changes: 4 additions & 3 deletions src/features/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { Status } from '../types/Status';

const initialState = {
query: '',
Expand All @@ -10,13 +9,15 @@ export const filterSlice = createSlice({
name: 'filter',
initialState,
reducers: {
setStatus: ({ query }, { payload }: PayloadAction<Status>) => ({
setStatus: ({ query }, { payload }: PayloadAction<string>) => ({
query,
status: payload,
}),
setQuery: ({ status }, { payload }: PayloadAction<Status>) => ({
setQuery: ({ status }, { payload }: PayloadAction<string>) => ({
status,
query: payload,
}),
},
});

export const { setStatus, setQuery } = filterSlice.actions;
2 changes: 2 additions & 0 deletions src/features/todos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export const todosSlice = createSlice({
setTodos: (_, { payload }: PayloadAction<Todo[]>) => [...payload],
},
});

export const { setTodos } = todosSlice.actions;

0 comments on commit 1ce43cf

Please sign in to comment.