Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Improve comments UX on mobile

Chocobozzza6836d27df3e
diff --git a/client/src/app/+video-watch/shared/comment/video-comment-add.component.html b/client/src/app/+video-watch/shared/comment/video-comment-add.component.html
index a48f891e25..95a082a46a 100644
--- a/client/src/app/+video-watch/shared/comment/video-comment-add.component.html
+++ b/client/src/app/+video-watch/shared/comment/video-comment-add.component.html
@@ -8,7 +8,7 @@
[readonly]="(user() === null) ? true : false"
(click)="openVisitorModal($event)"
formControlName="text" [ngClass]="{ 'input-error': formErrors['text'] }"
- (keyup.control.enter)="onValidKey()" (keyup.meta.enter)="onValidKey()" #textarea
+ (keyup.control.enter)="formValidated()" (keyup.meta.enter)="formValidated()" #textarea
>
</textarea>
@@ -46,15 +46,15 @@
</div>
<div class="comment-buttons">
- @if (isAddButtonDisplayed()) {
+ @if (hasCancel()) {
<button class="peertube-button tertiary-button cancel-button me-2" (click)="cancelCommentReply()" type="button" i18n>
Cancel
</button>
-
- <button class="peertube-button primary-button" [disabled]="!form.valid || addingComment">
- {{ addingCommentButtonValue }}
- </button>
}
+
+ <button class="peertube-button primary-button" [disabled]="!form.valid || addingComment">
+ {{ addingCommentButtonValue }}
+ </button>
</div>
</form>
diff --git a/client/src/app/+video-watch/shared/comment/video-comment-add.component.ts b/client/src/app/+video-watch/shared/comment/video-comment-add.component.ts
index 5bc8ab5614..158777a02d 100644
--- a/client/src/app/+video-watch/shared/comment/video-comment-add.component.ts
+++ b/client/src/app/+video-watch/shared/comment/video-comment-add.component.ts
@@ -1,5 +1,18 @@
import { getLocaleDirection, NgClass } from '@angular/common'
-import { Component, ElementRef, inject, input, LOCALE_ID, OnChanges, OnInit, output, SimpleChanges, viewChild } from '@angular/core'
+import {
+ booleanAttribute,
+ Component,
+ ElementRef,
+ inject,
+ input,
+ LOCALE_ID,
+ numberAttribute,
+ OnChanges,
+ OnInit,
+ output,
+ SimpleChanges,
+ viewChild
+} from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { Notifier, User } from '@app/core'
import { VIDEO_COMMENT_TEXT_VALIDATOR } from '@app/shared/form-validators/video-comment-validators'
@@ -46,7 +59,8 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
readonly videoPassword = input<string>(undefined)
readonly parentComment = input<VideoComment>(undefined)
readonly parentComments = input<VideoComment[]>(undefined)
- readonly focusOnInit = input(false)
+ readonly focusOnInit = input(false, { transform: booleanAttribute })
+ readonly hasCancel = input(true, { transform: booleanAttribute })
readonly textValue = input<string>(undefined)
readonly commentCreated = output<VideoComment>()
@@ -100,13 +114,6 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
return this.emojiMarkupList
}
- onValidKey () {
- this.forceCheck()
- if (!this.form.valid) return
-
- this.formValidated()
- }
-
openVisitorModal (event: any) {
if (this.user() === null) { // we only open it for visitors
// fixing ng-bootstrap ModalService and the "Expression Changed After It Has Been Checked" Error
@@ -130,6 +137,9 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
// If we validate very quickly the comment form, we might comment twice
if (this.addingComment) return
+ this.forceCheck()
+ if (!this.form.valid) return
+
this.addingComment = true
const commentCreate: VideoCommentCreate = this.form.value
@@ -156,10 +166,6 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
})
}
- isAddButtonDisplayed () {
- return this.form.value['text']
- }
-
getUri () {
return window.location.href
}
@@ -208,6 +214,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
.map(c => '@' + c.by)
const mentionsSet = new Set(mentions)
+
const mentionsText = Array.from(mentionsSet).join(' ') + ' '
this.patchTextValue(mentionsText, this.focusOnInit())
@@ -215,6 +222,8 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
}
private patchTextValue (text: string, focus: boolean) {
+ const hasText = text && text.trim() !== ''
+
setTimeout(() => {
if (focus) {
this.textareaElement().nativeElement.focus()
@@ -224,9 +233,9 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges,
this.textareaElement().nativeElement.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' })
// Use the native textarea autosize according to the text's break lines
- this.textareaElement().nativeElement.dispatchEvent(new Event('input'))
+ if (hasText) this.textareaElement().nativeElement.dispatchEvent(new Event('input'))
})
- this.form.patchValue({ text })
+ if (hasText) this.form.patchValue({ text })
}
}
diff --git a/client/src/app/+video-watch/shared/comment/video-comment.component.html b/client/src/app/+video-watch/shared/comment/video-comment.component.html
index edbaf050a0..9c0ef7d58a 100644
--- a/client/src/app/+video-watch/shared/comment/video-comment.component.html
+++ b/client/src/app/+video-watch/shared/comment/video-comment.component.html
@@ -1,5 +1,5 @@
@if (isCommentDisplayed()) {
- <div class="root-comment" [ngClass]="{ 'is-child': isChild() }">
+ <div class="root-comment" [ngClass]="{ 'is-child': isChild(), 'mb-3': firstInThread() }">
<div class="left">
@if (!comment().isDeleted) {
<my-actor-avatar
@@ -7,36 +7,43 @@
[actor]="comment().account" actorType="account" [size]="isChild() ? '25' : '36'"
></my-actor-avatar>
}
+
<div class="vertical-border"></div>
</div>
- <div class="right" [ngClass]="{ 'mb-3': firstInThread() }">
+
+ <div class="right">
<div class="comment">
@if (!comment().isDeleted) {
@if (highlightedComment() === true) {
<div class="highlighted-comment" i18n>Highlighted comment</div>
}
+
<div class="comment-account-date">
<div class="comment-account">
<a [routerLink]="[ '/a', comment().by ]">
<span class="comment-account-name" [ngClass]="{ 'video-author': video().account.id === comment().account.id }">
{{ comment().account.displayName }}
</span>
- <span class="comment-account-fid ms-1">{{ comment().by }}</span>
+ <span class="comment-account-handle ms-1">{{ comment().by }}</span>
</a>
</div>
+
<a [routerLink]="['/w', video().shortUUID, { 'threadId': comment().threadId }]" class="comment-date" [title]="comment().createdAt">
{{ comment().createdAt | myFromNow }}
</a>
+
@if (comment().heldForReview) {
<span class="pt-badge badge-red ms-2" i18n>Pending review</span>
}
</div>
+
<div
class="comment-html"
[innerHTML]="sanitizedCommentHTML"
(timestampClicked)="handleTimestampClicked($event)"
myTimestampRouteTransformer
></div>
+
<div class="comment-actions">
<button (click)="onWantToReply()" class="comment-action-reply border-0 p-0" i18n>Reply</button>
<my-user-moderation-dropdown
@@ -45,17 +52,18 @@
></my-user-moderation-dropdown>
</div>
}
+
@if (comment().isDeleted) {
<div class="comment-account-date">
<span class="comment-account" i18n>Deleted</span>
<a [routerLink]="['/w', video().shortUUID, { 'threadId': comment().threadId }]"
class="comment-date">{{ comment().createdAt | myFromNow }}</a>
</div>
+
<div class="comment-html comment-html-deleted">
<i i18n>This comment has been deleted</i>
</div>
- }
- @if (!comment().isDeleted && inReplyToCommentId() === comment().id) {
+ } @else if (inReplyToCommentId() === comment().id && !isInMobileView()) {
<my-video-comment-add
[user]="user"
[video]="video()"
@@ -68,6 +76,7 @@
[textValue]="redraftValue()"
></my-video-comment-add>
}
+
@if (commentTree()) {
<div>
@for (commentChild of commentTree().children; track commentChild) {
@@ -100,3 +109,26 @@
@if (prependModerationActions) {
<my-comment-report #commentReportModal [comment]="comment()"></my-comment-report>
}
+
+<ng-template #commentReplyModal>
+ <div class="modal-header">
+ <h4 class="modal-title" i18n>Reply to {{ comment().account?.displayName || 'Unknown' }}</h4>
+ <button class="border-0 p-0" title="Close this modal" i18n-title (click)="onResetReply()">
+ <my-global-icon iconName="cross" ariaHidden="true"></my-global-icon>
+ </button>
+ </div>
+
+ <div class="modal-body">
+ <my-video-comment-add
+ [user]="user"
+ [video]="video()"
+ [videoPassword]="videoPassword()"
+ [parentComment]="comment()"
+ [parentComments]="newParentComments"
+ [focusOnInit]="true"
+ (commentCreated)="onCommentReplyCreated($event)"
+ (cancelEdit)="onResetReply()"
+ [textValue]="redraftValue()"
+ ></my-video-comment-add>
+ </div>
+</ng-template>
diff --git a/client/src/app/+video-watch/shared/comment/video-comment.component.scss b/client/src/app/+video-watch/shared/comment/video-comment.component.scss
index 9b2122f5eb..ef08004063 100644
--- a/client/src/app/+video-watch/shared/comment/video-comment.component.scss
+++ b/client/src/app/+video-watch/shared/comment/video-comment.component.scss
@@ -9,13 +9,13 @@
flex-direction: column;
align-items: center;
- @include margin-right(10px);
+ @include margin-right(0.5rem);
.vertical-border {
width: 2px;
height: 100%;
background-color: rgba(0, 0, 0, 0.05);
- margin: 10px calc(1rem + 1px);
+ margin: 10px auto;
}
}
@@ -32,8 +32,8 @@
.highlighted-comment {
display: inline-block;
- background-color: pvar(--bg-secondary-400);
- color: pvar(--fg);
+ background-color: pvar(--primary);
+ color: pvar(--on-primary);
padding: 0 5px;
font-size: 13px;
margin-bottom: 5px;
@@ -77,7 +77,7 @@
}
}
- .comment-account-fid {
+ .comment-account-handle {
color: pvar(--fg-300);
}
}
@@ -142,29 +142,9 @@ my-video-comment-add {
}
}
-.is-child {
- .left {
- @include margin-right(6px);
- }
-}
-
-@media screen and (max-width: 1200px) {
- .children {
- @include margin-left(-10px);
- }
-}
-
@media screen and (max-width: 600px) {
- .children {
- @include margin-left(-20px);
-
- .left {
- align-items: flex-start;
-
- .vertical-border {
- @include margin-left(2px);
- }
- }
+ .is-child .left {
+ @include margin-right(0.25rem);
}
.comment-account-date {
diff --git a/client/src/app/+video-watch/shared/comment/video-comment.component.ts b/client/src/app/+video-watch/shared/comment/video-comment.component.ts
index 89c9d904bd..c4c1fecd7d 100644
--- a/client/src/app/+video-watch/shared/comment/video-comment.component.ts
+++ b/client/src/app/+video-watch/shared/comment/video-comment.component.ts
@@ -1,9 +1,10 @@
import { NgClass } from '@angular/common'
-import { Component, OnChanges, OnInit, inject, input, model, output, viewChild } from '@angular/core'
+import { Component, OnChanges, OnInit, TemplateRef, inject, input, model, output, viewChild } from '@angular/core'
import { RouterLink } from '@angular/router'
-import { MarkdownService, Notifier, UserService } from '@app/core'
+import { MarkdownService, Notifier, ScreenService, UserService } from '@app/core'
import { AuthService } from '@app/core/auth'
import { ActorAvatarComponent } from '@app/shared/shared-actor-image/actor-avatar.component'
+import { GlobalIconComponent } from '@app/shared/shared-icons/global-icon.component'
import { Account } from '@app/shared/shared-main/account/account.model'
import { DropdownAction } from '@app/shared/shared-main/buttons/action-dropdown.component'
import { FromNowPipe } from '@app/shared/shared-main/date/from-now.pipe'
@@ -12,6 +13,7 @@ import { CommentReportComponent } from '@app/shared/shared-moderation/report-mod
import { UserModerationDropdownComponent } from '@app/shared/shared-moderation/user-moderation-dropdown.component'
import { VideoCommentThreadTree } from '@app/shared/shared-video-comment/video-comment-thread-tree.model'
import { VideoComment } from '@app/shared/shared-video-comment/video-comment.model'
+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { User, UserRight } from '@peertube/peertube-models'
import { TimestampRouteTransformerDirective } from '../timestamp-route-transformer.directive'
import { VideoCommentAddComponent } from './video-comment-add.component'
@@ -28,6 +30,7 @@ import { VideoCommentAddComponent } from './video-comment-add.component'
UserModerationDropdownComponent,
VideoCommentAddComponent,
CommentReportComponent,
+ GlobalIconComponent,
FromNowPipe
]
})
@@ -36,8 +39,11 @@ export class VideoCommentComponent implements OnInit, OnChanges {
private authService = inject(AuthService)
private userService = inject(UserService)
private notifier = inject(Notifier)
+ private screenService = inject(ScreenService)
+ private modalService = inject(NgbModal)
readonly commentReportModal = viewChild<CommentReportComponent>('commentReportModal')
+ readonly commentReplyModal = viewChild<TemplateRef<any>>('commentReplyModal')
readonly video = input<Video>(undefined)
readonly videoPassword = input<string>(undefined)
@@ -64,6 +70,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
commentAccount: Account
commentUser: User
+ private replyModalRef: NgbModalRef
get user () {
return this.authService.getUser()
@@ -75,6 +82,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
ngOnChanges () {
this.init()
+ this.toggleMobileReplyModalIfNeeded()
}
onCommentReplyCreated (createdComment: VideoComment) {
@@ -97,6 +105,8 @@ export class VideoCommentComponent implements OnInit, OnChanges {
this.resetReply.emit()
this.redraftValue.set(undefined)
+
+ this.closeReplyModal()
}
onWantToReply (comment?: VideoComment) {
@@ -121,6 +131,11 @@ export class VideoCommentComponent implements OnInit, OnChanges {
onResetReply () {
this.resetReply.emit()
+ this.closeReplyModal()
+ }
+
+ isInMobileView () {
+ return this.screenService.isInMobileView()
}
handleTimestampClicked (timestamp: number) {
@@ -252,4 +267,28 @@ export class VideoCommentComponent implements OnInit, OnChanges {
private showReportModal () {
this.commentReportModal().show()
}
+
+ private closeReplyModal () {
+ if (!this.replyModalRef) return
+
+ this.replyModalRef.close()
+ this.replyModalRef = undefined
+ }
+
+ private toggleMobileReplyModalIfNeeded () {
+ const shouldOpenReplyModal = this.isInMobileView() &&
+ this.inReplyToCommentId() === this.comment().id
+
+ if (!shouldOpenReplyModal || this.replyModalRef) return
+
+ this.replyModalRef = this.modalService.open(this.commentReplyModal(), { centered: true })
+
+ this.replyModalRef.result.finally(() => {
+ this.replyModalRef = undefined
+
+ if (this.inReplyToCommentId() === this.comment().id) {
+ this.resetReply.emit()
+ }
+ })
+ }
}
diff --git a/client/src/app/+video-watch/shared/comment/video-comments.component.html b/client/src/app/+video-watch/shared/comment/video-comments.component.html
index b9648932e6..0864c4bef4 100644
--- a/client/src/app/+video-watch/shared/comment/video-comments.component.html
+++ b/client/src/app/+video-watch/shared/comment/video-comments.component.html
@@ -1,7 +1,7 @@
<div>
<div class="title-block">
<h2>
- {totalNotDeletedComments, plural, =0 {Comments} =1 {1 Comment} other {{{totalNotDeletedComments}} Comments}}
+ {totalNotDeletedComments, plural, =0 {Comments} =1 {1 Comment} other {{{ totalNotDeletedComments }} Comments}}
</h2>
<my-feed class="me-1" [syndicationItems]="syndicationItems"></my-feed>
@@ -25,6 +25,7 @@
[user]="user()"
(commentCreated)="onCommentThreadCreated($event)"
[textValue]="commentThreadRedraftValue"
+ hasCancel="false"
></my-video-comment-add>
@if (totalNotDeletedComments === 0 && comments.length === 0) {
@@ -73,19 +74,23 @@
(resetReply)="onResetReply()"
(timestampClicked)="handleTimestampClicked($event)"
[redraftValue]="commentReplyRedraftValue"
- >
+ >
@if (comment.totalReplies !== 0 && !threadComments[comment.id]) {
<button (click)="viewReplies(comment.id)" class="view-replies mb-2 button-unstyle">
<span class="chevron-down"></span>
@if (comment.totalRepliesFromVideoAuthor > 0) {
@if (comment.totalReplies !== comment.totalRepliesFromVideoAuthor) {
<ng-container i18n>
- View {comment.totalReplies, plural, =1 {1 reply} other {{{ comment.totalReplies }} replies}} from {{ video()?.account?.displayName || 'the author' }} and others
- </ng-container>
+ View {comment.totalReplies, plural, =1 {1 reply} other {{{ comment.totalReplies }} replies}} from {{
+ video()?.account?.displayName || 'the author'
+ }} and others
+ </ng-container>
} @else {
<ng-container i18n>
- View {comment.totalReplies, plural, =1 {1 reply} other {{{ comment.totalReplies }} replies}} from {{ video()?.account?.displayName || 'the author' }}
- </ng-container>
+ View {comment.totalReplies, plural, =1 {1 reply} other {{{ comment.totalReplies }} replies}} from {{
+ video()?.account?.displayName || 'the author'
+ }}
+ </ng-container>
}
} @else {
<ng-container i18n>View {comment.totalReplies, plural, =1 {1 reply} other {{{ comment.totalReplies }} replies}}</ng-container>