aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/user-subscription
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-23 17:58:39 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitf37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch)
tree2050443febcdb2a3eec68b7bbf9687e26dcb24dc /client/src/app/shared/user-subscription
parent240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff)
downloadPeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.gz
PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.zst
PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.zip
Add ability to search video channels
Diffstat (limited to 'client/src/app/shared/user-subscription')
-rw-r--r--client/src/app/shared/user-subscription/subscribe-button.component.html4
-rw-r--r--client/src/app/shared/user-subscription/subscribe-button.component.scss16
-rw-r--r--client/src/app/shared/user-subscription/subscribe-button.component.ts3
-rw-r--r--client/src/app/shared/user-subscription/user-subscription.service.ts47
4 files changed, 51 insertions, 19 deletions
diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.html b/client/src/app/shared/user-subscription/subscribe-button.component.html
index 63b313662..34c024c17 100644
--- a/client/src/app/shared/user-subscription/subscribe-button.component.html
+++ b/client/src/app/shared/user-subscription/subscribe-button.component.html
@@ -1,11 +1,11 @@
1<span i18n *ngIf="subscribed === false" class="subscribe-button" role="button" (click)="subscribe()"> 1<span i18n *ngIf="subscribed === false" class="subscribe-button" [ngClass]="size" role="button" (click)="subscribe()">
2 <span>Subscribe</span> 2 <span>Subscribe</span>
3 <span *ngIf="displayFollowers && videoChannel.followersCount !== 0" class="followers-count"> 3 <span *ngIf="displayFollowers && videoChannel.followersCount !== 0" class="followers-count">
4 {{ videoChannel.followersCount | myNumberFormatter }} 4 {{ videoChannel.followersCount | myNumberFormatter }}
5 </span> 5 </span>
6</span> 6</span>
7 7
8<span *ngIf="subscribed === true" class="unsubscribe-button" role="button" (click)="unsubscribe()"> 8<span *ngIf="subscribed === true" class="unsubscribe-button" [ngClass]="size" role="button" (click)="unsubscribe()">
9 <span class="subscribed" i18n>Subscribed</span> 9 <span class="subscribed" i18n>Subscribed</span>
10 <span class="unsubscribe" i18n>Unsubscribe</span> 10 <span class="unsubscribe" i18n>Unsubscribe</span>
11 11
diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.scss b/client/src/app/shared/user-subscription/subscribe-button.component.scss
index 9811fdc0c..b78d2f59c 100644
--- a/client/src/app/shared/user-subscription/subscribe-button.component.scss
+++ b/client/src/app/shared/user-subscription/subscribe-button.component.scss
@@ -13,7 +13,21 @@
13 13
14.subscribe-button, 14.subscribe-button,
15.unsubscribe-button { 15.unsubscribe-button {
16 padding: 3px 7px; 16 display: inline-block;
17
18 &.small {
19 min-width: 75px;
20 height: 20px;
21 line-height: 20px;
22 font-size: 13px;
23 }
24
25 &.normal {
26 min-width: 120px;
27 height: 30px;
28 line-height: 30px;
29 font-size: 16px;
30 }
17} 31}
18 32
19.unsubscribe-button { 33.unsubscribe-button {
diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.ts b/client/src/app/shared/user-subscription/subscribe-button.component.ts
index 46d6dbaf7..ba7acf69a 100644
--- a/client/src/app/shared/user-subscription/subscribe-button.component.ts
+++ b/client/src/app/shared/user-subscription/subscribe-button.component.ts
@@ -15,6 +15,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
15export class SubscribeButtonComponent implements OnInit { 15export class SubscribeButtonComponent implements OnInit {
16 @Input() videoChannel: VideoChannel 16 @Input() videoChannel: VideoChannel
17 @Input() displayFollowers = false 17 @Input() displayFollowers = false
18 @Input() size: 'small' | 'normal' = 'normal'
18 19
19 subscribed: boolean 20 subscribed: boolean
20 21
@@ -34,7 +35,7 @@ export class SubscribeButtonComponent implements OnInit {
34 ngOnInit () { 35 ngOnInit () {
35 this.userSubscriptionService.isSubscriptionExists(this.uri) 36 this.userSubscriptionService.isSubscriptionExists(this.uri)
36 .subscribe( 37 .subscribe(
37 exists => this.subscribed = exists, 38 res => this.subscribed = res[this.uri],
38 39
39 err => this.notificationsService.error(this.i18n('Error'), err.message) 40 err => this.notificationsService.error(this.i18n('Error'), err.message)
40 ) 41 )
diff --git a/client/src/app/shared/user-subscription/user-subscription.service.ts b/client/src/app/shared/user-subscription/user-subscription.service.ts
index 3103706d1..cf622019f 100644
--- a/client/src/app/shared/user-subscription/user-subscription.service.ts
+++ b/client/src/app/shared/user-subscription/user-subscription.service.ts
@@ -1,22 +1,36 @@
1import { catchError, map } from 'rxjs/operators' 1import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http' 2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { ResultList } from '../../../../../shared' 4import { ResultList } from '../../../../../shared'
5import { environment } from '../../../environments/environment' 5import { environment } from '../../../environments/environment'
6import { RestExtractor } from '../rest' 6import { RestExtractor, RestService } from '../rest'
7import { Observable, of } from 'rxjs' 7import { Observable, ReplaySubject, Subject } from 'rxjs'
8import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' 9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
10import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' 10import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
11 11
12type SubscriptionExistResult = { [ uri: string ]: boolean }
13
12@Injectable() 14@Injectable()
13export class UserSubscriptionService { 15export class UserSubscriptionService {
14 static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/users/me/subscriptions' 16 static BASE_USER_SUBSCRIPTIONS_URL = environment.apiUrl + '/api/v1/users/me/subscriptions'
15 17
18 // Use a replay subject because we "next" a value before subscribing
19 private existsSubject: Subject<string> = new ReplaySubject(1)
20 private existsObservable: Observable<SubscriptionExistResult>
21
16 constructor ( 22 constructor (
17 private authHttp: HttpClient, 23 private authHttp: HttpClient,
18 private restExtractor: RestExtractor 24 private restExtractor: RestExtractor,
25 private restService: RestService
19 ) { 26 ) {
27 this.existsObservable = this.existsSubject.pipe(
28 tap(u => console.log(u)),
29 bufferTime(500),
30 filter(uris => uris.length !== 0),
31 switchMap(uris => this.areSubscriptionExist(uris)),
32 share()
33 )
20 } 34 }
21 35
22 deleteSubscription (nameWithHost: string) { 36 deleteSubscription (nameWithHost: string) {
@@ -50,17 +64,20 @@ export class UserSubscriptionService {
50 ) 64 )
51 } 65 }
52 66
53 isSubscriptionExists (nameWithHost: string): Observable<boolean> { 67 isSubscriptionExists (nameWithHost: string) {
54 const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/' + nameWithHost 68 this.existsSubject.next(nameWithHost)
55 69
56 return this.authHttp.get(url) 70 return this.existsObservable
57 .pipe( 71 }
58 map(this.restExtractor.extractDataBool),
59 catchError(err => {
60 if (err.status === 404) return of(false)
61 72
62 return this.restExtractor.handleError(err) 73 private areSubscriptionExist (uris: string[]): Observable<SubscriptionExistResult> {
63 }) 74 console.log(uris)
64 ) 75 const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/exist'
76 let params = new HttpParams()
77
78 params = this.restService.addObjectParams(params, { uris })
79
80 return this.authHttp.get<SubscriptionExistResult>(url, { params })
81 .pipe(catchError(err => this.restExtractor.handleError(err)))
65 } 82 }
66} 83}