diff --git a/src/app/degree-planner/store/actions/note.actions.ts b/src/app/degree-planner/store/actions/note.actions.ts index 7e80e4a52f3996c2fefda0a3125c2197dabac46c..48a4db8114d5aab8dda26873e4269ef9371aff02 100644 --- a/src/app/degree-planner/store/actions/note.actions.ts +++ b/src/app/degree-planner/store/actions/note.actions.ts @@ -33,5 +33,5 @@ export class DeleteNoteSuccess implements Action { export class NoteError implements Action { public readonly type = NoteActionTypes.NoteError; - constructor(public payload: { message: string; error: any }) {} + constructor(public payload: { message: string; duration: number; error: any }) {} } diff --git a/src/app/degree-planner/store/actions/plan.actions.ts b/src/app/degree-planner/store/actions/plan.actions.ts index 25548f97e3119f46ca81b1a7a00f5473831b394f..7f3662489808b46b0038090f88387a9a428b786b 100644 --- a/src/app/degree-planner/store/actions/plan.actions.ts +++ b/src/app/degree-planner/store/actions/plan.actions.ts @@ -68,7 +68,7 @@ export class DeletePlanSuccess implements Action { export class PlanError implements Action { public readonly type = PlanActionTypes.PlanError; - constructor(public payload: { message: string; error: any }) {} + constructor(public payload: { message: string; duration: number; error: any }) {} } export class MakePlanPrimary implements Action { diff --git a/src/app/degree-planner/store/effects/course.effects.ts b/src/app/degree-planner/store/effects/course.effects.ts index b6c0843cc8c880418a9801b5ad9f90c2c136c385..12cb2a584e48571e55e9a1b05cb103b95fe6a386 100644 --- a/src/app/degree-planner/store/effects/course.effects.ts +++ b/src/app/degree-planner/store/effects/course.effects.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { of } from 'rxjs'; import { + tap, map, flatMap, withLatestFrom, @@ -11,6 +12,7 @@ import { } from 'rxjs/operators'; import { GlobalState } from '@app/core/state'; import { Store } from '@ngrx/store'; +import { MatSnackBar } from '@angular/material'; // Services import { DegreePlannerApiService } from '@app/degree-planner/services/api.service'; @@ -36,12 +38,16 @@ import { import { DegreePlan } from '@app/core/models/degree-plan'; import { Course, CourseBase } from '@app/core/models/course'; +// Pipes +import { GetTermDescriptionPipe } from '@app/shared/pipes/get-term-description.pipe'; + @Injectable() export class CourseEffects { constructor( private actions$: Actions, private api: DegreePlannerApiService, private store$: Store<GlobalState>, + private snackBar: MatSnackBar ) {} @Effect() @@ -63,10 +69,16 @@ export class CourseEffects { map(action => new MoveCourseBetweenTermsSuccess(action.payload)), + tap((state) => { + const touchedTerm = new GetTermDescriptionPipe().transform(state.payload.to); + const message = `Course has been moved to ${touchedTerm}`; + this.snackBar.open(message, undefined, {duration: 2000}); + }), + catchError(error => { return of( new CourseError({ - message: 'Error moving course', + message: 'Unable to move course', error, }), ); @@ -107,10 +119,17 @@ export class CourseEffects { return toSuccessAction$; }), + tap((state) => { + const touchedCourse: any = state.payload.course; + const touchedTerm: any = new GetTermDescriptionPipe().transform(touchedCourse.termCode); + const message = `${touchedCourse.subject} ${touchedCourse.catalogNumber} has been added to ${touchedTerm}`; + this.snackBar.open(message, undefined, {duration: 2000}); + }), + catchError(error => { return of( new CourseError({ - message: 'Error adding course', + message: 'Unable to add course', error, }), ); @@ -130,7 +149,6 @@ export class CourseEffects { const recordId = action.payload.recordId; const removeCourse$ = this.api.removeCourse(roadmapId, recordId); - const toSuccessAction$ = removeCourse$.pipe( map(() => new RemoveCourseSuccess({ recordId })), ); @@ -141,7 +159,7 @@ export class CourseEffects { catchError(error => { return of( new CourseError({ - message: 'Error removing course', + message: 'Unable to remove course', error, }), ); @@ -164,7 +182,7 @@ export class CourseEffects { catchError(error => { return of( new CourseError({ - message: 'Error removing saved-for-later course', + message: 'Unable to remove saved course', error, }), ); @@ -184,10 +202,15 @@ export class CourseEffects { map(action => new AddSaveForLaterSuccess(action.payload)), + tap(() => { + const message = 'Course has been saved for later'; + this.snackBar.open(message, undefined, {duration: 2000}); + }), + catchError(error => { return of( new CourseError({ - message: 'Error saving course for later', + message: 'Unable to save course for later', error, }), ); diff --git a/src/app/degree-planner/store/effects/note.effects.ts b/src/app/degree-planner/store/effects/note.effects.ts index a761fe6556b8bca014fd02c97ee8416db8b6d5f4..177f3073695691c3f6db6a11d2d67ac70849a778 100644 --- a/src/app/degree-planner/store/effects/note.effects.ts +++ b/src/app/degree-planner/store/effects/note.effects.ts @@ -6,10 +6,12 @@ import { Observable, of } from 'rxjs'; import { mergeMap, withLatestFrom, + tap, map, filter, catchError, } from 'rxjs/operators'; +import { MatSnackBar } from '@angular/material'; // Models import { Note } from '@app/core/models/note'; @@ -37,6 +39,7 @@ export class NoteEffects { private actions$: Actions, private store$: Store<GlobalState>, private api: DegreePlannerApiService, + private snackBar: MatSnackBar ) {} @Effect() @@ -72,10 +75,15 @@ export class NoteEffects { // object can be updated with the new Note data. map(updatedNote => new WriteNoteSuccess({ updatedNote })), + tap(() => { + const message = 'Note has been saved'; + this.snackBar.open(message, undefined, {duration: 2000}); + }), + catchError(error => { return of( new NoteError({ - message: 'Error writing note', + message: 'Unable to save note', duration: 2000, error, }), ); @@ -113,10 +121,16 @@ export class NoteEffects { // State object can be updated with the note removed. map(termCode => new DeleteNoteSuccess({ termCode })), + tap(() => { + const message = 'Note has been deleted'; + this.snackBar.open(message, undefined, {duration: 2000}); + }), + catchError(error => { return of( new NoteError({ - message: 'Error deleting note', + message: 'Unable to remove note', + duration: 2000, error, }), ); diff --git a/src/app/degree-planner/store/effects/plan.effects.ts b/src/app/degree-planner/store/effects/plan.effects.ts index ca23f5367e9ebac342b890150b83f4bf208f6e88..26eb7f37e95dbeefb0ff2100b7b863177adcd99f 100644 --- a/src/app/degree-planner/store/effects/plan.effects.ts +++ b/src/app/degree-planner/store/effects/plan.effects.ts @@ -1,9 +1,9 @@ -import { tap } from 'rxjs/operators'; // Libraries import { Injectable } from '@angular/core'; import { ROOT_EFFECTS_INIT, Actions, Effect, ofType } from '@ngrx/effects'; import { Observable, forkJoin, of } from 'rxjs'; import { + tap, map, flatMap, withLatestFrom, @@ -12,6 +12,7 @@ import { } from 'rxjs/operators'; import { GlobalState } from '@app/core/state'; import { Store, Action } from '@ngrx/store'; +import { MatSnackBar } from '@angular/material'; // Services import { DegreePlannerApiService } from '@app/degree-planner/services/api.service'; @@ -49,6 +50,7 @@ export class DegreePlanEffects { private actions$: Actions, private api: DegreePlannerApiService, private store$: Store<GlobalState>, + private snackBar: MatSnackBar ) {} @Effect() @@ -104,7 +106,7 @@ export class DegreePlanEffects { map(payload => new InitialLoadSuccess(payload)), catchError(error => { - return of(new PlanError({ message: '', error })); + return of(new PlanError({ message: 'Something went wrong', duration: 2000, error })); }), ); @@ -134,8 +136,14 @@ export class DegreePlanEffects { 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({ message: '', error })); + return of(new PlanError({ message: 'Unable to switch plan', duration: 2000, error })); }), );