Skip to content
Snippets Groups Projects
Commit a50e4f2f authored by Paulina Nogal's avatar Paulina Nogal
Browse files

User action messaging

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