aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch/comment/video-comments.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-19 10:38:24 +0100
committerChocobozzz <me@florianbigard.com>2018-02-19 10:48:44 +0100
commit1263fc4e6eff9ba4bf4c706c6e37c2e556bf8eb5 (patch)
tree00c27b7e6a81dfc04a8cc86ba782df1e9d0c1db8 /client/src/app/videos/+video-watch/comment/video-comments.component.ts
parent3bb6c52645af84832212c99fdec04143e4230180 (diff)
downloadPeerTube-1263fc4e6eff9ba4bf4c706c6e37c2e556bf8eb5.tar.gz
PeerTube-1263fc4e6eff9ba4bf4c706c6e37c2e556bf8eb5.tar.zst
PeerTube-1263fc4e6eff9ba4bf4c706c6e37c2e556bf8eb5.zip
Improve comment highlighting
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comments.component.ts')
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comments.component.ts76
1 files changed, 42 insertions, 34 deletions
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 7970a5dcf..aada9554d 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
@@ -1,7 +1,9 @@
1import { Component, Input, OnChanges, SimpleChanges } from '@angular/core' 1import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'
2import { ActivatedRoute } from '@angular/router'
2import { ConfirmService } from '@app/core' 3import { ConfirmService } from '@app/core'
3import { NotificationsService } from 'angular2-notifications' 4import { NotificationsService } from 'angular2-notifications'
4import { VideoComment as VideoCommentInterface, VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' 5import { Subscription } from 'rxjs/Subscription'
6import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
5import { AuthService } from '../../../core/auth' 7import { AuthService } from '../../../core/auth'
6import { ComponentPagination } from '../../../shared/rest/component-pagination.model' 8import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
7import { User } from '../../../shared/users' 9import { User } from '../../../shared/users'
@@ -9,18 +11,18 @@ import { SortField } from '../../../shared/video/sort-field.type'
9import { VideoDetails } from '../../../shared/video/video-details.model' 11import { VideoDetails } from '../../../shared/video/video-details.model'
10import { VideoComment } from './video-comment.model' 12import { VideoComment } from './video-comment.model'
11import { VideoCommentService } from './video-comment.service' 13import { VideoCommentService } from './video-comment.service'
12import { ActivatedRoute } from '@angular/router'
13 14
14@Component({ 15@Component({
15 selector: 'my-video-comments', 16 selector: 'my-video-comments',
16 templateUrl: './video-comments.component.html', 17 templateUrl: './video-comments.component.html',
17 styleUrls: ['./video-comments.component.scss'] 18 styleUrls: ['./video-comments.component.scss']
18}) 19})
19export class VideoCommentsComponent implements OnChanges { 20export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
20 @Input() video: VideoDetails 21 @Input() video: VideoDetails
21 @Input() user: User 22 @Input() user: User
22 23
23 comments: VideoComment[] = [] 24 comments: VideoComment[] = []
25 highlightedComment: VideoComment
24 sort: SortField = '-createdAt' 26 sort: SortField = '-createdAt'
25 componentPagination: ComponentPagination = { 27 componentPagination: ComponentPagination = {
26 currentPage: 1, 28 currentPage: 1,
@@ -30,7 +32,8 @@ export class VideoCommentsComponent implements OnChanges {
30 inReplyToCommentId: number 32 inReplyToCommentId: number
31 threadComments: { [ id: number ]: VideoCommentThreadTree } = {} 33 threadComments: { [ id: number ]: VideoCommentThreadTree } = {}
32 threadLoading: { [ id: number ]: boolean } = {} 34 threadLoading: { [ id: number ]: boolean } = {}
33 markedCommentID: number 35
36 private sub: Subscription
34 37
35 constructor ( 38 constructor (
36 private authService: AuthService, 39 private authService: AuthService,
@@ -40,20 +43,38 @@ export class VideoCommentsComponent implements OnChanges {
40 private activatedRoute: ActivatedRoute 43 private activatedRoute: ActivatedRoute
41 ) {} 44 ) {}
42 45
46 ngOnInit () {
47 // Find highlighted comment in params
48 this.sub = this.activatedRoute.params.subscribe(
49 params => {
50 if (params['commentId']) {
51 const highlightedCommentId = +params['commentId']
52 this.processHighlightedComment(highlightedCommentId)
53 }
54 }
55 )
56 }
57
43 ngOnChanges (changes: SimpleChanges) { 58 ngOnChanges (changes: SimpleChanges) {
44 if (changes['video']) { 59 if (changes['video']) {
45 this.loadVideoComments() 60 this.resetVideo()
46 } 61 }
47 } 62 }
48 63
49 viewReplies (comment: VideoCommentInterface) { 64 ngOnDestroy () {
50 this.threadLoading[comment.id] = true 65 if (this.sub) this.sub.unsubscribe()
66 }
67
68 viewReplies (commentId: number, highlightComment = false) {
69 this.threadLoading[commentId] = true
51 70
52 this.videoCommentService.getVideoThreadComments(this.video.id, comment.id) 71 this.videoCommentService.getVideoThreadComments(this.video.id, commentId)
53 .subscribe( 72 .subscribe(
54 res => { 73 res => {
55 this.threadComments[comment.id] = res 74 this.threadComments[commentId] = res
56 this.threadLoading[comment.id] = false 75 this.threadLoading[commentId] = false
76
77 if (highlightComment) this.highlightedComment = new VideoComment(res.comment)
57 }, 78 },
58 79
59 err => this.notificationsService.error('Error', err.message) 80 err => this.notificationsService.error('Error', err.message)
@@ -66,18 +87,6 @@ export class VideoCommentsComponent implements OnChanges {
66 res => { 87 res => {
67 this.comments = this.comments.concat(res.comments) 88 this.comments = this.comments.concat(res.comments)
68 this.componentPagination.totalItems = res.totalComments 89 this.componentPagination.totalItems = res.totalComments
69
70 if (this.markedCommentID) {
71 // If there is a marked comment, retrieve it separately as it may not be on this page, filter to prevent duplicate
72 this.comments = this.comments.filter(value => value.id !== this.markedCommentID)
73 this.videoCommentService.getVideoThreadComments(this.video.id, this.markedCommentID).subscribe(
74 res => {
75 let comment = new VideoComment(res.comment)
76 comment.marked = true
77 this.comments.unshift(comment) // Insert marked comment at the beginning
78 }
79 )
80 }
81 }, 90 },
82 91
83 err => this.notificationsService.error('Error', err.message) 92 err => this.notificationsService.error('Error', err.message)
@@ -97,7 +106,7 @@ export class VideoCommentsComponent implements OnChanges {
97 } 106 }
98 107
99 onThreadCreated (commentTree: VideoCommentThreadTree) { 108 onThreadCreated (commentTree: VideoCommentThreadTree) {
100 this.viewReplies(commentTree.comment) 109 this.viewReplies(commentTree.comment.id)
101 } 110 }
102 111
103 onWantedToDelete (commentToDelete: VideoComment) { 112 onWantedToDelete (commentToDelete: VideoComment) {
@@ -168,9 +177,10 @@ export class VideoCommentsComponent implements OnChanges {
168 } 177 }
169 } 178 }
170 179
171 private loadVideoComments () { 180 private resetVideo () {
172 if (this.video.commentsEnabled === true) { 181 if (this.video.commentsEnabled === true) {
173 // Reset all our fields 182 // Reset all our fields
183 this.highlightedComment = null
174 this.comments = [] 184 this.comments = []
175 this.threadComments = {} 185 this.threadComments = {}
176 this.threadLoading = {} 186 this.threadLoading = {}
@@ -178,16 +188,14 @@ export class VideoCommentsComponent implements OnChanges {
178 this.componentPagination.currentPage = 1 188 this.componentPagination.currentPage = 1
179 this.componentPagination.totalItems = null 189 this.componentPagination.totalItems = null
180 190
181 // Find marked comment in params
182 this.activatedRoute.params.subscribe(
183 params => {
184 if (params['commentId']) {
185 this.markedCommentID = +params['commentId']
186 }
187 }
188 )
189
190 this.loadMoreComments() 191 this.loadMoreComments()
191 } 192 }
192 } 193 }
194
195 private processHighlightedComment (highlightedCommentId: number) {
196 this.highlightedComment = this.comments.find(c => c.id === highlightedCommentId)
197
198 const highlightComment = true
199 this.viewReplies(highlightedCommentId, highlightComment)
200 }
193} 201}