chore: refactor app reducer to use rtk

This commit is contained in:
2024-08-17 18:33:20 +02:00
parent 7cd60b5c61
commit 5067f64ec3
4 changed files with 46 additions and 78 deletions

View File

@@ -1,11 +1,6 @@
import { todolistsAPI, TodolistType } from 'api/todolists-api'
import { Dispatch } from 'redux'
import {
RequestStatusType,
SetAppErrorActionType,
setAppStatusAC,
SetAppStatusActionType,
} from 'app/app-reducer'
import { RequestStatusType, setAppStatusAC } from 'app/app-reducer'
import { handleServerNetworkError } from 'utils/error-utils'
import { AppThunk } from 'app/store'
@@ -110,8 +105,8 @@ export const fetchTodolistsTC = (): AppThunk => {
})
}
}
export const removeTodolistTC = (todolistId: string) => {
return (dispatch: ThunkDispatch) => {
export const removeTodolistTC = (todolistId: string): AppThunk => {
return (dispatch) => {
//изменим глобальный статус приложения, чтобы вверху полоса побежала
dispatch(setAppStatusAC('loading'))
//изменим статус конкретного тудулиста, чтобы он мог задизеблить что надо
@@ -125,8 +120,8 @@ export const removeTodolistTC = (todolistId: string) => {
})
}
}
export const addTodolistTC = (title: string) => {
return (dispatch: ThunkDispatch) => {
export const addTodolistTC = (title: string): AppThunk => {
return (dispatch) => {
dispatch(setAppStatusAC('loading'))
todolistsAPI.createTodolist(title).then((res) => {
dispatch(addTodolistAC(res.data.data.item))
@@ -158,6 +153,3 @@ export type TodolistDomainType = TodolistType & {
filter: FilterValuesType
entityStatus: RequestStatusType
}
type ThunkDispatch = Dispatch<
ActionsType | SetAppStatusActionType | SetAppErrorActionType
>