1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'
import { NavigationEnd, Router } from '@angular/router'
import { TabsetComponent } from 'ngx-bootstrap/tabs'
import { I18n } from '@ngx-translate/i18n-polyfill'
@Component({
templateUrl: './follows.component.html',
styleUrls: [ './follows.component.scss' ]
})
export class FollowsComponent implements OnInit, AfterViewInit {
@ViewChild('followsMenuTabs') followsMenuTabs: TabsetComponent
links: { path: string, title: string }[] = []
constructor (
private i18n: I18n,
private router: Router
) {
this.links = [
{
path: 'following-list',
title: this.i18n('Following')
},
{
path: 'following-add',
title: this.i18n('Follow')
},
{
path: 'followers-list',
title: this.i18n('Followers')
}
]
}
ngOnInit () {
this.router.events.subscribe(
event => {
if (event instanceof NavigationEnd) {
this.updateActiveTab()
}
}
)
}
ngAfterViewInit () {
// Avoid issue with change detector
setTimeout(() => this.updateActiveTab())
}
private updateActiveTab () {
const url = window.location.pathname
for (let i = 0; i < this.links.length; i++) {
const path = this.links[i].path
if (url.endsWith(path) === true && this.followsMenuTabs.tabs[i]) {
this.followsMenuTabs.tabs[i].active = true
return
}
}
}
}
|