aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos
diff options
context:
space:
mode:
authorkimsible <kimsible@users.noreply.github.com>2020-08-12 12:43:26 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-14 15:03:38 +0200
commitfdd1296521354401e9927e5faeb0aa17ba810c41 (patch)
tree51a0e4db94db8736c51aec0b714c3cf0bda1ad9d /client/src/app/+videos
parente548a7c9b0c0d8bead03dd49ea86c600515e42db (diff)
downloadPeerTube-fdd1296521354401e9927e5faeb0aa17ba810c41.tar.gz
PeerTube-fdd1296521354401e9927e5faeb0aa17ba810c41.tar.zst
PeerTube-fdd1296521354401e9927e5faeb0aa17ba810c41.zip
Small refactor comments
Diffstat (limited to 'client/src/app/+videos')
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts41
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comment.component.html2
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comment.component.ts6
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comments.component.html1
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comments.component.ts4
5 files changed, 30 insertions, 24 deletions
diff --git a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
index 3d0611a2d..3fa5fd623 100644
--- a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
+++ b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts
@@ -17,11 +17,10 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
17export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit { 17export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit {
18 @Input() user: User 18 @Input() user: User
19 @Input() video: Video 19 @Input() video: Video
20 @Input() parentComment: VideoComment 20 @Input() parentComment?: VideoComment
21 @Input() parentComments: VideoComment[] 21 @Input() parentComments?: VideoComment[]
22 @Input() focusOnInit = false 22 @Input() focusOnInit = false
23 @Input() textValue?: string 23 @Input() textValue?: string
24 @Input() commentThread?: boolean
25 24
26 @Output() commentCreated = new EventEmitter<VideoComment>() 25 @Output() commentCreated = new EventEmitter<VideoComment>()
27 @Output() cancel = new EventEmitter() 26 @Output() cancel = new EventEmitter()
@@ -57,27 +56,13 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
57 }) 56 })
58 57
59 if (this.user) { 58 if (this.user) {
60 if (this.commentThread) { 59 if (!this.parentComment) {
61 this.addingCommentButtonValue = this.i18n('Comment') 60 this.addingCommentButtonValue = this.i18n('Comment')
62 } else { 61 } else {
63 this.addingCommentButtonValue = this.i18n('Reply') 62 this.addingCommentButtonValue = this.i18n('Reply')
64 } 63 }
65 64
66 if (this.textValue) { 65 this.initTextValue()
67 this.patchTextValue(this.textValue, this.focusOnInit)
68 return
69 }
70
71 if (this.parentComment) {
72 const mentions = this.parentComments
73 .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves
74 .map(c => '@' + c.by)
75
76 const mentionsSet = new Set(mentions)
77 const mentionsText = Array.from(mentionsSet).join(' ') + ' '
78
79 this.patchTextValue(mentionsText, this.focusOnInit)
80 }
81 } 66 }
82 } 67 }
83 68
@@ -176,6 +161,24 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
176 .addCommentThread(this.video.id, commentCreate) 161 .addCommentThread(this.video.id, commentCreate)
177 } 162 }
178 163
164 private initTextValue () {
165 if (this.textValue) {
166 this.patchTextValue(this.textValue, this.focusOnInit)
167 return
168 }
169
170 if (this.parentComment) {
171 const mentions = this.parentComments
172 .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves
173 .map(c => '@' + c.by)
174
175 const mentionsSet = new Set(mentions)
176 const mentionsText = Array.from(mentionsSet).join(' ') + ' '
177
178 this.patchTextValue(mentionsText, this.focusOnInit)
179 }
180 }
181
179 private patchTextValue (text: string, focus: boolean) { 182 private patchTextValue (text: string, focus: boolean) {
180 setTimeout(() => { 183 setTimeout(() => {
181 if (focus) { 184 if (focus) {
diff --git a/client/src/app/+videos/+video-watch/comment/video-comment.component.html b/client/src/app/+videos/+video-watch/comment/video-comment.component.html
index 8e44d0052..c4b2cd117 100644
--- a/client/src/app/+videos/+video-watch/comment/video-comment.component.html
+++ b/client/src/app/+videos/+video-watch/comment/video-comment.component.html
@@ -1,4 +1,4 @@
1<div *ngIf="!comment.isDeleted || comment.isDeleted && comment.totalReplies !== 0" class="root-comment"> 1<div *ngIf="isNotDeletedOrDeletedWithReplies()" class="root-comment">
2 <div class="left"> 2 <div class="left">
3 <a *ngIf="!comment.isDeleted" [href]="comment.account.url" target="_blank" rel="noopener noreferrer"> 3 <a *ngIf="!comment.isDeleted" [href]="comment.account.url" target="_blank" rel="noopener noreferrer">
4 <img 4 <img
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 5491023ee..17e7e28ca 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
@@ -75,7 +75,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
75 75
76 this.resetReply.emit() 76 this.resetReply.emit()
77 77
78 delete this.redraftValue 78 this.redraftValue = undefined
79 } 79 }
80 80
81 onWantToReply (comment?: VideoComment) { 81 onWantToReply (comment?: VideoComment) {
@@ -133,6 +133,10 @@ export class VideoCommentComponent implements OnInit, OnChanges {
133 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() 133 ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL()
134 } 134 }
135 135
136 isNotDeletedOrDeletedWithReplies () {
137 return !this.comment.isDeleted || this.comment.isDeleted && this.comment.totalReplies !== 0
138 }
139
136 private getUserIfNeeded (account: Account) { 140 private getUserIfNeeded (account: Account) {
137 if (!account.userId) return 141 if (!account.userId) return
138 if (!this.authService.isLoggedIn()) return 142 if (!this.authService.isLoggedIn()) return
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 ac69f094b..1bc0885a4 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
@@ -28,7 +28,6 @@
28 [user]="user" 28 [user]="user"
29 (commentCreated)="onCommentThreadCreated($event)" 29 (commentCreated)="onCommentThreadCreated($event)"
30 [textValue]="commentThreadRedraftValue" 30 [textValue]="commentThreadRedraftValue"
31 [commentThread]="true"
32 ></my-video-comment-add> 31 ></my-video-comment-add>
33 32
34 <div *ngIf="componentPagination.totalItems === 0 && comments.length === 0" i18n>No comments.</div> 33 <div *ngIf="componentPagination.totalItems === 0 && comments.length === 0" i18n>No comments.</div>
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 9e8e143c2..adce31c5b 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
@@ -133,7 +133,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
133 133
134 onCommentThreadCreated (comment: VideoComment) { 134 onCommentThreadCreated (comment: VideoComment) {
135 this.comments.unshift(comment) 135 this.comments.unshift(comment)
136 delete this.commentThreadRedraftValue 136 this.commentThreadRedraftValue = undefined
137 } 137 }
138 138
139 onWantedToReply (comment: VideoComment) { 139 onWantedToReply (comment: VideoComment) {
@@ -142,7 +142,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
142 142
143 onResetReply () { 143 onResetReply () {
144 this.inReplyToCommentId = undefined 144 this.inReplyToCommentId = undefined
145 delete this.commentReplyRedraftValue 145 this.commentReplyRedraftValue = undefined
146 } 146 }
147 147
148 onThreadCreated (commentTree: VideoCommentThreadTree) { 148 onThreadCreated (commentTree: VideoCommentThreadTree) {