2017-11-28 17:11:07 +01:00
|
|
|
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'
|
|
|
|
import { NavigationEnd, Router } from '@angular/router'
|
2018-06-05 16:31:52 +02:00
|
|
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
2018-08-09 14:55:06 +02:00
|
|
|
import { NgbTabset } from '@ng-bootstrap/ng-bootstrap'
|
2017-11-15 10:10:41 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: './follows.component.html',
|
|
|
|
styleUrls: [ './follows.component.scss' ]
|
|
|
|
})
|
2017-11-28 17:11:07 +01:00
|
|
|
export class FollowsComponent implements OnInit, AfterViewInit {
|
2018-08-09 14:55:06 +02:00
|
|
|
@ViewChild('followsMenuTabs') followsMenuTabs: NgbTabset
|
2017-11-15 10:10:41 +01:00
|
|
|
|
2018-06-05 16:31:52 +02:00
|
|
|
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')
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2017-11-28 17:11:07 +01:00
|
|
|
|
|
|
|
ngOnInit () {
|
|
|
|
this.router.events.subscribe(
|
|
|
|
event => {
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
this.updateActiveTab()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-11-15 10:10:41 +01:00
|
|
|
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
|
|
|
|
|
2018-08-09 14:55:06 +02:00
|
|
|
if (url.endsWith(path) === true) {
|
|
|
|
this.followsMenuTabs.select(path)
|
2017-11-15 10:10:41 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|