Skip to content
Snippets Groups Projects
Commit 8259a6b1 authored by Isaac Evavold's avatar Isaac Evavold
Browse files

ROENROLL-1554 preserve course order inside saved-for-later

parent d8d82669
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ import { DegreePlannerState } from '@app/degree-planner/store/state';
import {
AddSaveForLater,
RemoveCourse,
MoveCourseInsideSFL,
} from '@app/degree-planner/store/actions/course.actions';
import * as selectors from '@app/degree-planner/store/selectors';
import { distinctUntilChanged } from 'rxjs/operators';
......@@ -69,6 +70,14 @@ export class SavedForLaterContainerComponent implements OnInit {
recordId: course.id as number,
}),
);
} else if (newContainerId === previousContainerId) {
const course = event.item.data as SavedForLaterCourse;
this.store.dispatch(
new MoveCourseInsideSFL({
courseId: course.courseId,
newIndex: event.currentIndex,
}),
);
}
}
}
......@@ -13,6 +13,8 @@ export enum CourseActionTypes {
MoveCourseBetweenTerms = '[Course] Move Between Terms',
MoveCourseBetweenTermsSuccess = '[Course] Move Between Terms (Success)',
MoveCourseInsideSFL = '[Course] Move Inside SFL',
AddSaveForLater = '[Course] Add Save for Later',
AddSaveForLaterSuccess = '[Course] Add Save for Later (Success)',
......@@ -29,6 +31,11 @@ export class MoveCourseInsideTerm implements Action {
) {}
}
export class MoveCourseInsideSFL implements Action {
public readonly type = CourseActionTypes.MoveCourseInsideSFL;
constructor(public payload: { courseId: string; newIndex: number }) {}
}
export class MoveCourseBetweenTerms implements Action {
public readonly type = CourseActionTypes.MoveCourseBetweenTerms;
constructor(
......
......@@ -28,6 +28,7 @@ import {
AddCourseSuccess,
RemoveSaveForLater,
AddSaveForLater,
MoveCourseInsideSFL,
} from '@app/degree-planner/store/actions/course.actions';
import {
NoteActionTypes,
......@@ -68,6 +69,7 @@ type SupportedActions =
| WriteNoteSuccess
| DeleteNote
| MoveCourseInsideTerm
| MoveCourseInsideSFL
| MoveCourseBetweenTerms
| RemoveCourse
| AddCourse
......@@ -334,6 +336,21 @@ export function degreePlannerReducer(
return state;
}
case CourseActionTypes.MoveCourseInsideSFL: {
const { courseId, newIndex } = action.payload;
const courses = state.savedForLaterCourses.slice();
const course = courses.find(c => c.courseId === courseId);
if (course) {
const oldIndex = courses.findIndex(c => c.courseId === courseId);
courses.splice(oldIndex, 1);
courses.splice(newIndex, 0, course);
return { ...state, savedForLaterCourses: courses };
}
return state;
}
case CourseActionTypes.MoveCourseBetweenTerms: {
const {
to: toTermCode,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment