Optimize video miniature dropdown

This commit is contained in:
Chocobozzz 2024-11-26 10:52:44 +01:00
parent 4a58c08c5b
commit 2929765025
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
7 changed files with 22 additions and 32 deletions

View File

@ -1,4 +1,7 @@
<div class="dropdown-root" ngbDropdown [placement]="placement" [container]="container" *ngIf="areActionsDisplayed(actions, entry)"> <div
*ngIf="areActionsDisplayed(actions, entry)" class="dropdown-root"
ngbDropdown (openChange)="openChange.emit($event)" [placement]="placement" [container]="container"
>
<button <button
class="action-button peertube-button" class="action-button peertube-button"
[ngClass]="{ 'icon-only': !label, 'peertube-button-small': buttonSize === 'small', 'secondary-button': buttonStyled && theme === 'secondary', 'primary-button': buttonStyled && theme === 'primary' }" [ngClass]="{ 'icon-only': !label, 'peertube-button-small': buttonSize === 'small', 'secondary-button': buttonStyled && theme === 'secondary', 'primary-button': buttonStyled && theme === 'primary' }"

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core' import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'
import { Params, RouterLink } from '@angular/router' import { Params, RouterLink } from '@angular/router'
import { GlobalIconName } from '@app/shared/shared-icons/global-icon.component' import { GlobalIconName } from '@app/shared/shared-icons/global-icon.component'
import { GlobalIconComponent } from '../../shared-icons/global-icon.component' import { GlobalIconComponent } from '../../shared-icons/global-icon.component'
@ -61,6 +61,8 @@ export class ActionDropdownComponent<T> {
@Input() label: string @Input() label: string
@Input() theme: DropdownTheme = 'secondary' @Input() theme: DropdownTheme = 'secondary'
@Output() openChange = new EventEmitter<boolean>()
getActions (): DropdownAction<T>[][] { getActions (): DropdownAction<T>[][] {
if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][] if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]

View File

@ -1,21 +1,23 @@
<ng-container *ngIf="videoActions.length !== 0"> <ng-container *ngIf="videoActions.length !== 0">
<div <div
*ngIf="isUserLoggedIn() && displayOptions.playlist"
role="button" aria-label="Open video actions" i18n-aria-label role="button" aria-label="Open video actions" i18n-aria-label
class="playlist-dropdown" ngbDropdown #playlistDropdown="ngbDropdown" autoClose="outside" [placement]="getPlaylistDropdownPlacement()" class="playlist-dropdown" ngbDropdown #playlistDropdown="ngbDropdown" autoClose="outside" [placement]="getPlaylistDropdownPlacement()"
*ngIf="isUserLoggedIn() && displayOptions.playlist" (openChange)="playlistAdd.openChange($event)"
> >
<span class="anchor" ngbDropdownAnchor></span> <span class="anchor" ngbDropdownAnchor></span>
<div ngbDropdownMenu> <div ngbDropdownMenu>
<my-video-add-to-playlist #playlistAdd [video]="video" [lazyLoad]="true"></my-video-add-to-playlist> @defer (when dropdownOpened) {
<my-video-add-to-playlist #playlistAdd [video]="video"></my-video-add-to-playlist>
}
</div> </div>
</div> </div>
<my-action-dropdown <my-action-dropdown
[actions]="videoActions" [label]="label" [entry]="{ video: video }" (click)="loadDropdownInformation()" [actions]="videoActions" [label]="label" [entry]="{ video: video }"
[buttonSize]="buttonSize" [placement]="placement" [buttonDirection]="buttonDirection" [buttonStyled]="buttonStyled" [buttonSize]="buttonSize" [placement]="placement" [buttonDirection]="buttonDirection" [buttonStyled]="buttonStyled"
container="body" container="body" (openChange)="dropdownOpened = true"
></my-action-dropdown> ></my-action-dropdown>
<my-video-download #videoDownloadModal></my-video-download> <my-video-download #videoDownloadModal></my-video-download>

View File

@ -114,7 +114,8 @@ export class VideoActionsDropdownComponent implements OnChanges {
videoActions: DropdownAction<{ video: Video }>[][] = [] videoActions: DropdownAction<{ video: Video }>[][] = []
private loaded = false dropdownOpened = false
private hasMutedAccount = false private hasMutedAccount = false
constructor ( constructor (
@ -135,12 +136,7 @@ export class VideoActionsDropdownComponent implements OnChanges {
} }
ngOnChanges () { ngOnChanges () {
console.log('on changes') if (this.playlistAdd) this.playlistAdd.reload()
if (this.loaded) {
this.loaded = false
if (this.playlistAdd) this.playlistAdd.reload()
}
this.buildActions() this.buildActions()
} }
@ -149,14 +145,6 @@ export class VideoActionsDropdownComponent implements OnChanges {
return this.authService.isLoggedIn() return this.authService.isLoggedIn()
} }
loadDropdownInformation () {
if (this.loaded === true) return
this.loaded = true
if (this.displayOptions.playlist) this.playlistAdd.load()
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Show modals // Show modals
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -300,7 +300,10 @@ export class VideoMiniatureComponent implements OnInit {
} }
isWatchLaterPlaylistDisplayed () { isWatchLaterPlaylistDisplayed () {
return this.displayVideoActions && this.isUserLoggedIn() && this.inWatchLaterPlaylist !== undefined return !this.screenService.isInTouchScreen() &&
this.displayVideoActions &&
this.isUserLoggedIn() &&
this.inWatchLaterPlaylist !== undefined
} }
getClasses () { getClasses () {
@ -320,7 +323,7 @@ export class VideoMiniatureComponent implements OnInit {
} }
private loadWatchLater () { private loadWatchLater () {
if (!this.isUserLoggedIn() || this.inWatchLaterPlaylist !== undefined) return if (this.screenService.isInTouchScreen() || !this.displayVideoActions || !this.isUserLoggedIn()) return
this.authService.userInformationLoaded this.authService.userInformationLoaded
.pipe(switchMap(() => this.videoPlaylistService.listenToVideoPlaylistChange(this.video.id))) .pipe(switchMap(() => this.videoPlaylistService.listenToVideoPlaylistChange(this.video.id)))

View File

@ -70,6 +70,7 @@ my-timestamp-input {
margin: 0; margin: 0;
font-weight: $font-regular; font-weight: $font-regular;
cursor: pointer; cursor: pointer;
font-size: 1rem;
} }
.optional-row-icon { .optional-row-icon {

View File

@ -59,7 +59,6 @@ type PlaylistSummary = {
export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, OnChanges, OnDestroy, DisableForReuseHook { export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, OnChanges, OnDestroy, DisableForReuseHook {
@Input() video: Video @Input() video: Video
@Input() currentVideoTimestamp: number @Input() currentVideoTimestamp: number
@Input() lazyLoad = false
isNewPlaylistBlockOpened = false isNewPlaylistBlockOpened = false
@ -104,8 +103,6 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
this.videoPlaylistSearchChanged this.videoPlaylistSearchChanged
.pipe(debounceTime(500)) .pipe(debounceTime(500))
.subscribe(() => this.load()) .subscribe(() => this.load())
if (this.lazyLoad === false) this.load()
} }
ngOnChanges (simpleChanges: SimpleChanges) { ngOnChanges (simpleChanges: SimpleChanges) {
@ -150,12 +147,6 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
}) })
} }
openChange (opened: boolean) {
if (opened === false) {
this.isNewPlaylistBlockOpened = false
}
}
openCreateBlock (event: Event) { openCreateBlock (event: Event) {
event.preventDefault() event.preventDefault()