]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/header/search-typeahead.component.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / header / search-typeahead.component.ts
index c546628ee66fb52b820fad529aed4de46fe4dd76..d2549315cd4f9db83cea26c84d9bca20c7844043 100644 (file)
@@ -1,10 +1,11 @@
 import { of } from 'rxjs'
 import { first, tap } from 'rxjs/operators'
 import { ListKeyManager } from '@angular/cdk/a11y'
-import { AfterViewChecked, AfterViewInit, Component, OnDestroy, OnInit, QueryList, ViewChildren } from '@angular/core'
+import { AfterViewChecked, Component, OnDestroy, OnInit, QueryList, ViewChildren } from '@angular/core'
 import { ActivatedRoute, Params, Router } from '@angular/router'
 import { AuthService, ServerService } from '@app/core'
-import { SearchTargetType, ServerConfig } from '@shared/models'
+import { logger } from '@root-helpers/logger'
+import { HTMLServerConfig, SearchTargetType } from '@shared/models'
 import { SuggestionComponent, SuggestionPayload, SuggestionPayloadType } from './suggestion.component'
 
 @Component({
@@ -12,7 +13,7 @@ import { SuggestionComponent, SuggestionPayload, SuggestionPayloadType } from '.
   templateUrl: './search-typeahead.component.html',
   styleUrls: [ './search-typeahead.component.scss' ]
 })
-export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterViewChecked, OnDestroy {
+export class SearchTypeaheadComponent implements OnInit, AfterViewChecked, OnDestroy {
   @ViewChildren(SuggestionComponent) suggestionItems: QueryList<SuggestionComponent>
 
   hasChannel = false
@@ -20,7 +21,7 @@ export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterVie
   areSuggestionsOpened = true
 
   search = ''
-  serverConfig: ServerConfig
+  serverConfig: HTMLServerConfig
 
   inThisChannelText: string
 
@@ -42,20 +43,14 @@ export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterVie
     this.route.queryParams
       .pipe(first(params => this.isOnSearch() && params.search !== undefined && params.search !== null))
       .subscribe(params => this.search = params.search)
-  }
 
-  ngAfterViewInit () {
-    this.serverService.getConfig()
+    this.serverConfig = this.serverService.getHTMLConfig()
+    this.computeTypeahead()
+
+    this.serverService.configReloaded
       .subscribe(config => {
         this.serverConfig = config
-
         this.computeTypeahead()
-
-        this.serverService.configReloaded
-          .subscribe(config => {
-            this.serverConfig = config
-            this.computeTypeahead()
-          })
       })
   }
 
@@ -97,7 +92,7 @@ export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterVie
 
     const activeIndex = this.suggestionItems.toArray().findIndex(i => i.result.default === true)
     if (activeIndex === -1) {
-      console.error('Cannot find active index.', { suggestionItems: this.suggestionItems })
+      logger.error('Cannot find active index.', { suggestionItems: this.suggestionItems })
     }
 
     this.updateItemsState(activeIndex)
@@ -158,7 +153,7 @@ export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterVie
     }
   }
 
-  onSuggestionlicked (payload: SuggestionPayload) {
+  onSuggestionClicked (payload: SuggestionPayload) {
     this.doSearch(this.buildSearchTarget(payload))
   }
 
@@ -176,6 +171,11 @@ export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterVie
 
         this.keyboardEventsManager.onKeydown(event)
         break
+
+      case 'Enter':
+        event.stopPropagation()
+        this.doSearch()
+        break
     }
   }
 
@@ -205,7 +205,7 @@ export class SearchTypeaheadComponent implements OnInit, AfterViewInit, AfterVie
   }
 
   private loadUserLanguagesIfNeeded (queryParams: any) {
-    if (queryParams && queryParams.languageOneOf) return of(queryParams)
+    if (queryParams?.languageOneOf) return of(queryParams)
 
     return this.authService.userInformationLoaded
                .pipe(