public static WorkbanchCourseState ReduceRemoveWorkbanchCourseRecordAction(WorkbanchCourseState state, RemoveWorkbanchCourseRecordAction action) { var rec = state.Course.RootRecord.Find(action.Record.Id); if (rec != null) { var recParent = state.Course.RootRecord.Find(r => r.Children != null && r.Children.Contains(action.Record)); if (recParent != null) { recParent.Children.Remove(action.Record); } } return(new WorkbanchCourseState(state.IsLoading, state.Course)); }
public static WorkbanchCourseState ReduceAddWorkbanchCourseRecordAction(WorkbanchCourseState state, AddWorkbanchCourseRecordAction action) { if (state.Course.RootRecord.Contains(action.ParentRecord.Id)) { if (action.ParentRecord.Children == null) { action.ParentRecord.Children = new(); } if (action.Record.Type == RecordType.Article) { action.Record.Id = Guid.NewGuid(); } else if (action.Record.Children == null) { action.Record.Children = new(); } action.ParentRecord.Children = new(action.ParentRecord.Children.Prepend(action.Record)); } return(new WorkbanchCourseState(state.IsLoading, state.Course)); }
public static WorkbanchCourseState ReduceMoveWorkbanchCourseRecordAction(WorkbanchCourseState state, MoveWorkbanchCourseRecordAction action) { if (state.Course.RootRecord.Contains(action.Record.Id)) { if (action.PreviousElement != null && state.Course.RootRecord.Contains(action.PreviousElement.Id)) { var destParent = action.DestinationParent != null && state.Course.RootRecord.Contains(action.DestinationParent.Id) ? action.DestinationParent : state.Course.RootRecord.Find(r => r.Children != null && r.Children.Contains(action.PreviousElement)); state.Course.RootRecord.Find(r => r.Children != null && r.Children.Contains(action.Record)).Children.Remove(action.Record); destParent.Children.Insert(destParent.Children.IndexOf(action.PreviousElement) + 1, action.Record); } else { if (action.DestinationParent != null && state.Course.RootRecord.Contains(action.DestinationParent.Id) && action.Record != action.DestinationParent) { state.Course.RootRecord.Find(r => r.Children != null && r.Children.Contains(action.Record)).Children.Remove(action.Record); action.DestinationParent.Children = action.DestinationParent.Children.Prepend(action.Record).ToList(); } } } return(new WorkbanchCourseState(state.IsLoading, state.Course)); }
public static WorkbanchCourseState ReduceEditWorkbanchCourseRecordAction(WorkbanchCourseState state, EditWorkbanchCourseRecordAction action) { state.Course.RootRecord.Find(action.Record.Id).Title = action.Record.Title; return(new WorkbanchCourseState(state.IsLoading, state.Course)); }
public static WorkbanchCourseState ReduceSetWorkbanchCourseAction(WorkbanchCourseState state, SetWorkbanchCourseAction action) { return(new WorkbanchCourseState(false, action.Course)); }
public static WorkbanchCourseState ReduceFetchWorkbanchCourseAction(WorkbanchCourseState state, FetchWorkbanchCourseAction action) => new WorkbanchCourseState(true, state.Course);