diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-23 17:58:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch) | |
tree | 2050443febcdb2a3eec68b7bbf9687e26dcb24dc /client/src/app | |
parent | 240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff) | |
download | PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.gz PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.zst PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.zip |
Add ability to search video channels
Diffstat (limited to 'client/src/app')
14 files changed, 171 insertions, 58 deletions
diff --git a/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.scss b/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.scss index 2fbfa335b..8cb0b677d 100644 --- a/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.scss +++ b/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.scss | |||
@@ -37,13 +37,6 @@ | |||
37 | .actor-owner { | 37 | .actor-owner { |
38 | @include actor-owner; | 38 | @include actor-owner; |
39 | } | 39 | } |
40 | |||
41 | my-subscribe-button { | ||
42 | /deep/ span[role=button] { | ||
43 | padding: 7px 12px; | ||
44 | font-size: 16px; | ||
45 | } | ||
46 | } | ||
47 | } | 40 | } |
48 | 41 | ||
49 | 42 | ||
diff --git a/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts b/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts index 1e94cf90b..9434b196f 100644 --- a/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts +++ b/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts | |||
@@ -21,7 +21,7 @@ export class MyAccountSubscriptionsComponent implements OnInit { | |||
21 | ngOnInit () { | 21 | ngOnInit () { |
22 | this.userSubscriptionService.listSubscriptions() | 22 | this.userSubscriptionService.listSubscriptions() |
23 | .subscribe( | 23 | .subscribe( |
24 | res => { console.log(res); this.videoChannels = res.data }, | 24 | res => this.videoChannels = res.data, |
25 | 25 | ||
26 | error => this.notificationsService.error(this.i18n('Error'), error.message) | 26 | error => this.notificationsService.error(this.i18n('Error'), error.message) |
27 | ) | 27 | ) |
diff --git a/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.scss b/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.scss index 5c892be01..83d657f03 100644 --- a/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.scss +++ b/client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.scss | |||
@@ -41,6 +41,10 @@ | |||
41 | color: $grey-actor-name; | 41 | color: $grey-actor-name; |
42 | margin-left: 5px; | 42 | margin-left: 5px; |
43 | } | 43 | } |
44 | |||
45 | .video-channel-followers { | ||
46 | |||
47 | } | ||
44 | } | 48 | } |
45 | } | 49 | } |
46 | 50 | ||
diff --git a/client/src/app/search/search.component.html b/client/src/app/search/search.component.html index bbc70f772..128cc52f5 100644 --- a/client/src/app/search/search.component.html +++ b/client/src/app/search/search.component.html | |||
@@ -22,10 +22,27 @@ | |||
22 | </div> | 22 | </div> |
23 | </div> | 23 | </div> |
24 | 24 | ||
25 | <div i18n *ngIf="pagination.totalItems === 0" class="no-result"> | 25 | <div i18n *ngIf="pagination.totalItems === 0 && videoChannels.length === 0" class="no-result"> |
26 | No results found | 26 | No results found |
27 | </div> | 27 | </div> |
28 | 28 | ||
29 | <div *ngFor="let videoChannel of videoChannels" class="entry video-channel"> | ||
30 | <a [routerLink]="[ '/video-channels', videoChannel.name ]"> | ||
31 | <img [src]="videoChannel.avatarUrl" alt="Avatar" /> | ||
32 | </a> | ||
33 | |||
34 | <div class="video-channel-info"> | ||
35 | <a [routerLink]="[ '/video-channels', videoChannel.name ]" class="video-channel-names"> | ||
36 | <div class="video-channel-display-name">{{ videoChannel.displayName }}</div> | ||
37 | <div class="video-channel-name">{{ videoChannel.name }}</div> | ||
38 | </a> | ||
39 | |||
40 | <div i18n class="video-channel-followers">{{ videoChannel.followersCount }} subscribers</div> | ||
41 | </div> | ||
42 | |||
43 | <my-subscribe-button [videoChannel]="videoChannel"></my-subscribe-button> | ||
44 | </div> | ||
45 | |||
29 | <div *ngFor="let video of videos" class="entry video"> | 46 | <div *ngFor="let video of videos" class="entry video"> |
30 | <my-video-thumbnail [video]="video"></my-video-thumbnail> | 47 | <my-video-thumbnail [video]="video"></my-video-thumbnail> |
31 | 48 | ||
diff --git a/client/src/app/search/search.component.scss b/client/src/app/search/search.component.scss index e54a8b32a..be7dd39cf 100644 --- a/client/src/app/search/search.component.scss +++ b/client/src/app/search/search.component.scss | |||
@@ -103,6 +103,42 @@ | |||
103 | } | 103 | } |
104 | } | 104 | } |
105 | } | 105 | } |
106 | |||
107 | &.video-channel { | ||
108 | |||
109 | img { | ||
110 | @include avatar(120px); | ||
111 | |||
112 | margin: 0 50px 0 40px; | ||
113 | } | ||
114 | |||
115 | .video-channel-info { | ||
116 | |||
117 | |||
118 | flex-grow: 1; | ||
119 | width: fit-content; | ||
120 | |||
121 | .video-channel-names { | ||
122 | @include disable-default-a-behaviour; | ||
123 | |||
124 | display: flex; | ||
125 | align-items: baseline; | ||
126 | color: #000; | ||
127 | width: fit-content; | ||
128 | |||
129 | .video-channel-display-name { | ||
130 | font-weight: $font-semibold; | ||
131 | font-size: 18px; | ||
132 | } | ||
133 | |||
134 | .video-channel-name { | ||
135 | font-size: 14px; | ||
136 | color: $grey-actor-name; | ||
137 | margin-left: 5px; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||
106 | } | 142 | } |
107 | } | 143 | } |
108 | 144 | ||
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts index 8d615fd05..f88df6391 100644 --- a/client/src/app/search/search.component.ts +++ b/client/src/app/search/search.component.ts | |||
@@ -2,13 +2,15 @@ import { Component, OnDestroy, OnInit } from '@angular/core' | |||
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { RedirectService } from '@app/core' | 3 | import { RedirectService } from '@app/core' |
4 | import { NotificationsService } from 'angular2-notifications' | 4 | import { NotificationsService } from 'angular2-notifications' |
5 | import { Subscription } from 'rxjs' | 5 | import { forkJoin, Subscription } from 'rxjs' |
6 | import { SearchService } from '@app/search/search.service' | 6 | import { SearchService } from '@app/search/search.service' |
7 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 7 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | 8 | import { I18n } from '@ngx-translate/i18n-polyfill' |
9 | import { Video } from '../../../../shared' | 9 | import { Video } from '../../../../shared' |
10 | import { MetaService } from '@ngx-meta/core' | 10 | import { MetaService } from '@ngx-meta/core' |
11 | import { AdvancedSearch } from '@app/search/advanced-search.model' | 11 | import { AdvancedSearch } from '@app/search/advanced-search.model' |
12 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | ||
13 | import { immutableAssign } from '@app/shared/misc/utils' | ||
12 | 14 | ||
13 | @Component({ | 15 | @Component({ |
14 | selector: 'my-search', | 16 | selector: 'my-search', |
@@ -17,18 +19,22 @@ import { AdvancedSearch } from '@app/search/advanced-search.model' | |||
17 | }) | 19 | }) |
18 | export class SearchComponent implements OnInit, OnDestroy { | 20 | export class SearchComponent implements OnInit, OnDestroy { |
19 | videos: Video[] = [] | 21 | videos: Video[] = [] |
22 | videoChannels: VideoChannel[] = [] | ||
23 | |||
20 | pagination: ComponentPagination = { | 24 | pagination: ComponentPagination = { |
21 | currentPage: 1, | 25 | currentPage: 1, |
22 | itemsPerPage: 10, // It's per object type (so 10 videos, 10 video channels etc) | 26 | itemsPerPage: 10, // Only for videos, use another variable for channels |
23 | totalItems: null | 27 | totalItems: null |
24 | } | 28 | } |
25 | advancedSearch: AdvancedSearch = new AdvancedSearch() | 29 | advancedSearch: AdvancedSearch = new AdvancedSearch() |
26 | isSearchFilterCollapsed = true | 30 | isSearchFilterCollapsed = true |
31 | currentSearch: string | ||
27 | 32 | ||
28 | private subActivatedRoute: Subscription | 33 | private subActivatedRoute: Subscription |
29 | private currentSearch: string | ||
30 | private isInitialLoad = true | 34 | private isInitialLoad = true |
31 | 35 | ||
36 | private channelsPerPage = 2 | ||
37 | |||
32 | constructor ( | 38 | constructor ( |
33 | private i18n: I18n, | 39 | private i18n: I18n, |
34 | private route: ActivatedRoute, | 40 | private route: ActivatedRoute, |
@@ -74,17 +80,23 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
74 | } | 80 | } |
75 | 81 | ||
76 | search () { | 82 | search () { |
77 | return this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch) | 83 | forkJoin([ |
84 | this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch), | ||
85 | this.searchService.searchVideoChannels(this.currentSearch, immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage })) | ||
86 | ]) | ||
78 | .subscribe( | 87 | .subscribe( |
79 | ({ videos, totalVideos }) => { | 88 | ([ videosResult, videoChannelsResult ]) => { |
80 | this.videos = this.videos.concat(videos) | 89 | this.videos = this.videos.concat(videosResult.videos) |
81 | this.pagination.totalItems = totalVideos | 90 | this.pagination.totalItems = videosResult.totalVideos |
91 | |||
92 | this.videoChannels = videoChannelsResult.data | ||
82 | }, | 93 | }, |
83 | 94 | ||
84 | error => { | 95 | error => { |
85 | this.notificationsService.error(this.i18n('Error'), error.message) | 96 | this.notificationsService.error(this.i18n('Error'), error.message) |
86 | } | 97 | } |
87 | ) | 98 | ) |
99 | |||
88 | } | 100 | } |
89 | 101 | ||
90 | onNearOfBottom () { | 102 | onNearOfBottom () { |
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts index a37c49161..cd3bdad35 100644 --- a/client/src/app/search/search.service.ts +++ b/client/src/app/search/search.service.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { catchError, switchMap } from 'rxjs/operators' | 1 | import { catchError, map, switchMap } from 'rxjs/operators' |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { Observable } from 'rxjs' | 4 | import { Observable } from 'rxjs' |
@@ -6,13 +6,11 @@ import { ComponentPagination } from '@app/shared/rest/component-pagination.model | |||
6 | import { VideoService } from '@app/shared/video/video.service' | 6 | import { VideoService } from '@app/shared/video/video.service' |
7 | import { RestExtractor, RestService } from '@app/shared' | 7 | import { RestExtractor, RestService } from '@app/shared' |
8 | import { environment } from 'environments/environment' | 8 | import { environment } from 'environments/environment' |
9 | import { ResultList, Video } from '../../../../shared' | 9 | import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared' |
10 | import { Video as VideoServerModel } from '@app/shared/video/video.model' | 10 | import { Video } from '@app/shared/video/video.model' |
11 | import { AdvancedSearch } from '@app/search/advanced-search.model' | 11 | import { AdvancedSearch } from '@app/search/advanced-search.model' |
12 | 12 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
13 | export type SearchResult = { | 13 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
14 | videosResult: { totalVideos: number, videos: Video[] } | ||
15 | } | ||
16 | 14 | ||
17 | @Injectable() | 15 | @Injectable() |
18 | export class SearchService { | 16 | export class SearchService { |
@@ -40,17 +38,7 @@ export class SearchService { | |||
40 | if (search) params = params.append('search', search) | 38 | if (search) params = params.append('search', search) |
41 | 39 | ||
42 | const advancedSearchObject = advancedSearch.toAPIObject() | 40 | const advancedSearchObject = advancedSearch.toAPIObject() |
43 | 41 | params = this.restService.addObjectParams(params, advancedSearchObject) | |
44 | for (const name of Object.keys(advancedSearchObject)) { | ||
45 | const value = advancedSearchObject[name] | ||
46 | if (!value) continue | ||
47 | |||
48 | if (Array.isArray(value) && value.length !== 0) { | ||
49 | for (const v of value) params = params.append(name, v) | ||
50 | } else { | ||
51 | params = params.append(name, value) | ||
52 | } | ||
53 | } | ||
54 | 42 | ||
55 | return this.authHttp | 43 | return this.authHttp |
56 | .get<ResultList<VideoServerModel>>(url, { params }) | 44 | .get<ResultList<VideoServerModel>>(url, { params }) |
@@ -59,4 +47,24 @@ export class SearchService { | |||
59 | catchError(err => this.restExtractor.handleError(err)) | 47 | catchError(err => this.restExtractor.handleError(err)) |
60 | ) | 48 | ) |
61 | } | 49 | } |
50 | |||
51 | searchVideoChannels ( | ||
52 | search: string, | ||
53 | componentPagination: ComponentPagination | ||
54 | ): Observable<{ data: VideoChannel[], total: number }> { | ||
55 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' | ||
56 | |||
57 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
58 | |||
59 | let params = new HttpParams() | ||
60 | params = this.restService.addRestGetParams(params, pagination) | ||
61 | params = params.append('search', search) | ||
62 | |||
63 | return this.authHttp | ||
64 | .get<ResultList<VideoChannelServerModel>>(url, { params }) | ||
65 | .pipe( | ||
66 | map(res => VideoChannelService.extractVideoChannels(res)), | ||
67 | catchError(err => this.restExtractor.handleError(err)) | ||
68 | ) | ||
69 | } | ||
62 | } | 70 | } |
diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts index 5d5410de9..4560c2024 100644 --- a/client/src/app/shared/rest/rest.service.ts +++ b/client/src/app/shared/rest/rest.service.ts | |||
@@ -32,6 +32,21 @@ export class RestService { | |||
32 | return newParams | 32 | return newParams |
33 | } | 33 | } |
34 | 34 | ||
35 | addObjectParams (params: HttpParams, object: object) { | ||
36 | for (const name of Object.keys(object)) { | ||
37 | const value = object[name] | ||
38 | if (!value) continue | ||
39 | |||
40 | if (Array.isArray(value) && value.length !== 0) { | ||
41 | for (const v of value) params = params.append(name, v) | ||
42 | } else { | ||
43 | params = params.append(name, value) | ||
44 | } | ||
45 | } | ||
46 | |||
47 | return params | ||
48 | } | ||
49 | |||
35 | componentPaginationToRestPagination (componentPagination: ComponentPagination): RestPagination { | 50 | componentPaginationToRestPagination (componentPagination: ComponentPagination): RestPagination { |
36 | const start: number = (componentPagination.currentPage - 1) * componentPagination.itemsPerPage | 51 | const start: number = (componentPagination.currentPage - 1) * componentPagination.itemsPerPage |
37 | const count: number = componentPagination.itemsPerPage | 52 | const count: number = componentPagination.itemsPerPage |
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' | |||
15 | export class SubscribeButtonComponent implements OnInit { | 15 | export 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 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | 1 | import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' |
2 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { ResultList } from '../../../../../shared' | 4 | import { ResultList } from '../../../../../shared' |
5 | import { environment } from '../../../environments/environment' | 5 | import { environment } from '../../../environments/environment' |
6 | import { RestExtractor } from '../rest' | 6 | import { RestExtractor, RestService } from '../rest' |
7 | import { Observable, of } from 'rxjs' | 7 | import { Observable, ReplaySubject, Subject } from 'rxjs' |
8 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | 8 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
9 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 9 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
10 | import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' | 10 | import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' |
11 | 11 | ||
12 | type SubscriptionExistResult = { [ uri: string ]: boolean } | ||
13 | |||
12 | @Injectable() | 14 | @Injectable() |
13 | export class UserSubscriptionService { | 15 | export 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 | } |
diff --git a/client/src/app/videos/+video-watch/video-watch.component.html b/client/src/app/videos/+video-watch/video-watch.component.html index 8a49e3566..e9c79741e 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.html +++ b/client/src/app/videos/+video-watch/video-watch.component.html | |||
@@ -43,7 +43,7 @@ | |||
43 | <img [src]="video.videoChannelAvatarUrl" alt="Video channel avatar" /> | 43 | <img [src]="video.videoChannelAvatarUrl" alt="Video channel avatar" /> |
44 | </a> | 44 | </a> |
45 | 45 | ||
46 | <my-subscribe-button [videoChannel]="video.channel"></my-subscribe-button> | 46 | <my-subscribe-button [videoChannel]="video.channel" size="small"></my-subscribe-button> |
47 | </div> | 47 | </div> |
48 | 48 | ||
49 | <div class="video-info-by"> | 49 | <div class="video-info-by"> |
diff --git a/client/src/app/videos/+video-watch/video-watch.component.scss b/client/src/app/videos/+video-watch/video-watch.component.scss index 5bf2f485a..6b18dc88a 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.scss +++ b/client/src/app/videos/+video-watch/video-watch.component.scss | |||
@@ -127,10 +127,6 @@ | |||
127 | } | 127 | } |
128 | 128 | ||
129 | my-subscribe-button { | 129 | my-subscribe-button { |
130 | /deep/ span[role=button] { | ||
131 | font-size: 13px !important; | ||
132 | } | ||
133 | |||
134 | margin-left: 5px; | 130 | margin-left: 5px; |
135 | } | 131 | } |
136 | } | 132 | } |