Merge branch 'master' into develop
[oweals/peertube.git] / client / src / app / +my-account / my-account.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ServerService } from '@app/core'
3 import { NavigationStart, Router } from '@angular/router'
4 import { filter } from 'rxjs/operators'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { Subscription } from 'rxjs'
7
8 @Component({
9   selector: 'my-my-account',
10   templateUrl: './my-account.component.html',
11   styleUrls: [ './my-account.component.scss' ]
12 })
13 export class MyAccountComponent implements OnInit, OnDestroy {
14
15   libraryLabel = ''
16   miscLabel = ''
17
18   private routeSub: Subscription
19
20   constructor (
21     private serverService: ServerService,
22     private router: Router,
23     private i18n: I18n
24   ) {}
25
26   ngOnInit () {
27     this.updateLabels(this.router.url)
28
29     this.routeSub = this.router.events
30         .pipe(filter(event => event instanceof NavigationStart))
31         .subscribe((event: NavigationStart) => this.updateLabels(event.url))
32   }
33
34   ngOnDestroy () {
35     if (this.routeSub) this.routeSub.unsubscribe()
36   }
37
38   isVideoImportEnabled () {
39     const importConfig = this.serverService.getConfig().import.videos
40
41     return importConfig.http.enabled || importConfig.torrent.enabled
42   }
43
44   private updateLabels (url: string) {
45     const [ path ] = url.split('?')
46
47     if (path.startsWith('/my-account/video-channels')) {
48       this.libraryLabel = this.i18n('Channels')
49     } else if (path.startsWith('/my-account/videos')) {
50       this.libraryLabel = this.i18n('Videos')
51     } else if (path.startsWith('/my-account/subscriptions')) {
52       this.libraryLabel = this.i18n('Subscriptions')
53     } else if (path.startsWith('/my-account/video-imports')) {
54       this.libraryLabel = this.i18n('Video imports')
55     } else {
56       this.libraryLabel = ''
57     }
58
59     if (path.startsWith('/my-account/blocklist/accounts')) {
60       this.miscLabel = this.i18n('Muted accounts')
61     } else if (path.startsWith('/my-account/blocklist/servers')) {
62       this.miscLabel = this.i18n('Muted instances')
63     } else {
64       this.miscLabel = ''
65     }
66   }
67 }