diff --git a/src/app/degree-planner/store/effects/plan.effects.ts b/src/app/degree-planner/store/effects/plan.effects.ts index 3b9021567b3243b5f58f194d11f7723586c004ee..aedbc86c25ad80b21b0bc750d0df11e7134cd5de 100644 --- a/src/app/degree-planner/store/effects/plan.effects.ts +++ b/src/app/degree-planner/store/effects/plan.effects.ts @@ -59,7 +59,6 @@ export class DegreePlanEffects { @Effect() init$ = this.actions$.pipe( ofType(ROOT_EFFECTS_INIT), - // Load the list of degree plans and data used by all degree plans. flatMap(() => { const activeTermCodes = this.api @@ -72,7 +71,6 @@ export class DegreePlanEffects { activeTermCodes, }); }), - // Load data specific to the primary degree plan. flatMap(({ allDegreePlans, subjects, activeTermCodes }) => { const savedForLaterCourses = this.loadSavedForLaterCourses(subjects); @@ -93,7 +91,6 @@ export class DegreePlanEffects { subjects: of(subjects), }); }), - map(payload => { const allTerms = payload.visibleTerms.map(term => term.termCode); const currentIndex = allTerms.indexOf(payload.activeTermCodes[0]); @@ -105,12 +102,10 @@ export class DegreePlanEffects { return { ...payload, expandedYears }; }), - map( payload => new InitialLoadSuccess({ ...INITIAL_DEGREE_PLANNER_STATE, ...payload }), ), - catchError(error => { return of( new PlanError({ @@ -125,9 +120,7 @@ export class DegreePlanEffects { @Effect() switch$ = this.actions$.pipe( ofType<SwitchPlan>(PlanActionTypes.SwitchPlan), - withLatestFrom(this.store$.select(getDegreePlannerState)), - flatMap(([action, state]) => { const visibleDegreePlan = state.allDegreePlans.find(plan => { return plan.roadmapId === action.payload.newVisibleRoadmapId; @@ -145,15 +138,12 @@ export class DegreePlanEffects { visibleTerms, }); }), - map(payload => new SwitchPlanSuccess(payload)), - tap(state => { const touchedPlan = state.payload.visibleDegreePlan.name; const message = `Switched to ${touchedPlan}`; this.snackBar.open(message, undefined, { duration: 2000 }); }), - catchError(error => { return of( new PlanError({ @@ -168,16 +158,13 @@ export class DegreePlanEffects { @Effect() MakePlanPrimary$ = this.actions$.pipe( ofType<MakePlanPrimary>(PlanActionTypes.MakePlanPrimary), - withLatestFrom(this.store$.select(getDegreePlannerState)), filter(([_, state]) => state.visibleDegreePlan !== undefined), - // Get term data for the degree plan specified by the roadmap ID. flatMap(([_action, state]) => { const { roadmapId, name } = state.visibleDegreePlan as DegreePlan; return this.api.updatePlan(roadmapId, name, true); }), - // // Wrap data in an Action for dispatch map(response => { if (response === 1) { @@ -186,6 +173,19 @@ export class DegreePlanEffects { return new MakePlanPrimaryFailure(); } }), + tap(state => { + const message = 'This plan has been set as the primary plan'; + this.snackBar.open(message, undefined, { duration: 2000 }); + }), + catchError(error => { + return of( + new PlanError({ + message: 'Unable to make this plan primary', + duration: 2000, + error, + }), + ); + }), ); @Effect() @@ -206,7 +206,7 @@ export class DegreePlanEffects { return new ChangePlanNameSuccess({ roadmapId, newName }); }), tap(() => { - const message = `Plan name has been changed to ${newName}`; + const message = `Plan has been renamed to ${newName}`; this.snackBar.open(message, undefined, { duration: 2000 }); }), catchError(() => { @@ -221,9 +221,22 @@ export class DegreePlanEffects { ofType<CreatePlan>(PlanActionTypes.CreatePlan), flatMap(action => { const { name, primary } = action.payload; - return this.api - .createDegreePlan(name, primary) - .pipe(map(newPlan => new CreatePlanSuccess({ newPlan }))); + return this.api.createDegreePlan(name, primary).pipe( + map(newPlan => new CreatePlanSuccess({ newPlan })), + tap(() => { + const message = `New plan has been created`; + this.snackBar.open(message, undefined, { duration: 2000 }); + }), + catchError(error => { + return of( + new PlanError({ + message: 'Unable to create new plan', + duration: 2000, + error, + }), + ); + }), + ); }), ); @@ -232,9 +245,18 @@ export class DegreePlanEffects { ofType<DeletePlan>(PlanActionTypes.DeletePlan), flatMap(action => { const { roadmapId } = action.payload; - return this.api - .deleteDegreePlan(roadmapId) - .pipe(map(() => new DeletePlanSuccess({ roadmapId }))); + return this.api.deleteDegreePlan(roadmapId).pipe( + map(() => new DeletePlanSuccess({ roadmapId })), + catchError(error => { + return of( + new PlanError({ + message: 'Unable to delete plan', + duration: 2000, + error, + }), + ); + }), + ); }), );