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: prepare todolists reducer for rtk (use single argument in action creators)
This commit is contained in:
@@ -80,7 +80,7 @@ export const TodolistsList: React.FC<PropsType> = ({ demo = false }) => {
|
|||||||
value: FilterValuesType,
|
value: FilterValuesType,
|
||||||
todolistId: string
|
todolistId: string
|
||||||
) {
|
) {
|
||||||
const action = changeTodolistFilterAC(todolistId, value)
|
const action = changeTodolistFilterAC({ id: todolistId, filter: value })
|
||||||
dispatch(action)
|
dispatch(action)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,10 @@ test('correct todolist should be added', () => {
|
|||||||
test('correct todolist should change its name', () => {
|
test('correct todolist should change its name', () => {
|
||||||
let newTodolistTitle = 'New Todolist'
|
let newTodolistTitle = 'New Todolist'
|
||||||
|
|
||||||
const action = changeTodolistTitleAC(todolistId2, newTodolistTitle)
|
const action = changeTodolistTitleAC({
|
||||||
|
id: todolistId2,
|
||||||
|
title: newTodolistTitle,
|
||||||
|
})
|
||||||
|
|
||||||
const endState = todolistsReducer(startState, action)
|
const endState = todolistsReducer(startState, action)
|
||||||
|
|
||||||
@@ -76,7 +79,7 @@ test('correct todolist should change its name', () => {
|
|||||||
test('correct filter of todolist should be changed', () => {
|
test('correct filter of todolist should be changed', () => {
|
||||||
let newFilter: FilterValuesType = 'completed'
|
let newFilter: FilterValuesType = 'completed'
|
||||||
|
|
||||||
const action = changeTodolistFilterAC(todolistId2, newFilter)
|
const action = changeTodolistFilterAC({ id: todolistId2, filter: newFilter })
|
||||||
|
|
||||||
const endState = todolistsReducer(startState, action)
|
const endState = todolistsReducer(startState, action)
|
||||||
|
|
||||||
@@ -93,7 +96,10 @@ test('todolists should be added', () => {
|
|||||||
test('correct entity status of todolist should be changed', () => {
|
test('correct entity status of todolist should be changed', () => {
|
||||||
let newStatus: RequestStatusType = 'loading'
|
let newStatus: RequestStatusType = 'loading'
|
||||||
|
|
||||||
const action = changeTodolistEntityStatusAC(todolistId2, newStatus)
|
const action = changeTodolistEntityStatusAC({
|
||||||
|
id: todolistId2,
|
||||||
|
status: newStatus,
|
||||||
|
})
|
||||||
|
|
||||||
const endState = todolistsReducer(startState, action)
|
const endState = todolistsReducer(startState, action)
|
||||||
|
|
||||||
|
|||||||
@@ -50,24 +50,43 @@ export const todolistsReducer = (
|
|||||||
// actions
|
// actions
|
||||||
export const removeTodolistAC = (id: string) =>
|
export const removeTodolistAC = (id: string) =>
|
||||||
({ type: 'REMOVE-TODOLIST', id }) as const
|
({ type: 'REMOVE-TODOLIST', id }) as const
|
||||||
|
|
||||||
export const addTodolistAC = (todolist: TodolistType) =>
|
export const addTodolistAC = (todolist: TodolistType) =>
|
||||||
({ type: 'ADD-TODOLIST', todolist }) as const
|
({ type: 'ADD-TODOLIST', todolist }) as const
|
||||||
export const changeTodolistTitleAC = (id: string, title: string) =>
|
|
||||||
|
export const changeTodolistTitleAC = ({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
id: string
|
||||||
|
title: string
|
||||||
|
}) =>
|
||||||
({
|
({
|
||||||
type: 'CHANGE-TODOLIST-TITLE',
|
type: 'CHANGE-TODOLIST-TITLE',
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
}) as const
|
}) as const
|
||||||
export const changeTodolistFilterAC = (id: string, filter: FilterValuesType) =>
|
|
||||||
|
export const changeTodolistFilterAC = ({
|
||||||
|
id,
|
||||||
|
filter,
|
||||||
|
}: {
|
||||||
|
id: string
|
||||||
|
filter: FilterValuesType
|
||||||
|
}) =>
|
||||||
({
|
({
|
||||||
type: 'CHANGE-TODOLIST-FILTER',
|
type: 'CHANGE-TODOLIST-FILTER',
|
||||||
id,
|
id,
|
||||||
filter,
|
filter,
|
||||||
}) as const
|
}) as const
|
||||||
export const changeTodolistEntityStatusAC = (
|
|
||||||
id: string,
|
export const changeTodolistEntityStatusAC = ({
|
||||||
|
id,
|
||||||
|
status,
|
||||||
|
}: {
|
||||||
|
id: string
|
||||||
status: RequestStatusType
|
status: RequestStatusType
|
||||||
) =>
|
}) =>
|
||||||
({
|
({
|
||||||
type: 'CHANGE-TODOLIST-ENTITY-STATUS',
|
type: 'CHANGE-TODOLIST-ENTITY-STATUS',
|
||||||
id,
|
id,
|
||||||
@@ -96,7 +115,9 @@ export const removeTodolistTC = (todolistId: string) => {
|
|||||||
//изменим глобальный статус приложения, чтобы вверху полоса побежала
|
//изменим глобальный статус приложения, чтобы вверху полоса побежала
|
||||||
dispatch(setAppStatusAC('loading'))
|
dispatch(setAppStatusAC('loading'))
|
||||||
//изменим статус конкретного тудулиста, чтобы он мог задизеблить что надо
|
//изменим статус конкретного тудулиста, чтобы он мог задизеблить что надо
|
||||||
dispatch(changeTodolistEntityStatusAC(todolistId, 'loading'))
|
dispatch(
|
||||||
|
changeTodolistEntityStatusAC({ id: todolistId, status: 'loading' })
|
||||||
|
)
|
||||||
todolistsAPI.deleteTodolist(todolistId).then((res) => {
|
todolistsAPI.deleteTodolist(todolistId).then((res) => {
|
||||||
dispatch(removeTodolistAC(todolistId))
|
dispatch(removeTodolistAC(todolistId))
|
||||||
//скажем глобально приложению, что асинхронная операция завершена
|
//скажем глобально приложению, что асинхронная операция завершена
|
||||||
@@ -116,7 +137,7 @@ export const addTodolistTC = (title: string) => {
|
|||||||
export const changeTodolistTitleTC = (id: string, title: string) => {
|
export const changeTodolistTitleTC = (id: string, title: string) => {
|
||||||
return (dispatch: Dispatch<ActionsType>) => {
|
return (dispatch: Dispatch<ActionsType>) => {
|
||||||
todolistsAPI.updateTodolist(id, title).then((res) => {
|
todolistsAPI.updateTodolist(id, title).then((res) => {
|
||||||
dispatch(changeTodolistTitleAC(id, title))
|
dispatch(changeTodolistTitleAC({ id: id, title: title }))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user