2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-15 18:13:00 +00:00
RTL/src/app/cln/routing/routing.component.ts

41 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, ResolveEnd, Event } from '@angular/router';
import { Subject } from 'rxjs';
import { takeUntil, filter } from 'rxjs/operators';
import { faMapSigns } from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'rtl-cln-routing',
templateUrl: './routing.component.html',
styleUrls: ['./routing.component.scss']
})
export class CLNRoutingComponent implements OnInit, OnDestroy {
2021-08-28 21:03:18 +00:00
public faMapSigns = faMapSigns;
public links = [{ link: 'forwardinghistory', name: 'Forwarding History' }, { link: 'routingpeers', name: 'Routing Peers' }, { link: 'failedtransactions', name: 'Failed Transactions' }, { link: 'localfail', name: 'Local Failed Transactions' }];
public activeLink = this.links[0].link;
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject()];
constructor(private router: Router) { }
ngOnInit() {
2021-08-28 21:03:18 +00:00
const linkFound = this.links.find((link) => this.router.url.includes(link.link));
this.activeLink = linkFound ? linkFound.link : this.links[0].link;
2021-08-28 21:03:18 +00:00
this.router.events.pipe(takeUntil(this.unSubs[0]), filter((e) => e instanceof ResolveEnd)).
subscribe({
next: (value: ResolveEnd | Event) => {
const linkFound = this.links.find((link) => (<ResolveEnd>value).urlAfterRedirects.includes(link.link));
this.activeLink = linkFound ? linkFound.link : this.links[0].link;
}
2021-08-28 21:03:18 +00:00
});
}
ngOnDestroy() {
2021-08-28 21:03:18 +00:00
this.unSubs.forEach((completeSub) => {
completeSub.next(<any>null);
completeSub.complete();
});
}
}