]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' |
2 | import { Subscription } from 'rxjs' | |
3 | import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators' | |
20d21199 | 4 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
170726f5 | 5 | import { ActivatedRoute } from '@angular/router' |
67ed6552 C |
6 | import { AuthService, Notifier, RestExtractor, ScreenService } from '@app/core' |
7 | import { ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main' | |
8 | import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' | |
e33f888b | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
170726f5 C |
10 | |
11 | @Component({ | |
12 | templateUrl: './video-channels.component.html', | |
13 | styleUrls: [ './video-channels.component.scss' ] | |
14 | }) | |
734a5ceb | 15 | export class VideoChannelsComponent implements OnInit, OnDestroy { |
2f5d2ec5 | 16 | @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent |
20d21199 | 17 | |
170726f5 | 18 | videoChannel: VideoChannel |
20d21199 | 19 | hotkeys: Hotkey[] |
24e7916c | 20 | links: ListOverflowItem[] = [] |
fef213ca | 21 | isChannelManageable = false |
170726f5 | 22 | |
734a5ceb C |
23 | private routeSub: Subscription |
24 | ||
170726f5 | 25 | constructor ( |
e33f888b | 26 | private i18n: I18n, |
170726f5 | 27 | private route: ActivatedRoute, |
a0dedc02 | 28 | private notifier: Notifier, |
2d3741d6 | 29 | private authService: AuthService, |
a51bad1a | 30 | private videoChannelService: VideoChannelService, |
20d21199 | 31 | private restExtractor: RestExtractor, |
937b7a6a | 32 | private hotkeysService: HotkeysService, |
edb86865 | 33 | private screenService: ScreenService |
734a5ceb | 34 | ) { } |
170726f5 C |
35 | |
36 | ngOnInit () { | |
734a5ceb C |
37 | this.routeSub = this.route.params |
38 | .pipe( | |
2f1548fd | 39 | map(params => params[ 'videoChannelName' ]), |
734a5ceb | 40 | distinctUntilChanged(), |
2f1548fd | 41 | switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)), |
734a5ceb C |
42 | catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) |
43 | ) | |
fef213ca C |
44 | .subscribe(videoChannel => { |
45 | this.videoChannel = videoChannel | |
46 | ||
47 | if (this.authService.isLoggedIn()) { | |
48 | this.authService.userInformationLoaded | |
49 | .subscribe(() => { | |
50 | const channelUserId = this.videoChannel.ownerAccount.userId | |
51 | this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id | |
52 | }) | |
53 | } | |
54 | }) | |
734a5ceb | 55 | |
20d21199 RK |
56 | this.hotkeys = [ |
57 | new Hotkey('S', (event: KeyboardEvent): boolean => { | |
58 | this.subscribeButton.subscribed ? | |
59 | this.subscribeButton.unsubscribe() : | |
60 | this.subscribeButton.subscribe() | |
61 | return false | |
e33f888b | 62 | }, undefined, this.i18n('Subscribe to the account')) |
20d21199 RK |
63 | ] |
64 | if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys) | |
24e7916c RK |
65 | |
66 | this.links = [ | |
14571f19 RK |
67 | { label: this.i18n('VIDEOS'), routerLink: 'videos' }, |
68 | { label: this.i18n('VIDEO PLAYLISTS'), routerLink: 'video-playlists' }, | |
69 | { label: this.i18n('ABOUT'), routerLink: 'about' } | |
24e7916c | 70 | ] |
734a5ceb | 71 | } |
170726f5 | 72 | |
734a5ceb C |
73 | ngOnDestroy () { |
74 | if (this.routeSub) this.routeSub.unsubscribe() | |
20d21199 RK |
75 | |
76 | // Unbind hotkeys | |
77 | if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys) | |
170726f5 | 78 | } |
2d3741d6 | 79 | |
937b7a6a RK |
80 | get isInSmallView () { |
81 | return this.screenService.isInSmallView() | |
82 | } | |
83 | ||
2d3741d6 C |
84 | isUserLoggedIn () { |
85 | return this.authService.isLoggedIn() | |
86 | } | |
a0dedc02 | 87 | |
aa0f1963 RK |
88 | get isManageable () { |
89 | if (!this.isUserLoggedIn()) return false | |
90 | return this.videoChannel.ownerAccount.userId === this.authService.getUser().id | |
91 | } | |
92 | ||
a0dedc02 RK |
93 | activateCopiedMessage () { |
94 | this.notifier.success(this.i18n('Username copied')) | |
95 | } | |
170726f5 | 96 | } |