]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
video add to playlist component -> onpush strategy
authorChocobozzz <me@florianbigard.com>
Fri, 5 Apr 2019 12:16:48 +0000 (14:16 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 5 Apr 2019 12:16:48 +0000 (14:16 +0200)
client/src/app/shared/forms/peertube-checkbox.component.scss
client/src/app/shared/forms/peertube-checkbox.component.ts
client/src/app/shared/misc/screen.service.ts
client/src/app/shared/video-playlist/video-add-to-playlist.component.html
client/src/app/shared/video-playlist/video-add-to-playlist.component.scss
client/src/app/shared/video-playlist/video-add-to-playlist.component.ts
client/src/app/shared/video/modals/video-download.component.html
client/src/app/shared/video/modals/video-download.component.ts
client/src/app/shared/video/video-actions-dropdown.component.ts
client/src/app/shared/video/video-miniature.component.scss
client/src/app/shared/video/video-miniature.component.ts

index 6e4e207751fe713b2c5fc89f6c59a91e4cc25f5c..ea321ee6581c4d2f29e3d272f0c335172eeddaf0 100644 (file)
@@ -28,4 +28,4 @@
     position: relative;
     top: -2px;
   }
-}
\ No newline at end of file
+}
index c1a6915e8613c901ef780a237411d1cb46c4604e..9578f56186a1df4b3d96d6cae9c650da8d57043d 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, forwardRef, Input } from '@angular/core'
+import { ChangeDetectorRef, Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core'
 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
 
 @Component({
@@ -21,10 +21,19 @@ export class PeertubeCheckboxComponent implements ControlValueAccessor {
   @Input() helpHtml: string
   @Input() disabled = false
 
+  // FIXME: https://github.com/angular/angular/issues/10816#issuecomment-307567836
+  @Input() onPushWorkaround = false
+
+  constructor (private cdr: ChangeDetectorRef) { }
+
   propagateChange = (_: any) => { /* empty */ }
 
   writeValue (checked: boolean) {
     this.checked = checked
+
+    if (this.onPushWorkaround) {
+      this.cdr.markForCheck()
+    }
   }
 
   registerOnChange (fn: (_: any) => void) {
index db481204e5ced7d75e971ae7821c9c62bd8f0ade..af75569d9bd66fb61b82cd070d4c30300cfbf1ce 100644 (file)
@@ -18,6 +18,10 @@ export class ScreenService {
     return this.getWindowInnerWidth() < 500
   }
 
+  isInTouchScreen () {
+    return 'ontouchstart' in window || navigator.msMaxTouchPoints
+  }
+
   // Cache window inner width, because it's an expensive call
   private getWindowInnerWidth () {
     if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
index 6029b364850208b361638e64f7d4481d54ae2969..648d580fa3067e34e007b8068243cded8f7a7f0f 100644 (file)
@@ -42,7 +42,7 @@
   </div>
 
   <div class="playlist dropdown-item" *ngFor="let playlist of videoPlaylists" (click)="togglePlaylist($event, playlist)">
-    <my-peertube-checkbox [inputName]="'in-playlist-' + playlist.id" [(ngModel)]="playlist.inPlaylist"></my-peertube-checkbox>
+    <my-peertube-checkbox [inputName]="'in-playlist-' + playlist.id" [(ngModel)]="playlist.inPlaylist" [onPushWorkaround]="true"></my-peertube-checkbox>
 
     <div class="display-name">
       {{ playlist.displayName }}
@@ -56,7 +56,7 @@
   <div class="new-playlist-button dropdown-item" (click)="openCreateBlock($event)" [hidden]="isNewPlaylistBlockOpened">
     <my-global-icon iconName="add"></my-global-icon>
 
-    Create a new playlist
+    Create a private playlist
   </div>
 
   <form class="new-playlist-block dropdown-item" *ngIf="isNewPlaylistBlockOpened" (ngSubmit)="createPlaylist()" [formGroup]="form">
index 0424e2ee9814edcf88b3627e07963d4910be518a..c677fea6ce9828e6d848fccb9f2bc7cfcd2e7da7 100644 (file)
@@ -40,6 +40,7 @@
 
   .options-row {
     margin-top: 10px;
+    padding-left: 10px;
 
     > div {
       display: flex;
index 152f20c856014e3754ce333020daded6ef84d5bb..7dcdf7a9eb44e1325626424daaa35d46ba53c412 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, Input, OnInit } from '@angular/core'
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'
 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
 import { AuthService, Notifier } from '@app/core'
 import { forkJoin } from 'rxjs'
@@ -19,7 +19,8 @@ type PlaylistSummary = {
 @Component({
   selector: 'my-video-add-to-playlist',
   styleUrls: [ './video-add-to-playlist.component.scss' ],
-  templateUrl: './video-add-to-playlist.component.html'
+  templateUrl: './video-add-to-playlist.component.html',
+  changeDetection: ChangeDetectionStrategy.OnPush
 })
 export class VideoAddToPlaylistComponent extends FormReactive implements OnInit {
   @Input() video: Video
@@ -42,7 +43,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
     private notifier: Notifier,
     private i18n: I18n,
     private videoPlaylistService: VideoPlaylistService,
-    private videoPlaylistValidatorsService: VideoPlaylistValidatorsService
+    private videoPlaylistValidatorsService: VideoPlaylistValidatorsService,
+    private cd: ChangeDetectorRef
   ) {
     super()
   }
@@ -79,6 +81,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
               stopTimestamp: existingPlaylist ? existingPlaylist.stopTimestamp : undefined
             })
           }
+
+          this.cd.markForCheck()
         }
       )
   }
@@ -107,6 +111,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
 
     playlist.inPlaylist = !playlist.inPlaylist
     this.resetOptions()
+
+    this.cd.markForCheck()
   }
 
   createPlaylist () {
@@ -126,6 +132,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
         })
 
         this.isNewPlaylistBlockOpened = false
+
+        this.cd.markForCheck()
       },
 
       err => this.notifier.error(err.message)
@@ -165,7 +173,9 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
             this.notifier.error(err.message)
 
             playlist.inPlaylist = true
-          }
+          },
+
+          () => this.cd.markForCheck()
         )
   }
 
@@ -194,7 +204,9 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
           this.notifier.error(err.message)
 
           playlist.inPlaylist = false
-        }
+        },
+
+        () => this.cd.markForCheck()
       )
   }
 }
index 2bb5d6d378f308c23e72d5dadb96cdc6e99cdd24..dd01c13886911e85a15611040a52d2d4fa6b749c 100644 (file)
@@ -9,7 +9,7 @@
       <div class="input-group input-group-sm">
         <div class="input-group-prepend peertube-select-container">
           <select [(ngModel)]="resolutionId">
-            <option *ngFor="let file of video.files" [value]="file.resolution.id">{{ file.resolution.label }}</option>
+            <option *ngFor="let file of video?.files" [value]="file.resolution.id">{{ file.resolution.label }}</option>
           </select>
         </div>
         <input #urlInput (click)="urlInput.select()" type="text" class="form-control input-sm readonly" readonly [value]="getLink()" />
index 64aaeb3c86ffa26e4d3c435ac17e2a38625ca7b3..d6d10d29ed86b7d5f7303957fdc6e9894fd7d628 100644 (file)
@@ -15,7 +15,7 @@ export class VideoDownloadComponent {
   downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
   resolutionId: number | string = -1
 
-  private video: VideoDetails
+  video: VideoDetails
 
   constructor (
     private notifier: Notifier,
index 90bdf7df8f0b271aa97eee4ca507acbe577bbbfb..787ef118804f169f8576376091cb42fd99e64a26 100644 (file)
@@ -46,7 +46,7 @@ export class VideoActionsDropdownComponent implements OnChanges {
     delete: true,
     report: true
   }
-  @Input() placement: string = 'left'
+  @Input() placement = 'left'
 
   @Input() label: string
 
index 0d4e59c2a372552de8419cf8af6a41ec33b14e92..fa2739f005d26d280a3e60f96087ba7dbdb58037 100644 (file)
@@ -99,6 +99,7 @@
 
     .video-miniature-information {
       width: auto;
+      min-width: 500px;
 
       .video-miniature-name {
         @include ellipsis-multiline(1.3em, 2);
       .video-miniature-account,
       .video-miniature-channel {
         font-size: 14px;
+        width: fit-content;
       }
 
       .video-info-privacy {
       my-video-thumbnail {
         margin-right: 0;
       }
+
+      .video-miniature-information {
+        min-width: initial;
+      }
     }
   }
 }
index e3552abbaf4caa8297214b575e90f3ed62c2a1d1..e32b8cbc585011d0581e7f5c11b5c543c34fa183 100644 (file)
@@ -72,7 +72,8 @@ export class VideoMiniatureComponent implements OnInit {
   ngOnInit () {
     this.setUpBy()
 
-    if (this.screenService.isInSmallView()) {
+    // We rely on mouseenter to lazy load actions
+    if (this.screenService.isInTouchScreen()) {
       this.showActions = true
     }
   }