X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bvideos%2F%2Bvideo-watch%2Fshared%2Fcomment%2Fvideo-comment-add.component.ts;h=9f4a68736b768bc1631794ded4c207e777a0d03c;hb=0d6843decdaecb4f726cba27fdb55fc164d00ba7;hp=78efe16843008bdf2d1c28c7f601a4b28b394d28;hpb=cf21b2cbef61929177b9c09b5e017c3b7eb8535d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts b/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts index 78efe1684..9f4a68736 100644 --- a/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts +++ b/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts @@ -25,7 +25,7 @@ import { VideoCommentCreate } from '@shared/models' @Component({ selector: 'my-video-comment-add', templateUrl: './video-comment-add.component.html', - styleUrls: ['./video-comment-add.component.scss'] + styleUrls: [ './video-comment-add.component.scss' ] }) export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit { @Input() user: User @@ -45,6 +45,8 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, addingComment = false addingCommentButtonValue: string + private emojiMarkupList: { emoji: string, name: string }[] + constructor ( protected formValidatorService: FormValidatorService, private notifier: Notifier, @@ -56,21 +58,6 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, super() } - get emojiMarkupList () { - const emojiMarkupObjectList = require('markdown-it-emoji/lib/data/light.json') - - // Populate emoji-markup-list from object to array to avoid keys alphabetical order - const emojiMarkupArrayList = [] - for (const emojiMarkupName in emojiMarkupObjectList) { - if (emojiMarkupName) { - const emoji = emojiMarkupObjectList[emojiMarkupName] - emojiMarkupArrayList.push([emoji, emojiMarkupName]) - } - } - - return emojiMarkupArrayList - } - ngOnInit () { this.buildForm({ text: VIDEO_COMMENT_TEXT_VALIDATOR @@ -91,13 +78,27 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, // Not initialized yet if (!this.form) return - if (changes.textValue && changes.textValue.currentValue && changes.textValue.currentValue !== changes.textValue.previousValue) { + if (changes.textValue?.currentValue && changes.textValue.currentValue !== changes.textValue.previousValue) { this.patchTextValue(changes.textValue.currentValue, true) } } + getEmojiMarkupList () { + if (this.emojiMarkupList) return this.emojiMarkupList + + const emojiMarkupObjectList = require('markdown-it-emoji/lib/data/light.json') + + this.emojiMarkupList = [] + for (const name of Object.keys(emojiMarkupObjectList)) { + const emoji = emojiMarkupObjectList[name] + this.emojiMarkupList.push({ emoji, name }) + } + + return this.emojiMarkupList + } + onValidKey () { - this.check() + this.forceCheck() if (!this.form.valid) return this.formValidated() @@ -137,19 +138,19 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, obs = this.addCommentThread(commentCreate) } - obs.subscribe( - comment => { + obs.subscribe({ + next: comment => { this.addingComment = false this.commentCreated.emit(comment) this.form.reset() }, - err => { + error: err => { this.addingComment = false - this.notifier.error(err.text) + this.notifier.error(err.message) } - ) + }) } isAddButtonDisplayed () { @@ -174,14 +175,20 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, return getLocaleDirection(this.localeId) === 'rtl' } + getAvatarActorType () { + if (this.user) return 'account' + + return 'unlogged' + } + private addCommentReply (commentCreate: VideoCommentCreate) { return this.videoCommentService - .addCommentReply(this.video.id, this.parentComment.id, commentCreate) + .addCommentReply(this.video.uuid, this.parentComment.id, commentCreate) } private addCommentThread (commentCreate: VideoCommentCreate) { return this.videoCommentService - .addCommentThread(this.video.id, commentCreate) + .addCommentThread(this.video.uuid, commentCreate) } private initTextValue () {