1
0
Files
yel-dspace-angular/src/app/header/context-help-toggle/context-help-toggle.component.ts

43 lines
1.3 KiB
TypeScript

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ContextHelpService } from '../../shared/context-help.service';
import { Observable, Subscription, BehaviorSubject } from 'rxjs';
import { combineLatest } from 'rxjs';
/**
* Renders a "context help toggle" button that toggles the visibility of tooltip buttons on the page.
* If there are no tooltip buttons available on the current page, the toggle is unclickable.
*/
@Component({
selector: 'ds-context-help-toggle',
templateUrl: './context-help-toggle.component.html',
styleUrls: ['./context-help-toggle.component.scss']
})
export class ContextHelpToggleComponent implements OnInit, OnDestroy {
buttonDisabled$: Observable<boolean>;
constructor(
private contextHelpService: ContextHelpService,
) { }
private clickEvents: BehaviorSubject<null> = new BehaviorSubject(null);
private subs: Subscription[];
ngOnInit(): void {
this.buttonDisabled$ = this.contextHelpService.contextHelpEmpty$();
this.subs = [
this.buttonDisabled$.subscribe(),
combineLatest([this.clickEvents, this.buttonDisabled$])
.subscribe(([_, disabled]) =>
disabled ? null : this.contextHelpService.toggleIcons())
];
}
ngOnDestroy() {
this.subs.forEach(sub => sub.unsubscribe());
}
onClick() {
this.clickEvents.next(null);
}
}