1 import {Component, HostListener, OnDestroy, OnInit} from '@angular/core';
2 import {IdlObject} from '@eg/core/idl.service';
3 import {StaffCatalogService} from './catalog.service';
4 import {BasketService} from '@eg/share/catalog/basket.service';
5 import {Subject} from 'rxjs';
6 import {takeUntil} from 'rxjs/operators';
9 templateUrl: 'catalog.component.html'
11 export class CatalogComponent implements OnInit, OnDestroy {
13 private onDestroy = new Subject<null>();
16 private basket: BasketService,
17 private staffCat: StaffCatalogService
21 // Create the search context that will be used by all of my
22 // child components. After initial creation, the context is
23 // reset and updated as needed to apply new search parameters.
24 this.staffCat.createContext();
26 // listen for hold patron target changes from other tabs
27 // until there's a route change
28 this.staffCat.onChangeHoldPatron().pipe(
29 takeUntil(this.onDestroy)
32 // Subscribe to these emissions so that we can force
33 // change detection in this component even though the
34 // hold-for value was modified by a child component.
35 this.staffCat.holdForChange.subscribe(() => {});
38 // Returns the 'au' object for the patron who we are
39 // trying to place a hold for.
40 holdForUser(): IdlObject {
41 return this.staffCat.holdForUser;
45 this.staffCat.clearHoldPatron();
48 @HostListener('window:beforeunload')
49 onBeforeUnload(): void {
50 this.staffCat.onBeforeUnload();
54 this.clearHoldPatron();
55 this.onDestroy.next(null);