</div>
<!-- search instructions, when search input is empty -->
- <div *ngIf="showInstructions" id="typeahead-instructions" class="overflow-hidden">
+ <div *ngIf="areInstructionsDisplayed" id="typeahead-instructions" class="overflow-hidden">
<div class="d-flex justify-content-between">
<label class="small-title" i18n>Advanced search</label>
<div class="advanced-search-status c-help">
- <span [ngClass]="anyURI ? 'text-success' : 'text-muted'" i18n-title title="Determines whether you can resolve any distant content, or if this instance only allows doing so for instances it follows.">
- <span *ngIf="anyURI" class="mr-1" i18n>any instance</span>
- <span *ngIf="!anyURI" class="mr-1" i18n>only followed instances</span>
- <i [ngClass]="anyURI ? 'glyphicon glyphicon-ok-sign' : 'glyphicon glyphicon-exclamation-sign'"></i>
+ <span [ngClass]="canSearchAnyURI ? 'text-success' : 'text-muted'" i18n-title title="Determines whether you can resolve any distant content, or if this instance only allows doing so for instances it follows.">
+ <span *ngIf="canSearchAnyURI" class="mr-1" i18n>any instance</span>
+ <span *ngIf="!canSearchAnyURI" class="mr-1" i18n>only followed instances</span>
+ <i [ngClass]="canSearchAnyURI ? 'glyphicon glyphicon-ok-sign' : 'glyphicon glyphicon-exclamation-sign'"></i>
</span>
</div>
</div>
import {
Component,
- AfterViewInit,
OnInit,
OnDestroy,
QueryList,
import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes'
import { SuggestionComponent, Result } from './suggestion.component'
import { of } from 'rxjs'
-import { getParameterByName } from '@app/shared/misc/utils'
import { ServerConfig } from '@shared/models'
@Component({
templateUrl: './search-typeahead.component.html',
styleUrls: [ './search-typeahead.component.scss' ]
})
-export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewInit {
+export class SearchTypeaheadComponent implements OnInit, OnDestroy {
@ViewChild('searchVideo', { static: true }) searchInput: ElementRef<HTMLInputElement>
hasChannel = false
inThisChannelText: string
keyboardEventsManager: ListKeyManager<SuggestionComponent>
- results: any[] = []
+ results: Result[] = []
constructor (
private authService: AuthService,
) {}
ngOnInit () {
+ const query = this.route.snapshot.queryParams
+ if (query['search']) this.search = query['search']
+
this.serverService.getConfig()
.subscribe(config => this.serverConfig = config)
}
if (this.keyboardEventsManager) this.keyboardEventsManager.change.unsubscribe()
}
- ngAfterViewInit () {
- this.search = getParameterByName('search', window.location.href) || ''
- }
-
get activeResult () {
- return this.keyboardEventsManager && this.keyboardEventsManager.activeItem && this.keyboardEventsManager.activeItem.result
+ return this.keyboardEventsManager?.activeItem?.result
}
- get showInstructions () {
+ get areInstructionsDisplayed () {
return !this.search
}
get showHelp () {
- return this.search && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false
+ return this.search && this.newSearch && this.activeResult?.type === 'search-global'
}
- get anyURI () {
+ get canSearchAnyURI () {
if (!this.serverConfig) return false
return this.authService.isLoggedIn()
? this.serverConfig.search.remoteUri.users
initKeyboardEventsManager (event: { items: QueryList<SuggestionComponent>, index?: number }) {
if (this.keyboardEventsManager) this.keyboardEventsManager.change.unsubscribe()
+
this.keyboardEventsManager = new ListKeyManager(event.items)
+
if (event.index !== undefined) {
this.keyboardEventsManager.setActiveItem(event.index)
} else {
this.keyboardEventsManager.setFirstItemActive()
}
+
this.keyboardEventsManager.change.subscribe(
_ => this.setEventItems(event)
)
}
- handleKeyUp (event: KeyboardEvent, indexSelected?: number) {
+ handleKeyUp (event: KeyboardEvent) {
event.stopImmediatePropagation()
- if (this.keyboardEventsManager) {
- if (event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW) {
+ if (!this.keyboardEventsManager) return
+
+ switch (event.key) {
+ case "ArrowDown":
+ case "ArrowUp":
this.keyboardEventsManager.onKeydown(event)
- return false
- } else if (event.keyCode === ENTER) {
+ break
+ case "Enter":
this.newSearch = false
this.doSearch()
- return false
- }
+ break
}
}