Gracefully downsize search bar for mobile devices
[oweals/peertube.git] / client / src / app / header / suggestion.component.ts
1 import { Input, Component, Output, EventEmitter, OnInit } from '@angular/core'
2 import { RouterLink } from '@angular/router'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { ListKeyManagerOption } from '@angular/cdk/a11y'
5
6 export type Result = {
7   text: string
8   type: 'channel' | 'suggestion' | 'search-channel' | 'search-instance' | 'search-global' | 'search-any'
9   routerLink?: RouterLink,
10   default?: boolean
11 }
12
13 @Component({
14   selector: 'my-suggestion',
15   templateUrl: './suggestion.component.html',
16   styleUrls: [ './suggestion.component.scss' ]
17 })
18 export class SuggestionComponent implements OnInit, ListKeyManagerOption {
19   @Input() result: Result
20   @Input() highlight: string
21   @Output() selected = new EventEmitter()
22
23   inAllText: string
24   inThisChannelText: string
25   inThisInstanceText: string
26
27   disabled = false
28   active = false
29
30   constructor (
31     private i18n: I18n
32   ) {
33     this.inAllText = this.i18n('In the vidiverse')
34     this.inThisChannelText = this.i18n('In this channel')
35     this.inThisInstanceText = this.i18n('In this instance')
36   }
37
38   getLabel () {
39     return this.result.text
40   }
41
42   ngOnInit () {
43     if (this.result.default) this.active = true
44   }
45
46   selectItem () {
47     this.selected.emit(this.result)
48   }
49 }