]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account.component.ts
Merge branch 'release/v1.0.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account.component.ts
CommitLineData
d7639f66 1import { Component, OnDestroy, OnInit } from '@angular/core'
5d08a6a7 2import { ServerService } from '@app/core'
4c8e4e04
C
3import { NavigationStart, Router } from '@angular/router'
4import { filter } from 'rxjs/operators'
5import { I18n } from '@ngx-translate/i18n-polyfill'
d7639f66 6import { Subscription } from 'rxjs'
4bb6886d
C
7
8@Component({
0626e7af 9 selector: 'my-my-account',
4c8e4e04
C
10 templateUrl: './my-account.component.html',
11 styleUrls: [ './my-account.component.scss' ]
4bb6886d 12})
d7639f66 13export class MyAccountComponent implements OnInit, OnDestroy {
4c8e4e04
C
14
15 libraryLabel = ''
5d08a6a7 16
d7639f66
C
17 private routeSub: Subscription
18
5d08a6a7 19 constructor (
4c8e4e04
C
20 private serverService: ServerService,
21 private router: Router,
22 private i18n: I18n
5d08a6a7
C
23 ) {}
24
4c8e4e04 25 ngOnInit () {
4c8e4e04
C
26 this.updateLibraryLabel(this.router.url)
27
d7639f66 28 this.routeSub = this.router.events
4c8e4e04
C
29 .pipe(filter(event => event instanceof NavigationStart))
30 .subscribe((event: NavigationStart) => this.updateLibraryLabel(event.url))
31 }
32
d7639f66
C
33 ngOnDestroy () {
34 if (this.routeSub) this.routeSub.unsubscribe()
35 }
36
5d08a6a7 37 isVideoImportEnabled () {
b0ee41df
C
38 const importConfig = this.serverService.getConfig().import.videos
39
40 return importConfig.http.enabled || importConfig.torrent.enabled
5d08a6a7 41 }
4c8e4e04
C
42
43 private updateLibraryLabel (url: string) {
44 const [ path ] = url.split('?')
45
75f1d362 46 if (path.startsWith('/my-account/video-channels')) {
4c8e4e04 47 this.libraryLabel = this.i18n('Channels')
75f1d362 48 } else if (path.startsWith('/my-account/videos')) {
4c8e4e04 49 this.libraryLabel = this.i18n('Videos')
75f1d362 50 } else if (path.startsWith('/my-account/subscriptions')) {
4c8e4e04 51 this.libraryLabel = this.i18n('Subscriptions')
75f1d362 52 } else if (path.startsWith('/my-account/video-imports')) {
4c8e4e04
C
53 this.libraryLabel = this.i18n('Video imports')
54 } else {
55 this.libraryLabel = ''
56 }
57 }
5d08a6a7 58}