mirror of
https://github.com/ershisan99/it-incubator-todolist-ts-17-live-2024-08-17.git
synced 2026-02-04 21:02:13 +00:00
chore: refactor app reducer to use rtk
This commit is contained in:
@@ -11,12 +11,8 @@ import {
|
||||
UpdateTaskModelType,
|
||||
} from 'api/todolists-api'
|
||||
import { Dispatch } from 'redux'
|
||||
import { AppRootStateType } from 'app/store'
|
||||
import {
|
||||
SetAppErrorActionType,
|
||||
setAppStatusAC,
|
||||
SetAppStatusActionType,
|
||||
} from 'app/app-reducer'
|
||||
import { AppRootStateType, AppThunk } from 'app/store'
|
||||
import { setAppStatusAC } from 'app/app-reducer'
|
||||
import {
|
||||
handleServerAppError,
|
||||
handleServerNetworkError,
|
||||
@@ -103,8 +99,8 @@ export const setTasksAC = ({
|
||||
|
||||
// thunks
|
||||
export const fetchTasksTC =
|
||||
(todolistId: string) =>
|
||||
(dispatch: Dispatch<ActionsType | SetAppStatusActionType>) => {
|
||||
(todolistId: string): AppThunk =>
|
||||
(dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
todolistsAPI.getTasks(todolistId).then((res) => {
|
||||
const tasks = res.data.items
|
||||
@@ -122,12 +118,8 @@ export const removeTaskTC =
|
||||
}
|
||||
|
||||
export const addTaskTC =
|
||||
(title: string, todolistId: string) =>
|
||||
(
|
||||
dispatch: Dispatch<
|
||||
ActionsType | SetAppErrorActionType | SetAppStatusActionType
|
||||
>
|
||||
) => {
|
||||
(title: string, todolistId: string): AppThunk =>
|
||||
(dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
todolistsAPI
|
||||
.createTask(todolistId, title)
|
||||
@@ -151,8 +143,8 @@ export const updateTaskTC =
|
||||
taskId: string,
|
||||
domainModel: UpdateDomainTaskModelType,
|
||||
todolistId: string
|
||||
) =>
|
||||
(dispatch: ThunkDispatch, getState: () => AppRootStateType) => {
|
||||
): AppThunk =>
|
||||
(dispatch, getState: () => AppRootStateType) => {
|
||||
const state = getState()
|
||||
const task = state.tasks[todolistId].find((t) => t.id === taskId)
|
||||
if (!task) {
|
||||
@@ -210,6 +202,3 @@ type ActionsType =
|
||||
| RemoveTodolistActionType
|
||||
| SetTodolistsActionType
|
||||
| ReturnType<typeof setTasksAC>
|
||||
type ThunkDispatch = Dispatch<
|
||||
ActionsType | SetAppStatusActionType | SetAppErrorActionType
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user