]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account.component.ts
Add user/instance block by users in the client
[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 = ''
af5767ff 16 miscLabel = ''
5d08a6a7 17
d7639f66
C
18 private routeSub: Subscription
19
5d08a6a7 20 constructor (
4c8e4e04
C
21 private serverService: ServerService,
22 private router: Router,
23 private i18n: I18n
5d08a6a7
C
24 ) {}
25
4c8e4e04 26 ngOnInit () {
af5767ff 27 this.updateLabels(this.router.url)
4c8e4e04 28
d7639f66 29 this.routeSub = this.router.events
4c8e4e04 30 .pipe(filter(event => event instanceof NavigationStart))
af5767ff 31 .subscribe((event: NavigationStart) => this.updateLabels(event.url))
4c8e4e04
C
32 }
33
d7639f66
C
34 ngOnDestroy () {
35 if (this.routeSub) this.routeSub.unsubscribe()
36 }
37
5d08a6a7 38 isVideoImportEnabled () {
b0ee41df
C
39 const importConfig = this.serverService.getConfig().import.videos
40
41 return importConfig.http.enabled || importConfig.torrent.enabled
5d08a6a7 42 }
4c8e4e04 43
af5767ff 44 private updateLabels (url: string) {
4c8e4e04
C
45 const [ path ] = url.split('?')
46
75f1d362 47 if (path.startsWith('/my-account/video-channels')) {
4c8e4e04 48 this.libraryLabel = this.i18n('Channels')
75f1d362 49 } else if (path.startsWith('/my-account/videos')) {
4c8e4e04 50 this.libraryLabel = this.i18n('Videos')
75f1d362 51 } else if (path.startsWith('/my-account/subscriptions')) {
4c8e4e04 52 this.libraryLabel = this.i18n('Subscriptions')
75f1d362 53 } else if (path.startsWith('/my-account/video-imports')) {
4c8e4e04
C
54 this.libraryLabel = this.i18n('Video imports')
55 } else {
56 this.libraryLabel = ''
57 }
af5767ff
C
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 }
4c8e4e04 66 }
5d08a6a7 67}