]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+search/search.component.ts
Non latin keyboard layout support player shortcut (#5684)
[github/Chocobozzz/PeerTube.git] / client / src / app / +search / search.component.ts
index 81d1006f8ea0840788cbe167e8f05728182ca9dc..31394a1d14cb366dcd88b86cfe292e7be35cdff6 100644 (file)
@@ -1,4 +1,4 @@
-import { forkJoin, Subscription } from 'rxjs'
+import { forkJoin, Subject, Subscription } from 'rxjs'
 import { LinkType } from 'src/types/link.type'
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
@@ -44,13 +44,11 @@ export class SearchComponent implements OnInit, OnDestroy {
 
   userMiniature: User
 
+  onSearchDataSubject = new Subject<any>()
+
   private subActivatedRoute: Subscription
   private isInitialLoad = false // set to false to show the search filters on first arrival
 
-  private channelsPerPage = 2
-  private playlistsPerPage = 2
-  private videosPerPage = 10
-
   private hasMoreResults = true
   private isSearching = false
 
@@ -75,7 +73,7 @@ export class SearchComponent implements OnInit, OnDestroy {
 
     this.subActivatedRoute = this.route.queryParams
       .subscribe({
-        next: async queryParams => {
+        next: queryParams => {
           const querySearch = queryParams['search']
           const searchTarget = queryParams['searchTarget']
 
@@ -102,7 +100,7 @@ export class SearchComponent implements OnInit, OnDestroy {
           this.search()
         },
 
-        error: err => this.notifier.error(err.text)
+        error: err => this.notifier.error(err.message)
       })
 
     this.userService.getAnonymousOrLoggedUser()
@@ -151,6 +149,8 @@ export class SearchComponent implements OnInit, OnDestroy {
         this.lastSearchTarget = this.advancedSearch.searchTarget
 
         this.hasMoreResults = this.results.length < this.pagination.totalItems
+
+        this.onSearchDataSubject.next(results)
       },
 
       error: err => {
@@ -247,17 +247,16 @@ export class SearchComponent implements OnInit, OnDestroy {
   private resetPagination () {
     this.pagination.currentPage = 1
     this.pagination.totalItems = null
-    this.channelsPerPage = 2
 
     this.results = []
   }
 
   private updateTitle () {
-    const suffix = this.currentSearch
-      ? ' ' + this.currentSearch
-      : ''
+    const title = this.currentSearch
+      ? $localize`Search ${this.currentSearch}`
+      : $localize`Search`
 
-    this.metaService.setTitle($localize`Search` + suffix)
+    this.metaService.setTitle(title)
   }
 
   private updateUrlFromAdvancedSearch () {
@@ -272,7 +271,7 @@ export class SearchComponent implements OnInit, OnDestroy {
   private getVideosObs () {
     const params = {
       search: this.currentSearch,
-      componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.videosPerPage }),
+      componentPagination: immutableAssign(this.pagination, { itemsPerPage: 10 }),
       advancedSearch: this.advancedSearch
     }
 
@@ -288,7 +287,7 @@ export class SearchComponent implements OnInit, OnDestroy {
   private getVideoChannelObs () {
     const params = {
       search: this.currentSearch,
-      componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }),
+      componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.buildChannelsPerPage() }),
       advancedSearch: this.advancedSearch
     }
 
@@ -304,7 +303,7 @@ export class SearchComponent implements OnInit, OnDestroy {
   private getVideoPlaylistObs () {
     const params = {
       search: this.currentSearch,
-      componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.playlistsPerPage }),
+      componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.buildPlaylistsPerPage() }),
       advancedSearch: this.advancedSearch
     }
 
@@ -334,4 +333,16 @@ export class SearchComponent implements OnInit, OnDestroy {
 
     return undefined
   }
+
+  private buildChannelsPerPage () {
+    if (this.advancedSearch.resultType === 'channels') return 10
+
+    return 2
+  }
+
+  private buildPlaylistsPerPage () {
+    if (this.advancedSearch.resultType === 'playlists') return 10
+
+    return 2
+  }
 }