Fix search results on mobile
[oweals/peertube.git] / client / src / app / shared / video / video-actions-dropdown.component.ts
index 787ef118804f169f8576376091cb42fd99e64a26..7f3e25d0aace4eb58f035545e6d585ea0ea5cfd5 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
+import { AfterViewInit, Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { DropdownAction, DropdownButtonSize, DropdownDirection } from '@app/shared/buttons/action-dropdown.component'
 import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core'
@@ -29,12 +29,12 @@ export type VideoActionsDisplayType = {
   styleUrls: [ './video-actions-dropdown.component.scss' ]
 })
 export class VideoActionsDropdownComponent implements OnChanges {
-  @ViewChild('playlistDropdown') playlistDropdown: NgbDropdown
-  @ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent
+  @ViewChild('playlistDropdown', { static: false }) playlistDropdown: NgbDropdown
+  @ViewChild('playlistAdd', { static: false }) playlistAdd: VideoAddToPlaylistComponent
 
-  @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
-  @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
-  @ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent
+  @ViewChild('videoDownloadModal', { static: false }) videoDownloadModal: VideoDownloadComponent
+  @ViewChild('videoReportModal', { static: false }) videoReportModal: VideoReportComponent
+  @ViewChild('videoBlacklistModal', { static: false }) videoBlacklistModal: VideoBlacklistComponent
 
   @Input() video: Video | VideoDetails
 
@@ -79,6 +79,11 @@ export class VideoActionsDropdownComponent implements OnChanges {
   }
 
   ngOnChanges () {
+    if (this.loaded) {
+      this.loaded = false
+      this.playlistAdd.reload()
+    }
+
     this.buildActions()
   }
 
@@ -126,6 +131,10 @@ export class VideoActionsDropdownComponent implements OnChanges {
     return this.video.isUnblacklistableBy(this.user)
   }
 
+  isVideoDownloadable () {
+    return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled
+  }
+
   /* Action handlers */
 
   async unblacklistVideo () {
@@ -179,59 +188,55 @@ export class VideoActionsDropdownComponent implements OnChanges {
   }
 
   private buildActions () {
-    this.videoActions = []
-
-    if (this.authService.isLoggedIn()) {
-      this.videoActions.push([
+    this.videoActions = [
+      [
         {
           label: this.i18n('Save to playlist'),
           handler: () => this.playlistDropdown.toggle(),
-          isDisplayed: () => this.displayOptions.playlist,
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
           iconName: 'playlist-add'
         }
-      ])
-
-      this.videoActions.push([
+      ],
+      [
         {
           label: this.i18n('Download'),
           handler: () => this.showDownloadModal(),
-          isDisplayed: () => this.displayOptions.download,
+          isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
           iconName: 'download'
         },
         {
           label: this.i18n('Update'),
           linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
           iconName: 'edit',
-          isDisplayed: () => this.displayOptions.update && this.isVideoUpdatable()
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
         },
         {
           label: this.i18n('Blacklist'),
           handler: () => this.showBlacklistModal(),
           iconName: 'no',
-          isDisplayed: () => this.displayOptions.blacklist && this.isVideoBlacklistable()
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlacklistable()
         },
         {
           label: this.i18n('Unblacklist'),
           handler: () => this.unblacklistVideo(),
           iconName: 'undo',
-          isDisplayed: () => this.displayOptions.blacklist && this.isVideoUnblacklistable()
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblacklistable()
         },
         {
           label: this.i18n('Delete'),
           handler: () => this.removeVideo(),
-          isDisplayed: () => this.displayOptions.delete && this.isVideoRemovable(),
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
           iconName: 'delete'
         }
-      ])
-
-      this.videoActions.push([
+      ],
+      [
         {
           label: this.i18n('Report'),
           handler: () => this.showReportModal(),
-          isDisplayed: () => this.displayOptions.report,
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
           iconName: 'alert'
         }
-      ])
-    }
+      ]
+    ]
   }
 }