-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,543 additions
and
2,114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,66 @@ | ||
import 'bulma/css/bulma.css'; | ||
import '@fortawesome/fontawesome-free/css/all.css'; | ||
import { Loader, TodoFilter, TodoList, TodoModal } from './components'; | ||
import { useEffect, useState } from 'react'; | ||
import { getTodos, getUser } from './api'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setTodos } from './features/todos'; | ||
import { Todo } from './types/Todo'; | ||
import { saveTodo } from './features/currentTodo'; | ||
|
||
export const App = () => ( | ||
<> | ||
<div className="section"> | ||
<div className="container"> | ||
<div className="box"> | ||
<h1 className="title">Todos:</h1> | ||
export const App = () => { | ||
const dispatch = useDispatch(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [isOpenerMOdal, setIsOpenerMOdal] = useState(false); | ||
|
||
<div className="block"> | ||
<TodoFilter /> | ||
</div> | ||
useEffect(() => { | ||
setIsLoading(true); | ||
getTodos() | ||
.then(todos => { | ||
dispatch(setTodos(todos)); | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
}, []); | ||
|
||
const openerModalWindow = async (userId: number, todo: Todo) => { | ||
setIsOpenerMOdal(true); | ||
|
||
const user = await getUser(userId); | ||
|
||
dispatch( | ||
saveTodo({ | ||
...todo, | ||
user, | ||
}), | ||
); | ||
|
||
setTimeout(() => { | ||
setIsOpenerMOdal(false); | ||
}, 300); | ||
}; | ||
|
||
<div className="block"> | ||
<Loader /> | ||
<TodoList /> | ||
return ( | ||
<> | ||
<div className="section"> | ||
<div className="container"> | ||
<div className="box"> | ||
<h1 className="title">Todos:</h1> | ||
|
||
<div className="block"> | ||
<TodoFilter /> | ||
</div> | ||
|
||
<div className="block"> | ||
{isLoading && <Loader />} | ||
|
||
{!isLoading && <TodoList openerModalWindow={openerModalWindow} />} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<TodoModal /> | ||
</> | ||
); | ||
<TodoModal isOpenerMOdal={isOpenerMOdal} /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import { combineSlices, configureStore } from '@reduxjs/toolkit'; | ||
import filterReducer, { FilterStateSlice } from '../features/filter'; | ||
import todosReducer, { TodosState } from '../features/todos'; | ||
import currentTodoReducer, { CurrentTodoState } from '../features/currentTodo'; | ||
|
||
const rootReducer = combineSlices(); | ||
const rootReducer = combineSlices({ | ||
filterSlice: filterReducer, | ||
todosSlice: todosReducer, | ||
currentTodoSlice: currentTodoReducer, | ||
}); | ||
|
||
export const store = configureStore({ | ||
reducer: rootReducer, | ||
}); | ||
|
||
export type RootState = ReturnType<typeof rootReducer>; | ||
export type RootState = { | ||
filterSlice: FilterStateSlice; | ||
todosSlice: TodosState; | ||
currentTodoSlice: CurrentTodoState; | ||
}; | ||
export type AppDispatch = typeof store.dispatch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.