1 import { Component, Input, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
4 import { AuthService } from '../../../core/auth'
5 import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
6 import { User } from '../../../shared/users'
7 import { SortField } from '../../../shared/video/sort-field.type'
8 import { Video } from '../../../shared/video/video.model'
9 import { VideoComment } from './video-comment.model'
10 import { VideoCommentService } from './video-comment.service'
13 selector: 'my-video-comments',
14 templateUrl: './video-comments.component.html',
15 styleUrls: ['./video-comments.component.scss']
17 export class VideoCommentsComponent implements OnInit {
21 comments: VideoComment[] = []
22 sort: SortField = '-createdAt'
23 componentPagination: ComponentPagination = {
28 inReplyToCommentId: number
29 threadComments: { [ id: number ]: VideoCommentThreadTree } = {}
30 threadLoading: { [ id: number ]: boolean } = {}
33 private authService: AuthService,
34 private notificationsService: NotificationsService,
35 private videoCommentService: VideoCommentService
39 this.videoCommentService.getVideoCommentThreads(this.video.id, this.componentPagination, this.sort)
42 this.comments = res.comments
43 this.componentPagination.totalItems = res.totalComments
46 err => this.notificationsService.error('Error', err.message)
50 viewReplies (comment: VideoComment) {
51 this.threadLoading[comment.id] = true
53 this.videoCommentService.getVideoThreadComments(this.video.id, comment.id)
56 this.threadComments[comment.id] = res
57 this.threadLoading[comment.id] = false
60 err => this.notificationsService.error('Error', err.message)
64 onCommentThreadCreated (comment: VideoComment) {
65 this.comments.unshift(comment)
68 onWantedToReply (comment: VideoComment) {
69 this.inReplyToCommentId = comment.id
73 this.inReplyToCommentId = undefined
77 return this.authService.isLoggedIn()