From 154898b0b7bc1af41fc5a94974e338a3590c90f3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 17 Jun 2017 11:28:11 +0200 Subject: Share models between server and client --- client/src/app/videos/shared/rate-type.type.ts | 1 - client/src/app/videos/shared/video.service.ts | 6 +++--- client/src/app/videos/video-watch/video-watch.component.ts | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 client/src/app/videos/shared/rate-type.type.ts (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/shared/rate-type.type.ts b/client/src/app/videos/shared/rate-type.type.ts deleted file mode 100644 index 20eea3ae5..000000000 --- a/client/src/app/videos/shared/rate-type.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type RateType = 'like' | 'dislike' diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index a4e3d16df..977b82118 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -6,7 +6,6 @@ import 'rxjs/add/operator/map' import { Search } from '../../shared' import { SortField } from './sort-field.type' -import { RateType } from './rate-type.type' import { AuthService } from '../../core' import { AuthHttp, @@ -17,6 +16,7 @@ import { UserService } from '../../shared' import { Video } from './video.model' +import { VideoRateType } from '../../../../../shared' @Injectable() export class VideoService { @@ -145,7 +145,7 @@ export class VideoService { return this.setVideoRate(id, 'dislike') } - getUserVideoRating (id: string) { + getUserVideoRating (id: string): Observable { const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating' return this.authHttp.get(url) @@ -159,7 +159,7 @@ export class VideoService { .catch((res) => this.restExtractor.handleError(res)) } - private setVideoRate (id: string, rateType: RateType) { + private setVideoRate (id: string, rateType: VideoRateType) { const url = VideoService.BASE_VIDEO_URL + id + '/rate' const body = { rating: rateType diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts index 4a547f7e4..808e0eda9 100644 --- a/client/src/app/videos/video-watch/video-watch.component.ts +++ b/client/src/app/videos/video-watch/video-watch.component.ts @@ -11,15 +11,15 @@ import { AuthService, ConfirmService } from '../../core' import { VideoMagnetComponent } from './video-magnet.component' import { VideoShareComponent } from './video-share.component' import { VideoReportComponent } from './video-report.component' -import { RateType, Video, VideoService } from '../shared' +import { Video, VideoService } from '../shared' import { WebTorrentService } from './webtorrent.service' +import { UserVideoRateType, VideoRateType, UserVideoRate } from '../../../../../shared' @Component({ selector: 'my-video-watch', templateUrl: './video-watch.component.html', styleUrls: [ './video-watch.component.scss' ] }) - export class VideoWatchComponent implements OnInit, OnDestroy { private static LOADTIME_TOO_LONG = 20000 @@ -34,7 +34,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { player: videojs.Player playerElement: Element uploadSpeed: number - userRating: RateType = null + userRating: UserVideoRateType = null video: Video = null videoNotFound = false @@ -249,7 +249,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.videoService.getUserVideoRating(this.video.id) .subscribe( - ratingObject => { + (ratingObject: UserVideoRate) => { if (ratingObject) { this.userRating = ratingObject.rating } @@ -282,7 +282,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { ) } - private updateVideoRating (oldRating: RateType, newRating: RateType) { + private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) { let likesToIncrement = 0 let dislikesToIncrement = 0 -- cgit v1.2.3