public static TodosState ReduceDeleteTodoSuccessAction(TodosState state, DeleteTodoSuccessAction action) { // Return the default state if no list of todos is found if (state.CurrentTodos is null) { return(new TodosState(false, null, null, state.CurrentTodo)); } // Create a new list with all todo items excluding the todo with the deleted ID var updatedTodos = state.CurrentTodos.Where(t => t.Id != action.Id); return(new TodosState(false, null, updatedTodos, state.CurrentTodo)); }
public static TodosState ReduceCreateTodoSuccessAction(TodosState state, CreateTodoSuccessAction action) { // Grab a reference to the current todo list, or initialize one if we do not currently have any loaded var currentTodos = state.CurrentTodos is null ? new List <TodoDto>() : state.CurrentTodos.ToList(); // Add the newly created todo to our list and sort by ID currentTodos.Add(action.Todo); currentTodos = currentTodos .OrderBy(t => t.Id) .ToList(); return(new TodosState(false, null, currentTodos, state.CurrentTodo)); }
public static TodosState ReduceUpdateTodoSuccessAction(TodosState state, UpdateTodoSuccessAction action) { // If the current todos list is null, set the state with a new list containing the updated todo if (state.CurrentTodos is null) { return(new TodosState(false, null, new List <TodoDto> { action.Todo }, state.CurrentTodo)); } // Rather than mutating in place, let's construct a new list and add our updated item var updatedList = state.CurrentTodos .Where(t => t.Id != action.Todo.Id) .ToList(); // Add the todo and sort the list updatedList.Add(action.Todo); updatedList = updatedList .OrderBy(t => t.Id) .ToList(); return(new TodosState(false, null, updatedList, null)); }
public static TodosState ReduceCreateTodoFailureAction(TodosState state, CreateTodoFailureAction action) => new TodosState(false, action.ErrorMessage, state.CurrentTodos, state.CurrentTodo);
public static TodosState ReduceCreateTodoAction(TodosState state, CreateTodoAction _) => new TodosState(true, null, state.CurrentTodos, state.CurrentTodo);
public static TodosState InitializeTodosAction(TodosState state, InitializeTodosAction action) => new TodosState(false, null, action.Todos, state.CurrentTodo);
public static TodosState ReduceLoadTodosAction(TodosState state, LoadTodosAction _) => new TodosState(true, null, null, state.CurrentTodo);
public static TodosState ReduceLoadTodosFailureAction(TodosState state, LoadTodosFailureAction action) => new TodosState(false, action.ErrorMessage, null, state.CurrentTodo);
public static TodosState ReduceLoadTodosSuccessAction(TodosState state, LoadTodosSuccessAction action) => new TodosState(false, null, action.Todos, state.CurrentTodo);
public static TodosState ReduceNavigationAction(TodosState state, GoAction _) => new TodosState(state.IsLoading, null, state.CurrentTodos, state.CurrentTodo);