1 import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'
2 import { NavigationEnd, Router } from '@angular/router'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { NgbTabset } from '@ng-bootstrap/ng-bootstrap'
7 templateUrl: './follows.component.html',
8 styleUrls: [ './follows.component.scss' ]
10 export class FollowsComponent implements OnInit, AfterViewInit {
11 @ViewChild('followsMenuTabs') followsMenuTabs: NgbTabset
13 links: { path: string, title: string }[] = []
17 private router: Router
21 path: 'following-list',
22 title: this.i18n('Following')
25 path: 'following-add',
26 title: this.i18n('Follow')
29 path: 'followers-list',
30 title: this.i18n('Followers')
36 this.router.events.subscribe(
38 if (event instanceof NavigationEnd) {
39 this.updateActiveTab()
46 // Avoid issue with change detector
47 setTimeout(() => this.updateActiveTab())
50 private updateActiveTab () {
51 const url = window.location.pathname
53 for (let i = 0; i < this.links.length; i++) {
54 const path = this.links[i].path
56 if (url.endsWith(path) === true) {
57 this.followsMenuTabs.select(path)