aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
diff options
context:
space:
mode:
authorRigel Kent <par@rigelk.eu>2018-09-25 15:42:58 +0200
committerGitHub <noreply@github.com>2018-09-25 15:42:58 +0200
commit660d11e91e1643927028d2d6870a911f569b34d8 (patch)
tree455a39a397667eaa175a87d4b62b46406e75711a /client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
parentba6a98b8fad8214338e0d0919eac3439e90569fe (diff)
downloadPeerTube-660d11e91e1643927028d2d6870a911f569b34d8.tar.gz
PeerTube-660d11e91e1643927028d2d6870a911f569b34d8.tar.zst
PeerTube-660d11e91e1643927028d2d6870a911f569b34d8.zip
refactor subscribe button and comment-add for visitor-interact UX (#1100)
* refactor subscribe button for visitor-subscribe UX * refactor comment-add for visitor-interact UX
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comment-add.component.ts')
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comment-add.component.ts57
1 files changed, 47 insertions, 10 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 9998685e8..91af113d2 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
@@ -1,4 +1,5 @@
1import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' 1import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2import { Router } from '@angular/router'
2import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
3import { Observable } from 'rxjs' 4import { Observable } from 'rxjs'
4import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model' 5import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model'
@@ -10,6 +11,8 @@ import { VideoCommentService } from './video-comment.service'
10import { I18n } from '@ngx-translate/i18n-polyfill' 11import { I18n } from '@ngx-translate/i18n-polyfill'
11import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 12import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
12import { VideoCommentValidatorsService } from '@app/shared/forms/form-validators/video-comment-validators.service' 13import { VideoCommentValidatorsService } from '@app/shared/forms/form-validators/video-comment-validators.service'
14import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
15import { AuthService } from '@app/core/auth'
13 16
14@Component({ 17@Component({
15 selector: 'my-video-comment-add', 18 selector: 'my-video-comment-add',
@@ -25,15 +28,20 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
25 28
26 @Output() commentCreated = new EventEmitter<VideoCommentCreate>() 29 @Output() commentCreated = new EventEmitter<VideoCommentCreate>()
27 30
31 @ViewChild('visitorModal') visitorModal: NgbModal
28 @ViewChild('textarea') private textareaElement: ElementRef 32 @ViewChild('textarea') private textareaElement: ElementRef
29 33
30 private addingComment = false 34 private addingComment = false
35 private uri: string
31 36
32 constructor ( 37 constructor (
33 protected formValidatorService: FormValidatorService, 38 protected formValidatorService: FormValidatorService,
34 private videoCommentValidatorsService: VideoCommentValidatorsService, 39 private videoCommentValidatorsService: VideoCommentValidatorsService,
35 private notificationsService: NotificationsService, 40 private notificationsService: NotificationsService,
36 private videoCommentService: VideoCommentService, 41 private videoCommentService: VideoCommentService,
42 private authService: AuthService,
43 private modalService: NgbModal,
44 private router: Router,
37 private i18n: I18n 45 private i18n: I18n
38 ) { 46 ) {
39 super() 47 super()
@@ -44,19 +52,23 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
44 text: this.videoCommentValidatorsService.VIDEO_COMMENT_TEXT 52 text: this.videoCommentValidatorsService.VIDEO_COMMENT_TEXT
45 }) 53 })
46 54
47 if (this.focusOnInit === true) { 55 this.uri = this.router.url
48 this.textareaElement.nativeElement.focus()
49 }
50 56
51 if (this.parentComment) { 57 if (this.user) {
52 const mentions = this.parentComments 58 if (this.focusOnInit === true) {
53 .filter(c => c.account.id !== this.user.account.id) // Don't add mention of ourselves 59 this.textareaElement.nativeElement.focus()
54 .map(c => '@' + c.by) 60 }
61
62 if (this.parentComment) {
63 const mentions = this.parentComments
64 .filter(c => c.account.id !== this.user.account.id) // Don't add mention of ourselves
65 .map(c => '@' + c.by)
55 66
56 const mentionsSet = new Set(mentions) 67 const mentionsSet = new Set(mentions)
57 const mentionsText = Array.from(mentionsSet).join(' ') + ' ' 68 const mentionsText = Array.from(mentionsSet).join(' ') + ' '
58 69
59 this.form.patchValue({ text: mentionsText }) 70 this.form.patchValue({ text: mentionsText })
71 }
60 } 72 }
61 } 73 }
62 74
@@ -67,6 +79,20 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
67 this.formValidated() 79 this.formValidated()
68 } 80 }
69 81
82 openVisitorModal (event) {
83 if (this.user === null) { // we only open it for visitors
84 // fixing ng-bootstrap ModalService and the "Expression Changed After It Has Been Checked" Error
85 event.srcElement.blur()
86 event.preventDefault()
87
88 this.modalService.open(this.visitorModal)
89 }
90 }
91
92 hideVisitorModal () {
93 this.modalService.dismissAll()
94 }
95
70 formValidated () { 96 formValidated () {
71 // If we validate very quickly the comment form, we might comment twice 97 // If we validate very quickly the comment form, we might comment twice
72 if (this.addingComment) return 98 if (this.addingComment) return
@@ -101,6 +127,17 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
101 return this.form.value['text'] 127 return this.form.value['text']
102 } 128 }
103 129
130 getAvatarUrl () {
131 if (this.user) return this.user.accountAvatarUrl
132 return window.location.origin + '/client/assets/images/default-avatar.png'
133 }
134
135 gotoLogin () {
136 this.hideVisitorModal()
137 this.authService.redirectUrl = this.router.url
138 this.router.navigate([ '/login' ])
139 }
140
104 private addCommentReply (commentCreate: VideoCommentCreate) { 141 private addCommentReply (commentCreate: VideoCommentCreate) {
105 return this.videoCommentService 142 return this.videoCommentService
106 .addCommentReply(this.video.id, this.parentComment.id, commentCreate) 143 .addCommentReply(this.video.id, this.parentComment.id, commentCreate)