]>
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' | |
f2eb23cd | 9 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
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 C |
25 | constructor ( |
26 | private route: ActivatedRoute, | |
a0dedc02 | 27 | private notifier: Notifier, |
2d3741d6 | 28 | private authService: AuthService, |
a51bad1a | 29 | private videoChannelService: VideoChannelService, |
20d21199 | 30 | private restExtractor: RestExtractor, |
937b7a6a | 31 | private hotkeysService: HotkeysService, |
edb86865 | 32 | private screenService: ScreenService |
734a5ceb | 33 | ) { } |
170726f5 C |
34 | |
35 | ngOnInit () { | |
734a5ceb C |
36 | this.routeSub = this.route.params |
37 | .pipe( | |
2f1548fd | 38 | map(params => params[ 'videoChannelName' ]), |
734a5ceb | 39 | distinctUntilChanged(), |
2f1548fd | 40 | switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)), |
ab398a05 | 41 | catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [ |
f2eb23cd RK |
42 | HttpStatusCode.BAD_REQUEST_400, |
43 | HttpStatusCode.NOT_FOUND_404 | |
44 | ])) | |
734a5ceb | 45 | ) |
fef213ca C |
46 | .subscribe(videoChannel => { |
47 | this.videoChannel = videoChannel | |
48 | ||
49 | if (this.authService.isLoggedIn()) { | |
50 | this.authService.userInformationLoaded | |
51 | .subscribe(() => { | |
52 | const channelUserId = this.videoChannel.ownerAccount.userId | |
53 | this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id | |
54 | }) | |
55 | } | |
56 | }) | |
734a5ceb | 57 | |
20d21199 RK |
58 | this.hotkeys = [ |
59 | new Hotkey('S', (event: KeyboardEvent): boolean => { | |
60 | this.subscribeButton.subscribed ? | |
61 | this.subscribeButton.unsubscribe() : | |
62 | this.subscribeButton.subscribe() | |
63 | return false | |
66357162 | 64 | }, undefined, $localize`Subscribe to the account`) |
20d21199 RK |
65 | ] |
66 | if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys) | |
24e7916c RK |
67 | |
68 | this.links = [ | |
66357162 C |
69 | { label: $localize`VIDEOS`, routerLink: 'videos' }, |
70 | { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' }, | |
71 | { label: $localize`ABOUT`, routerLink: 'about' } | |
24e7916c | 72 | ] |
734a5ceb | 73 | } |
170726f5 | 74 | |
734a5ceb C |
75 | ngOnDestroy () { |
76 | if (this.routeSub) this.routeSub.unsubscribe() | |
20d21199 RK |
77 | |
78 | // Unbind hotkeys | |
79 | if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys) | |
170726f5 | 80 | } |
2d3741d6 | 81 | |
937b7a6a RK |
82 | get isInSmallView () { |
83 | return this.screenService.isInSmallView() | |
84 | } | |
85 | ||
2d3741d6 C |
86 | isUserLoggedIn () { |
87 | return this.authService.isLoggedIn() | |
88 | } | |
a0dedc02 | 89 | |
aa0f1963 RK |
90 | get isManageable () { |
91 | if (!this.isUserLoggedIn()) return false | |
92 | return this.videoChannel.ownerAccount.userId === this.authService.getUser().id | |
93 | } | |
94 | ||
a0dedc02 | 95 | activateCopiedMessage () { |
66357162 | 96 | this.notifier.success($localize`Username copied`) |
a0dedc02 | 97 | } |
170726f5 | 98 | } |