import { Component } from '@angular/core'; import { Store } from '@ngrx/store'; import { DegreePlannerState } from '@app/degree-planner/store/state'; import { MatDialog, MatSnackBar } from '@angular/material'; import { PromptDialogComponent } from '@app/shared/dialogs/prompt-dialog/prompt-dialog.component'; import { CreatePlan } from '@app/degree-planner/store/actions/plan.actions'; import { AddAcademicYearRequest } from '@app/degree-planner/store/actions/addAcademicYear.actions'; @Component({ selector: 'cse-header', templateUrl: './header.component.html', styleUrls: ['./header.component.scss'], }) export class HeaderComponent { constructor( private store: Store<DegreePlannerState>, private dialog: MatDialog, private snackBar: MatSnackBar, ) {} public printPlan() { window.print(); } public downloadPdf() { // FIXME and open in new window this.snackBar.open('Not supported yet'); } public addPlan() { this.dialog .open(PromptDialogComponent, { data: { title: 'Add degree plan', confirmText: 'Save', inputName: 'i.e. Psychology', }, }) .afterClosed() .subscribe((result: { confirmed: boolean; value: string }) => { const { confirmed, value } = result; if (confirmed) { const action = new CreatePlan({ name: value, primary: false }); this.store.dispatch(action); } }); } public addYear() { this.store.dispatch(new AddAcademicYearRequest()); this.snackBar.open('New academic year has been created'); } }