aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/follows/follows.component.ts
blob: 97422a41bbda5d02463fbd9df309384e3f6f7b97 (plain) (blame)
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
import { AfterViewInit, Component, ViewChild } from '@angular/core'
import { TabsetComponent } from 'ngx-bootstrap/tabs'

@Component({
  templateUrl: './follows.component.html',
  styleUrls: [ './follows.component.scss' ]
})
export class FollowsComponent implements AfterViewInit {
  @ViewChild('followsMenuTabs') followsMenuTabs: TabsetComponent

  links = [
    {
      path: 'following-list',
      title: 'Following'
    },
    {
      path: 'following-add',
      title: 'Follow'
    },
    {
      path: 'followers-list',
      title: 'Followers'
    }
  ]

  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].active = true
        return
      }
    }
  }
}