Вот кусок моего кода (это редьюсер туду листа):
let initialState={
newLists:[{list:null,tasks:[]}],//созданные листы
completedTasks:[{list:null,tasks:[]}],//завершенные задачи
setWindow:[{list:null,task:'',set:false}],//открыть-закрыть окно настроек задачи
note:[{list:'',task:'',note:''}],//заметки
date:[{list:'',task:'',date:''}],//дата,выбранная в календаре
isCalendarForAdd:[{list:'',task:'',check:false}],//открытие-закрытие календаря в окне настроек задач
flagForSelectedDateFordd:[{list:'',str:''}],//фильтрация по промежутку времени
repeateForAdd:[{list:'',task:'',days:[]}]//выбор дней для повтора задачи
};
const navReducer=(state=initialState, action)=>{
switch (action.type) {
case 'CHANGE_VALUE_TASK_ADD':
state.newLists.forEach(item=>{
if(item.list===action.list){
item.tasks.forEach((i,index,arr)=>{
if(i===action.def){
arr[index]=action.add
}
})
}
});
return {...state,newLists:[...state.newLists]}
case 'DELETE_LIST':
state.newLists.forEach((item,i,arr)=>{
if(item.list===action.list){
arr.splice(i,1);
}
});
return {...state,newLists:[...state.newLists]}
case 'MOVE_INTO_COMPLETED_TASKS':
let previousTask;
state.newLists.forEach((item,i)=>{
if(item.list===action.listName){
item.tasks.forEach((element,ind,array)=>{
if(action.task===element){
array[ind-1]?previousTask=array[ind-1]:previousTask=null
}
});
let move_to_competed_flag;
state.completedTasks.forEach((elem,index,arr)=>{
if(elem.list===action.listName){
elem.tasks.push({current:action.task,previous:previousTask})
return move_to_competed_flag=true;
}else{return move_to_competed_flag=false;}});
if(move_to_competed_flag===false){
state.completedTasks.push({list:action.listName,tasks:[{current:action.task,previous:previousTask}]});
} ;
item.tasks.length>1 ? item.tasks=item.tasks.filter(item=>item!==action.task) : item.tasks.splice(0,1)
};
})
return {...state,newLists:[...state.newLists],completedTasks:[...state.completedTasks]}
case 'MOVE_INTO_ACTIVE_TASKS':
let prevTask;
state.completedTasks.forEach((item,i,arr)=>{
if(item.list===action.listName){
arr[i].tasks.forEach((elem,index,mass)=>{
if(elem.current===action.task){
mass.splice(index,1);
prevTask=elem.previous;
};
});
};
});
let move_to_active_flag;
let notFoundPrevCount=1;
state.newLists.forEach((item,i,arr)=>{
if(item.list===action.listName){
item.tasks.forEach((el,index,mass)=>{
if(el===prevTask){
if(mass.length>1){
let rest_arr=mass.splice(index+1)
mass.push(action.task);
mass.push(...rest_arr)
}else{
mass.push(action.task)
};
notFoundPrevCount+=2;
};
});
if(prevTask===null ||notFoundPrevCount===1){
item.tasks.unshift(action.task);
};
if(item.tasks.length===0){
item.tasks.push(action.task)
};
return move_to_active_flag=true;
}else{
return move_to_active_flag=false;
}
});
if(move_to_active_flag===false){
state.newLists.unshift({list:action.listName,tasks:[action.task]})
};
return {...state,newLists:[...state.newLists],completedTasks:[...state.completedTasks]}
case 'HAS_NOTE_ADD':
let flagForNote=false;
state.note.forEach((item,i,arr)=>{
if(item?.list===action.listName && item?.task===action.task){
if(action.value==='') delete arr[i]
item.note=action.value;
flagForNote=true;
};
});
if(!flagForNote){
state.note.push({list:action.listName,task:action.task,note:action.value})
};
return {...state,note:[...state.note]};
default:
return state;
}
}
export const changeAddListTaskTextCreator=(list,def,add)=>{
return {
type:'CHANGE_VALUE_TASK_ADD',list,def,add
}
};
export const deleteListCreator=(list)=>{
return {
type:'DELETE_LIST',list
}
};
export const moveIntoCompletedTasks=(listName,task)=>{
return {
type:'MOVE_INTO_COMPLETED_TASKS',listName,task
}
};
export const moveToActiveTasksAgainInAddingList=(listName,task)=>{
return {
type:'MOVE_INTO_ACTIVE_TASKS',listName,task
}
};
export const hasNoteForAdd=(listName,task,value)=>{
return {
type:'HAS_NOTE_ADD',listName,task,value
}
};
export default navReducer