From c199c427d4ae586339822320f20f512a7a19dc3f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Oct 2018 14:35:31 +0200 Subject: Better typings --- .../shared/video-caption-add-modal.component.ts | 5 +++-- .../video-import-torrent.component.ts | 6 +++--- .../+video-edit/video-add-components/video-send.ts | 6 +++--- .../video-add-components/video-upload.component.ts | 6 +++--- .../app/videos/+video-watch/comment/linkifier.service.ts | 1 + .../+video-watch/comment/video-comment.component.ts | 2 +- .../videos/+video-watch/comment/video-comment.service.ts | 8 ++++---- .../+video-watch/comment/video-comments.component.html | 2 +- .../+video-watch/comment/video-comments.component.scss | 2 +- .../+video-watch/comment/video-comments.component.ts | 3 ++- .../app/videos/+video-watch/video-watch.component.scss | 2 +- .../src/app/videos/+video-watch/video-watch.component.ts | 16 +++++++++------- 12 files changed, 32 insertions(+), 27 deletions(-) (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts b/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts index a2c9237ad..796fbe531 100644 --- a/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts +++ b/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts @@ -5,6 +5,7 @@ import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validator import { ServerService } from '@app/core' import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' +import { VideoConstant } from '../../../../../../shared' @Component({ selector: 'my-video-caption-add-modal', @@ -19,7 +20,7 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni @ViewChild('modal') modal: ElementRef - videoCaptionLanguages: any = [] + videoCaptionLanguages: VideoConstant[] = [] private openedModal: NgbModalRef private closingModal = false @@ -73,7 +74,7 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni this.hide() const languageId = this.form.value[ 'language' ] - const languageObject = this.videoCaptionLanguages.find((l: any) => l.id === languageId) + const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId) this.captionAdded.emit({ language: languageObject, diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts index 9a50e2ab2..e13c06ce9 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' +import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' import { Router } from '@angular/router' import { NotificationsService } from 'angular2-notifications' import { VideoPrivacy, VideoUpdate } from '../../../../../../shared/models/videos' @@ -23,7 +23,7 @@ import { VideoImportService } from '@app/shared/video-import' }) export class VideoImportTorrentComponent extends VideoSend implements OnInit, CanComponentDeactivate { @Output() firstStepDone = new EventEmitter() - @ViewChild('torrentfileInput') torrentfileInput: any + @ViewChild('torrentfileInput') torrentfileInput: ElementRef videoFileName: string magnetUri = '' @@ -64,7 +64,7 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca } fileChange () { - const torrentfile = this.torrentfileInput.nativeElement.files[0] as File + const torrentfile = this.torrentfileInput.nativeElement.files[0] if (!torrentfile) return this.importVideo(torrentfile) diff --git a/client/src/app/videos/+video-edit/video-add-components/video-send.ts b/client/src/app/videos/+video-edit/video-add-components/video-send.ts index cf9d47cbe..1bf22e1a9 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-send.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-send.ts @@ -3,7 +3,6 @@ import { LoadingBarService } from '@ngx-loading-bar/core' import { NotificationsService } from 'angular2-notifications' import { catchError, switchMap, tap } from 'rxjs/operators' import { FormReactive } from '@app/shared' -import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' import { VideoConstant, VideoPrivacy } from '../../../../../../shared' import { AuthService, ServerService } from '@app/core' import { VideoService } from '@app/shared/video/video.service' @@ -11,8 +10,9 @@ import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.m import { VideoCaptionService } from '@app/shared/video-caption' import { VideoEdit } from '@app/shared/video/video-edit.model' import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils' +import { CanComponentDeactivateResult } from '@app/shared/guards/can-deactivate-guard.service' -export abstract class VideoSend extends FormReactive implements OnInit, CanComponentDeactivate { +export abstract class VideoSend extends FormReactive implements OnInit { userVideoChannels: { id: number, label: string, support: string }[] = [] videoPrivacies: VideoConstant[] = [] videoCaptions: VideoCaptionEdit[] = [] @@ -30,7 +30,7 @@ export abstract class VideoSend extends FormReactive implements OnInit, CanCompo protected videoService: VideoService protected videoCaptionService: VideoCaptionService - abstract canDeactivate (): any + abstract canDeactivate (): CanComponentDeactivateResult ngOnInit () { this.buildForm({}) diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts index fa6ee0c23..8e2d0deaf 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts @@ -1,5 +1,5 @@ import { HttpEventType, HttpResponse } from '@angular/common/http' -import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' +import { Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' import { Router } from '@angular/router' import { LoadingBarService } from '@ngx-loading-bar/core' import { NotificationsService } from 'angular2-notifications' @@ -25,7 +25,7 @@ import { VideoCaptionService } from '@app/shared/video-caption' }) export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy, CanComponentDeactivate { @Output() firstStepDone = new EventEmitter() - @ViewChild('videofileInput') videofileInput: any + @ViewChild('videofileInput') videofileInput: ElementRef // So that it can be accessed in the template readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY @@ -110,7 +110,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy } uploadFirstStep () { - const videofile = this.videofileInput.nativeElement.files[0] as File + const videofile = this.videofileInput.nativeElement.files[0] if (!videofile) return // Cannot upload videos > 8GB for now diff --git a/client/src/app/videos/+video-watch/comment/linkifier.service.ts b/client/src/app/videos/+video-watch/comment/linkifier.service.ts index 9ad419a69..4f4ec1e5d 100644 --- a/client/src/app/videos/+video-watch/comment/linkifier.service.ts +++ b/client/src/app/videos/+video-watch/comment/linkifier.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core' import { getAbsoluteAPIUrl } from '@app/shared/misc/utils' +// FIXME: use @types/linkify when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/29682/files is merged? const linkify = require('linkifyjs') const linkifyHtml = require('linkifyjs/html') diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts index 982470786..00f0460a1 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts @@ -26,7 +26,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { @Output() resetReply = new EventEmitter() sanitizedCommentHTML = '' - newParentComments: any = [] + newParentComments: VideoComment[] = [] constructor ( private linkifierService: LinkifierService, diff --git a/client/src/app/videos/+video-watch/comment/video-comment.service.ts b/client/src/app/videos/+video-watch/comment/video-comment.service.ts index 7d9c2d0ad..921447d5b 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.service.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.service.ts @@ -30,9 +30,9 @@ export class VideoCommentService { const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' const normalizedComment = lineFeedToHtml(comment, 'text') - return this.authHttp.post(url, normalizedComment) + return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) .pipe( - map((data: any) => this.extractVideoComment(data['comment'])), + map(data => this.extractVideoComment(data.comment)), catchError(err => this.restExtractor.handleError(err)) ) } @@ -41,9 +41,9 @@ export class VideoCommentService { const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId const normalizedComment = lineFeedToHtml(comment, 'text') - return this.authHttp.post(url, normalizedComment) + return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) .pipe( - map((data: any) => this.extractVideoComment(data[ 'comment' ])), + map(data => this.extractVideoComment(data.comment)), catchError(err => this.restExtractor.handleError(err)) ) } diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.html b/client/src/app/videos/+video-watch/comment/video-comments.component.html index 42e129d65..44016d8ad 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.html @@ -4,7 +4,7 @@ Comments - + diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.scss b/client/src/app/videos/+video-watch/comment/video-comments.component.scss index dbb44c66c..575e331e4 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.scss +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.scss @@ -23,7 +23,7 @@ margin-right: 0; } -my-video-feed { +my-feed { display: inline-block; margin-left: 5px; } diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.ts b/client/src/app/videos/+video-watch/comment/video-comments.component.ts index 4c1bdf2dd..8850eccd8 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.ts @@ -12,6 +12,7 @@ import { VideoDetails } from '../../../shared/video/video-details.model' import { VideoComment } from './video-comment.model' import { VideoCommentService } from './video-comment.service' import { I18n } from '@ngx-translate/i18n-polyfill' +import { Syndication } from '@app/shared/video/syndication.model' @Component({ selector: 'my-video-comments', @@ -35,7 +36,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { threadComments: { [ id: number ]: VideoCommentThreadTree } = {} threadLoading: { [ id: number ]: boolean } = {} - syndicationItems: any = [] + syndicationItems: Syndication[] = [] private sub: Subscription 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 f31e4694a..2586a2204 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.scss +++ b/client/src/app/videos/+video-watch/video-watch.component.scss @@ -162,7 +162,7 @@ $other-videos-width: 260px; } } - my-video-feed { + my-feed { margin-left: 5px; margin-top: 1px; } 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 ed5e723c9..65b974037 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -7,7 +7,9 @@ import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-supp import { MetaService } from '@ngx-meta/core' import { NotificationsService } from 'angular2-notifications' import { forkJoin, Subscription } from 'rxjs' -const videojs = require('video.js') +// FIXME: something weird with our path definition in tsconfig and typings +// @ts-ignore +import videojs from 'video.js' import 'videojs-hotkeys' import { Hotkey, HotkeysService } from 'angular2-hotkeys' import * as WebTorrent from 'webtorrent' @@ -45,7 +47,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { @ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent - player: any + player: videojs.Player playerElement: HTMLVideoElement userRating: UserVideoRateType = null video: VideoDetails = null @@ -435,7 +437,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.zone.runOutsideAngular(async () => { videojs(this.playerElement, videojsOptions, function () { self.player = this - this.on('customError', (data: any) => self.handleError(data.err)) + this.on('customError', ({ err }: { err: any }) => self.handleError(err)) addContextMenu(self.player, self.video.embedUrl) }) @@ -448,7 +450,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.checkUserRating() } - private setRating (nextRating: string) { + private setRating (nextRating: VideoRateType) { let method switch (nextRating) { case 'like': @@ -466,11 +468,11 @@ export class VideoWatchComponent implements OnInit, OnDestroy { .subscribe( () => { // Update the video like attribute - this.updateVideoRating(this.userRating, nextRating as VideoRateType) - this.userRating = nextRating as UserVideoRateType + this.updateVideoRating(this.userRating, nextRating) + this.userRating = nextRating }, - (err: any) => this.notificationsService.error(this.i18n('Error'), err.message) + (err: { message: string }) => this.notificationsService.error(this.i18n('Error'), err.message) ) } -- cgit v1.2.3