mirror of
https://github.com/ershisan99/it-incubator-todolist-ts-17-live-2024-08-17.git
synced 2025-12-16 20:59:30 +00:00
chore: rename action creators to remove "AC"
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
appReducer,
|
||||
InitialStateType,
|
||||
setAppErrorAC,
|
||||
setAppStatusAC,
|
||||
setAppError,
|
||||
setAppStatus,
|
||||
} from './app-reducer'
|
||||
|
||||
let startState: InitialStateType
|
||||
@@ -16,11 +16,11 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
test('correct error message should be set', () => {
|
||||
const endState = appReducer(startState, setAppErrorAC('some error'))
|
||||
const endState = appReducer(startState, setAppError('some error'))
|
||||
expect(endState.error).toBe('some error')
|
||||
})
|
||||
|
||||
test('correct status should be set', () => {
|
||||
const endState = appReducer(startState, setAppStatusAC('loading'))
|
||||
const endState = appReducer(startState, setAppStatus('loading'))
|
||||
expect(endState.status).toBe('loading')
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { authAPI } from 'api/todolists-api'
|
||||
import { setIsLoggedInAC } from 'features/Login/auth-reducer'
|
||||
import { setIsLoggedIn } from 'features/Login/auth-reducer'
|
||||
import { AppThunk } from 'app/store'
|
||||
|
||||
export type RequestStatusType = 'idle' | 'loading' | 'succeeded' | 'failed'
|
||||
@@ -24,13 +24,13 @@ const appSlice = createSlice({
|
||||
name: 'app',
|
||||
initialState,
|
||||
reducers: {
|
||||
setAppErrorAC(state, action: PayloadAction<string | null>) {
|
||||
setAppError(state, action: PayloadAction<string | null>) {
|
||||
return { ...state, error: action.payload }
|
||||
},
|
||||
setAppStatusAC(state, action: PayloadAction<RequestStatusType>) {
|
||||
setAppStatus(state, action: PayloadAction<RequestStatusType>) {
|
||||
return { ...state, status: action.payload }
|
||||
},
|
||||
setAppInitializedAC(state, action: PayloadAction<boolean>) {
|
||||
setAppInitialized(state, action: PayloadAction<boolean>) {
|
||||
return { ...state, isInitialized: action.payload }
|
||||
},
|
||||
},
|
||||
@@ -38,16 +38,15 @@ const appSlice = createSlice({
|
||||
|
||||
export const appReducer = appSlice.reducer
|
||||
|
||||
export const { setAppInitializedAC, setAppStatusAC, setAppErrorAC } =
|
||||
appSlice.actions
|
||||
export const { setAppInitialized, setAppStatus, setAppError } = appSlice.actions
|
||||
|
||||
export const initializeAppTC = (): AppThunk => (dispatch) => {
|
||||
authAPI.me().then((res) => {
|
||||
if (res.data.resultCode === 0) {
|
||||
dispatch(setIsLoggedInAC(true))
|
||||
dispatch(setIsLoggedIn(true))
|
||||
} else {
|
||||
}
|
||||
|
||||
dispatch(setAppInitializedAC(true))
|
||||
dispatch(setAppInitialized(true))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
import { AppRootStateType } from 'app/store'
|
||||
import { setAppErrorAC } from 'app/app-reducer'
|
||||
import { setAppError } from 'app/app-reducer'
|
||||
import { AlertProps, Snackbar } from '@mui/material'
|
||||
import MuiAlert from '@mui/material/Alert'
|
||||
|
||||
@@ -31,7 +31,7 @@ export function ErrorSnackbar() {
|
||||
if (reason === 'clickaway') {
|
||||
return
|
||||
}
|
||||
dispatch(setAppErrorAC(null))
|
||||
dispatch(setAppError(null))
|
||||
}
|
||||
|
||||
const isOpen = error !== null
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { authAPI, LoginParamsType } from 'api/todolists-api'
|
||||
import { setAppStatusAC } from 'app/app-reducer'
|
||||
import { setAppStatus } from 'app/app-reducer'
|
||||
import {
|
||||
handleServerAppError,
|
||||
handleServerNetworkError,
|
||||
@@ -19,7 +19,7 @@ const authSlice = createSlice({
|
||||
name: 'auth',
|
||||
initialState,
|
||||
reducers: {
|
||||
setIsLoggedInAC(state, action: PayloadAction<boolean>) {
|
||||
setIsLoggedIn(state, action: PayloadAction<boolean>) {
|
||||
return { ...state, isLoggedIn: action.payload }
|
||||
},
|
||||
},
|
||||
@@ -27,19 +27,19 @@ const authSlice = createSlice({
|
||||
|
||||
export const authReducer = authSlice.reducer
|
||||
|
||||
export const { setIsLoggedInAC } = authSlice.actions
|
||||
export const { setIsLoggedIn } = authSlice.actions
|
||||
|
||||
// thunks
|
||||
export const loginTC =
|
||||
(data: LoginParamsType): AppThunk =>
|
||||
(dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
authAPI
|
||||
.login(data)
|
||||
.then((res) => {
|
||||
if (res.data.resultCode === 0) {
|
||||
dispatch(setIsLoggedInAC(true))
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(setIsLoggedIn(true))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
} else {
|
||||
handleServerAppError(res.data, dispatch)
|
||||
}
|
||||
@@ -50,13 +50,13 @@ export const loginTC =
|
||||
}
|
||||
|
||||
export const logoutTC = (): AppThunk => (dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
authAPI
|
||||
.logout()
|
||||
.then((res) => {
|
||||
if (res.data.resultCode === 0) {
|
||||
dispatch(setIsLoggedInAC(false))
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(setIsLoggedIn(false))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
} else {
|
||||
handleServerAppError(res.data, dispatch)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useSelector } from 'react-redux'
|
||||
import { AppRootStateType } from 'app/store'
|
||||
import {
|
||||
addTodolistTC,
|
||||
changeTodolistFilterAC,
|
||||
changeTodolistFilter,
|
||||
changeTodolistTitleTC,
|
||||
fetchTodolistsTC,
|
||||
FilterValuesType,
|
||||
@@ -80,7 +80,7 @@ export const TodolistsList: React.FC<PropsType> = ({ demo = false }) => {
|
||||
value: FilterValuesType,
|
||||
todolistId: string
|
||||
) {
|
||||
const action = changeTodolistFilterAC({ id: todolistId, filter: value })
|
||||
const action = changeTodolistFilter({ id: todolistId, filter: value })
|
||||
dispatch(action)
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import {
|
||||
addTaskAC,
|
||||
removeTaskAC,
|
||||
setTasksAC,
|
||||
addTask,
|
||||
removeTask,
|
||||
setTasks,
|
||||
tasksReducer,
|
||||
TasksStateType,
|
||||
updateTaskAC,
|
||||
updateTask,
|
||||
} from './tasks-reducer'
|
||||
|
||||
import {
|
||||
addTodolistAC,
|
||||
removeTodolistAC,
|
||||
setTodolistsAC,
|
||||
} from './todolists-reducer'
|
||||
import { addTodolist, removeTodolist, setTodolists } from './todolists-reducer'
|
||||
import { TaskPriorities, TaskStatuses } from 'api/todolists-api'
|
||||
|
||||
let startState: TasksStateType = {}
|
||||
@@ -97,7 +93,7 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
test('correct task should be deleted from correct array', () => {
|
||||
const action = removeTaskAC({ taskId: '2', todolistId: 'todolistId2' })
|
||||
const action = removeTask({ taskId: '2', todolistId: 'todolistId2' })
|
||||
|
||||
const endState = tasksReducer(startState, action)
|
||||
|
||||
@@ -106,8 +102,8 @@ test('correct task should be deleted from correct array', () => {
|
||||
expect(endState['todolistId2'].every((t) => t.id != '2')).toBeTruthy()
|
||||
})
|
||||
test('correct task should be added to correct array', () => {
|
||||
//const action = addTaskAC("juce", "todolistId2");
|
||||
const action = addTaskAC({
|
||||
//const action = addTask("juce", "todolistId2");
|
||||
const action = addTask({
|
||||
todoListId: 'todolistId2',
|
||||
title: 'juce',
|
||||
status: TaskStatuses.New,
|
||||
@@ -129,7 +125,7 @@ test('correct task should be added to correct array', () => {
|
||||
expect(endState['todolistId2'][0].status).toBe(TaskStatuses.New)
|
||||
})
|
||||
test('status of specified task should be changed', () => {
|
||||
const action = updateTaskAC({
|
||||
const action = updateTask({
|
||||
taskId: '2',
|
||||
model: { status: TaskStatuses.New },
|
||||
todolistId: 'todolistId2',
|
||||
@@ -141,7 +137,7 @@ test('status of specified task should be changed', () => {
|
||||
expect(endState['todolistId2'][1].status).toBe(TaskStatuses.New)
|
||||
})
|
||||
test('title of specified task should be changed', () => {
|
||||
const action = updateTaskAC({
|
||||
const action = updateTask({
|
||||
taskId: '2',
|
||||
model: { title: 'yogurt' },
|
||||
todolistId: 'todolistId2',
|
||||
@@ -154,7 +150,7 @@ test('title of specified task should be changed', () => {
|
||||
expect(endState['todolistId2'][0].title).toBe('bread')
|
||||
})
|
||||
test('new array should be added when new todolist is added', () => {
|
||||
const action = addTodolistAC({
|
||||
const action = addTodolist({
|
||||
id: 'blabla',
|
||||
title: 'new todolist',
|
||||
order: 0,
|
||||
@@ -173,7 +169,7 @@ test('new array should be added when new todolist is added', () => {
|
||||
expect(endState[newKey]).toEqual([])
|
||||
})
|
||||
test('propertry with todolistId should be deleted', () => {
|
||||
const action = removeTodolistAC('todolistId2')
|
||||
const action = removeTodolist('todolistId2')
|
||||
|
||||
const endState = tasksReducer(startState, action)
|
||||
|
||||
@@ -184,7 +180,7 @@ test('propertry with todolistId should be deleted', () => {
|
||||
})
|
||||
|
||||
test('empty arrays should be added when we set todolists', () => {
|
||||
const action = setTodolistsAC([
|
||||
const action = setTodolists([
|
||||
{ id: '1', title: 'title 1', order: 0, addedDate: '' },
|
||||
{ id: '2', title: 'title 2', order: 0, addedDate: '' },
|
||||
])
|
||||
@@ -198,7 +194,7 @@ test('empty arrays should be added when we set todolists', () => {
|
||||
expect(endState['2']).toBeDefined()
|
||||
})
|
||||
test('tasks should be added for todolist', () => {
|
||||
const action = setTasksAC({
|
||||
const action = setTasks({
|
||||
tasks: startState['todolistId1'],
|
||||
todolistId: 'todolistId1',
|
||||
})
|
||||
|
||||
@@ -7,12 +7,12 @@ import {
|
||||
} from 'api/todolists-api'
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import {
|
||||
addTodolistAC,
|
||||
removeTodolistAC,
|
||||
setTodolistsAC,
|
||||
addTodolist,
|
||||
removeTodolist,
|
||||
setTodolists,
|
||||
} from 'features/TodolistsList/todolists-reducer'
|
||||
import { AppRootStateType, AppThunk } from 'app/store'
|
||||
import { setAppStatusAC } from 'app/app-reducer'
|
||||
import { setAppStatus } from 'app/app-reducer'
|
||||
import {
|
||||
handleServerAppError,
|
||||
handleServerNetworkError,
|
||||
@@ -37,7 +37,7 @@ const tasksSlice = createSlice({
|
||||
name: 'tasks',
|
||||
initialState,
|
||||
reducers: {
|
||||
removeTaskAC(
|
||||
removeTask(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
taskId: string
|
||||
@@ -51,7 +51,7 @@ const tasksSlice = createSlice({
|
||||
),
|
||||
}
|
||||
},
|
||||
addTaskAC(state, action: PayloadAction<TaskType>) {
|
||||
addTask(state, action: PayloadAction<TaskType>) {
|
||||
return {
|
||||
...state,
|
||||
[action.payload.todoListId]: [
|
||||
@@ -60,7 +60,7 @@ const tasksSlice = createSlice({
|
||||
],
|
||||
}
|
||||
},
|
||||
updateTaskAC(
|
||||
updateTask(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
taskId: string
|
||||
@@ -78,7 +78,7 @@ const tasksSlice = createSlice({
|
||||
),
|
||||
}
|
||||
},
|
||||
setTasksAC(
|
||||
setTasks(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
tasks: Array<TaskType>
|
||||
@@ -90,15 +90,15 @@ const tasksSlice = createSlice({
|
||||
},
|
||||
extraReducers(builder) {
|
||||
builder
|
||||
.addCase(addTodolistAC, (state, action) => {
|
||||
.addCase(addTodolist, (state, action) => {
|
||||
return { ...state, [action.payload.id]: [] }
|
||||
})
|
||||
.addCase(removeTodolistAC, (state, action) => {
|
||||
.addCase(removeTodolist, (state, action) => {
|
||||
const copyState = { ...state }
|
||||
delete copyState[action.payload]
|
||||
return copyState
|
||||
})
|
||||
.addCase(setTodolistsAC, (state, action) => {
|
||||
.addCase(setTodolists, (state, action) => {
|
||||
const copyState = { ...state }
|
||||
action.payload.forEach((tl) => {
|
||||
copyState[tl.id] = []
|
||||
@@ -110,17 +110,16 @@ const tasksSlice = createSlice({
|
||||
|
||||
export const tasksReducer = tasksSlice.reducer
|
||||
|
||||
export const { removeTaskAC, setTasksAC, updateTaskAC, addTaskAC } =
|
||||
tasksSlice.actions
|
||||
export const { removeTask, setTasks, updateTask, addTask } = tasksSlice.actions
|
||||
|
||||
export const fetchTasksTC =
|
||||
(todolistId: string): AppThunk =>
|
||||
(dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
todolistsAPI.getTasks(todolistId).then((res) => {
|
||||
const tasks = res.data.items
|
||||
dispatch(setTasksAC({ tasks: tasks, todolistId: todolistId }))
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(setTasks({ tasks: tasks, todolistId: todolistId }))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -128,7 +127,7 @@ export const removeTaskTC =
|
||||
(taskId: string, todolistId: string): AppThunk =>
|
||||
(dispatch) => {
|
||||
todolistsAPI.deleteTask(todolistId, taskId).then((res) => {
|
||||
const action = removeTaskAC({ taskId: taskId, todolistId: todolistId })
|
||||
const action = removeTask({ taskId: taskId, todolistId: todolistId })
|
||||
dispatch(action)
|
||||
})
|
||||
}
|
||||
@@ -136,15 +135,15 @@ export const removeTaskTC =
|
||||
export const addTaskTC =
|
||||
(title: string, todolistId: string): AppThunk =>
|
||||
(dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
todolistsAPI
|
||||
.createTask(todolistId, title)
|
||||
.then((res) => {
|
||||
if (res.data.resultCode === 0) {
|
||||
const task = res.data.data.item
|
||||
const action = addTaskAC(task)
|
||||
const action = addTask(task)
|
||||
dispatch(action)
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
} else {
|
||||
handleServerAppError(res.data, dispatch)
|
||||
}
|
||||
@@ -183,7 +182,7 @@ export const updateTaskTC =
|
||||
.updateTask(todolistId, taskId, apiModel)
|
||||
.then((res) => {
|
||||
if (res.data.resultCode === 0) {
|
||||
const action = updateTaskAC({
|
||||
const action = updateTask({
|
||||
taskId: taskId,
|
||||
model: domainModel,
|
||||
todolistId: todolistId,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
addTodolistAC,
|
||||
changeTodolistEntityStatusAC,
|
||||
changeTodolistFilterAC,
|
||||
changeTodolistTitleAC,
|
||||
addTodolist,
|
||||
changeTodolistEntityStatus,
|
||||
changeTodolistFilter,
|
||||
changeTodolistTitle,
|
||||
FilterValuesType,
|
||||
removeTodolistAC,
|
||||
setTodolistsAC,
|
||||
removeTodolist,
|
||||
setTodolists,
|
||||
TodolistDomainType,
|
||||
todolistsReducer,
|
||||
} from './todolists-reducer'
|
||||
@@ -41,7 +41,7 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
test('correct todolist should be removed', () => {
|
||||
const endState = todolistsReducer(startState, removeTodolistAC(todolistId1))
|
||||
const endState = todolistsReducer(startState, removeTodolist(todolistId1))
|
||||
|
||||
expect(endState.length).toBe(1)
|
||||
expect(endState[0].id).toBe(todolistId2)
|
||||
@@ -55,7 +55,7 @@ test('correct todolist should be added', () => {
|
||||
order: 0,
|
||||
}
|
||||
|
||||
const endState = todolistsReducer(startState, addTodolistAC(todolist))
|
||||
const endState = todolistsReducer(startState, addTodolist(todolist))
|
||||
|
||||
expect(endState.length).toBe(3)
|
||||
expect(endState[0].title).toBe(todolist.title)
|
||||
@@ -65,7 +65,7 @@ test('correct todolist should be added', () => {
|
||||
test('correct todolist should change its name', () => {
|
||||
let newTodolistTitle = 'New Todolist'
|
||||
|
||||
const action = changeTodolistTitleAC({
|
||||
const action = changeTodolistTitle({
|
||||
id: todolistId2,
|
||||
title: newTodolistTitle,
|
||||
})
|
||||
@@ -79,7 +79,7 @@ test('correct todolist should change its name', () => {
|
||||
test('correct filter of todolist should be changed', () => {
|
||||
let newFilter: FilterValuesType = 'completed'
|
||||
|
||||
const action = changeTodolistFilterAC({ id: todolistId2, filter: newFilter })
|
||||
const action = changeTodolistFilter({ id: todolistId2, filter: newFilter })
|
||||
|
||||
const endState = todolistsReducer(startState, action)
|
||||
|
||||
@@ -87,7 +87,7 @@ test('correct filter of todolist should be changed', () => {
|
||||
expect(endState[1].filter).toBe(newFilter)
|
||||
})
|
||||
test('todolists should be added', () => {
|
||||
const action = setTodolistsAC(startState)
|
||||
const action = setTodolists(startState)
|
||||
|
||||
const endState = todolistsReducer([], action)
|
||||
|
||||
@@ -96,7 +96,7 @@ test('todolists should be added', () => {
|
||||
test('correct entity status of todolist should be changed', () => {
|
||||
let newStatus: RequestStatusType = 'loading'
|
||||
|
||||
const action = changeTodolistEntityStatusAC({
|
||||
const action = changeTodolistEntityStatus({
|
||||
id: todolistId2,
|
||||
status: newStatus,
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { todolistsAPI, TodolistType } from 'api/todolists-api'
|
||||
import { RequestStatusType, setAppStatusAC } from 'app/app-reducer'
|
||||
import { RequestStatusType, setAppStatus } from 'app/app-reducer'
|
||||
import { AppThunk } from 'app/store'
|
||||
import { handleServerNetworkError } from 'utils/error-utils'
|
||||
|
||||
@@ -16,16 +16,16 @@ const todolistsSlice = createSlice({
|
||||
name: 'todolists',
|
||||
initialState,
|
||||
reducers: {
|
||||
removeTodolistAC(state, action: PayloadAction<string>) {
|
||||
removeTodolist(state, action: PayloadAction<string>) {
|
||||
return state.filter((tl) => tl.id != action.payload)
|
||||
},
|
||||
addTodolistAC(state, action: PayloadAction<TodolistType>) {
|
||||
addTodolist(state, action: PayloadAction<TodolistType>) {
|
||||
return [
|
||||
{ ...action.payload, filter: 'all', entityStatus: 'idle' },
|
||||
...state,
|
||||
]
|
||||
},
|
||||
changeTodolistTitleAC(
|
||||
changeTodolistTitle(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
id: string
|
||||
@@ -38,7 +38,7 @@ const todolistsSlice = createSlice({
|
||||
: tl
|
||||
)
|
||||
},
|
||||
changeTodolistFilterAC(
|
||||
changeTodolistFilter(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
id: string
|
||||
@@ -51,7 +51,7 @@ const todolistsSlice = createSlice({
|
||||
: tl
|
||||
)
|
||||
},
|
||||
changeTodolistEntityStatusAC(
|
||||
changeTodolistEntityStatus(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
id: string
|
||||
@@ -64,7 +64,7 @@ const todolistsSlice = createSlice({
|
||||
: tl
|
||||
)
|
||||
},
|
||||
setTodolistsAC(state, action: PayloadAction<Array<TodolistType>>) {
|
||||
setTodolists(state, action: PayloadAction<Array<TodolistType>>) {
|
||||
return action.payload.map((tl) => ({
|
||||
...tl,
|
||||
filter: 'all',
|
||||
@@ -75,24 +75,24 @@ const todolistsSlice = createSlice({
|
||||
})
|
||||
|
||||
export const {
|
||||
changeTodolistEntityStatusAC,
|
||||
changeTodolistFilterAC,
|
||||
changeTodolistTitleAC,
|
||||
addTodolistAC,
|
||||
removeTodolistAC,
|
||||
setTodolistsAC,
|
||||
changeTodolistEntityStatus,
|
||||
changeTodolistFilter,
|
||||
changeTodolistTitle,
|
||||
addTodolist,
|
||||
removeTodolist,
|
||||
setTodolists,
|
||||
} = todolistsSlice.actions
|
||||
|
||||
export const todolistsReducer = todolistsSlice.reducer
|
||||
|
||||
export const fetchTodolistsTC = (): AppThunk => {
|
||||
return (dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
todolistsAPI
|
||||
.getTodolists()
|
||||
.then((res) => {
|
||||
dispatch(setTodolistsAC(res.data))
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(setTodolists(res.data))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
})
|
||||
.catch((error) => {
|
||||
handleServerNetworkError(error, dispatch)
|
||||
@@ -102,31 +102,29 @@ export const fetchTodolistsTC = (): AppThunk => {
|
||||
export const removeTodolistTC = (todolistId: string): AppThunk => {
|
||||
return (dispatch) => {
|
||||
//изменим глобальный статус приложения, чтобы вверху полоса побежала
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
//изменим статус конкретного тудулиста, чтобы он мог задизеблить что надо
|
||||
dispatch(
|
||||
changeTodolistEntityStatusAC({ id: todolistId, status: 'loading' })
|
||||
)
|
||||
dispatch(changeTodolistEntityStatus({ id: todolistId, status: 'loading' }))
|
||||
todolistsAPI.deleteTodolist(todolistId).then((res) => {
|
||||
dispatch(removeTodolistAC(todolistId))
|
||||
dispatch(removeTodolist(todolistId))
|
||||
//скажем глобально приложению, что асинхронная операция завершена
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
})
|
||||
}
|
||||
}
|
||||
export const addTodolistTC = (title: string): AppThunk => {
|
||||
return (dispatch) => {
|
||||
dispatch(setAppStatusAC('loading'))
|
||||
dispatch(setAppStatus('loading'))
|
||||
todolistsAPI.createTodolist(title).then((res) => {
|
||||
dispatch(addTodolistAC(res.data.data.item))
|
||||
dispatch(setAppStatusAC('succeeded'))
|
||||
dispatch(addTodolist(res.data.data.item))
|
||||
dispatch(setAppStatus('succeeded'))
|
||||
})
|
||||
}
|
||||
}
|
||||
export const changeTodolistTitleTC = (id: string, title: string): AppThunk => {
|
||||
return (dispatch) => {
|
||||
todolistsAPI.updateTodolist(id, title).then((res) => {
|
||||
dispatch(changeTodolistTitleAC({ id: id, title: title }))
|
||||
dispatch(changeTodolistTitle({ id: id, title: title }))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
addTodolistAC,
|
||||
addTodolist,
|
||||
TodolistDomainType,
|
||||
todolistsReducer,
|
||||
} from './todolists-reducer'
|
||||
@@ -17,7 +17,7 @@ test('ids should be equals', () => {
|
||||
order: 0,
|
||||
}
|
||||
|
||||
const action = addTodolistAC(todolist)
|
||||
const action = addTodolist(todolist)
|
||||
|
||||
const endTasksState = tasksReducer(startTasksState, action)
|
||||
const endTodolistsState = todolistsReducer(startTodolistsState, action)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { setAppErrorAC, setAppStatusAC } from 'app/app-reducer'
|
||||
import { setAppError, setAppStatus } from 'app/app-reducer'
|
||||
import { ResponseType } from 'api/todolists-api'
|
||||
import { Dispatch } from 'redux'
|
||||
|
||||
@@ -7,17 +7,17 @@ export const handleServerAppError = <D>(
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
if (data.messages.length) {
|
||||
dispatch(setAppErrorAC(data.messages[0]))
|
||||
dispatch(setAppError(data.messages[0]))
|
||||
} else {
|
||||
dispatch(setAppErrorAC('Some error occurred'))
|
||||
dispatch(setAppError('Some error occurred'))
|
||||
}
|
||||
dispatch(setAppStatusAC('failed'))
|
||||
dispatch(setAppStatus('failed'))
|
||||
}
|
||||
|
||||
export const handleServerNetworkError = (
|
||||
error: { message: string },
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
dispatch(setAppErrorAC(error.message ? error.message : 'Some error occurred'))
|
||||
dispatch(setAppStatusAC('failed'))
|
||||
dispatch(setAppError(error.message ? error.message : 'Some error occurred'))
|
||||
dispatch(setAppStatus('failed'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user