From 857507dd1d9f76cc686205874291144bf3cfa823 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Nov 2024 10:31:19 +0100 Subject: [PATCH] Optimize caption edit modal --- ...-caption-edit-modal-content.component.html | 114 +++++++++--------- ...-caption-edit-modal-content.component.scss | 2 + ...eo-caption-edit-modal-content.component.ts | 6 +- .../shared-main/buttons/button.component.ts | 16 ++- .../buttons/delete-button.component.ts | 7 +- .../buttons/edit-button.component.ts | 7 +- 6 files changed, 78 insertions(+), 74 deletions(-) diff --git a/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.html b/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.html index 08fc6a763..f472b505b 100644 --- a/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.html +++ b/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.html @@ -42,72 +42,78 @@
-
- @if (segmentToUpdate === segment) { -
-
-
- + @for (segment of segments; track segment.id) { +
+ @if (segmentToUpdate === segment) { +
+
+
+ - + - - + + +
+ + + +
+ + + + + + +
- +
+
+ -
- + - + +
- - +
+ + +
- -
-
- - - - - + } @else { +
+
+ {{ segment.startFormatted }} -> {{ segment.endFormatted }} + {{ segment.text }}
-
- - -
+
+ @defer (on viewport) { + + + } @placeholder { +
+ } +
-
- } @else { -
-
- {{ segment.startFormatted }} -> {{ segment.endFormatted }} - -
- -
- - -
-
- } -
+ } +
+ }
diff --git a/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.scss b/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.scss index a5f86c994..4ed446c52 100644 --- a/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.scss +++ b/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.scss @@ -14,6 +14,8 @@ } .segment-text { + white-space: pre-wrap; + &.active, &:hover { background: pvar(--mainBackgroundHoverColor); diff --git a/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.ts b/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.ts index 185f733b4..102126ae2 100644 --- a/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.ts +++ b/client/src/app/+videos/+video-edit/shared/caption/video-caption-edit-modal-content.component.ts @@ -330,13 +330,9 @@ export class VideoCaptionEditModalContentComponent extends FormReactive implemen this.openedModal.close() } - getSegmentClasses (segment: Segment) { - return { active: this.activeSegment === segment, ['segment-' + segment.id]: true } - } - private scrollToSegment (segment: Segment) { setTimeout(() => { - const element = document.querySelector('.segment-' + segment.id) + const element = document.querySelector(`.segments > div:nth-child(${parseInt(segment.id) + 1})`) if (!element) return element.scrollIntoView({ behavior: 'smooth', block: 'center' }) diff --git a/client/src/app/shared/shared-main/buttons/button.component.ts b/client/src/app/shared/shared-main/buttons/button.component.ts index f61c4abab..3a437e33f 100644 --- a/client/src/app/shared/shared-main/buttons/button.component.ts +++ b/client/src/app/shared/shared-main/buttons/button.component.ts @@ -1,10 +1,10 @@ -import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, booleanAttribute } from '@angular/core' +import { NgClass, NgIf, NgTemplateOutlet } from '@angular/common' +import { ChangeDetectionStrategy, Component, Input, OnChanges, booleanAttribute } from '@angular/core' +import { RouterLink } from '@angular/router' import { GlobalIconName } from '@app/shared/shared-icons/global-icon.component' +import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap' import { GlobalIconComponent } from '../../shared-icons/global-icon.component' import { LoaderComponent } from '../common/loader.component' -import { RouterLink } from '@angular/router' -import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap' -import { NgIf, NgClass, NgTemplateOutlet } from '@angular/common' @Component({ selector: 'my-button', @@ -15,7 +15,7 @@ import { NgIf, NgClass, NgTemplateOutlet } from '@angular/common' imports: [ NgIf, NgClass, NgbTooltip, NgTemplateOutlet, RouterLink, LoaderComponent, GlobalIconComponent ] }) -export class ButtonComponent implements OnInit, OnChanges { +export class ButtonComponent implements OnChanges { @Input() label = '' @Input() theme: 'orange' | 'grey' = 'grey' @Input() icon: GlobalIconName @@ -27,15 +27,13 @@ export class ButtonComponent implements OnInit, OnChanges { classes: { [id: string]: boolean } = {} - ngOnInit () { - this.buildClasses() - } - ngOnChanges () { this.buildClasses() } private buildClasses () { + console.log('build classes') + this.classes = { 'peertube-button': !this.ptRouterLink, 'peertube-button-link': !!this.ptRouterLink, diff --git a/client/src/app/shared/shared-main/buttons/delete-button.component.ts b/client/src/app/shared/shared-main/buttons/delete-button.component.ts index a3d296516..773caf94f 100644 --- a/client/src/app/shared/shared-main/buttons/delete-button.component.ts +++ b/client/src/app/shared/shared-main/buttons/delete-button.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core' +import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core' import { ButtonComponent } from './button.component' @Component({ @@ -11,15 +11,16 @@ import { ButtonComponent } from './button.component' > `, standalone: true, + changeDetection: ChangeDetectionStrategy.OnPush, imports: [ ButtonComponent ] }) -export class DeleteButtonComponent implements OnInit { +export class DeleteButtonComponent implements OnChanges { @Input() label: string @Input() title: string @Input() responsiveLabel = false @Input() disabled: boolean - ngOnInit () { + ngOnChanges () { if (this.label === undefined && !this.title) { this.title = $localize`Delete` } diff --git a/client/src/app/shared/shared-main/buttons/edit-button.component.ts b/client/src/app/shared/shared-main/buttons/edit-button.component.ts index 69e9ec413..e69ecb978 100644 --- a/client/src/app/shared/shared-main/buttons/edit-button.component.ts +++ b/client/src/app/shared/shared-main/buttons/edit-button.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core' +import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core' import { ButtonComponent } from './button.component' @Component({ @@ -10,15 +10,16 @@ import { ButtonComponent } from './button.component' > `, standalone: true, + changeDetection: ChangeDetectionStrategy.OnPush, imports: [ ButtonComponent ] }) -export class EditButtonComponent implements OnInit { +export class EditButtonComponent implements OnChanges { @Input() label: string @Input() title: string @Input() ptRouterLink: string[] | string = [] @Input() responsiveLabel = false - ngOnInit () { + ngOnChanges () { // No label if (this.label === undefined && !this.title) { this.title = $localize`Update`