aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/header/suggestion.component.ts
blob: 75c44a5839037720154f43f90442636d5bb92914 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Input, Component, Output, EventEmitter, OnInit } from '@angular/core'
import { RouterLink } from '@angular/router'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { ListKeyManagerOption } from '@angular/cdk/a11y'

type Result = {
  text: string
  type: 'channel' | 'suggestion' | 'search-channel' | 'search-instance' | 'search-global' | 'search-any'
  routerLink?: RouterLink
}

@Component({
  selector: 'my-suggestion',
  templateUrl: './suggestion.component.html',
  styleUrls: [ './suggestion.component.scss' ]
})
export class SuggestionComponent implements OnInit, ListKeyManagerOption {
  @Input() result: Result
  @Input() highlight: string
  @Output() selected = new EventEmitter()

  inAllText: string
  inThisChannelText: string
  inThisInstanceText: string

  disabled = false
  active = false

  constructor (
    private i18n: I18n
  ) {
    this.inAllText = this.i18n('In the vidiverse')
    this.inThisChannelText = this.i18n('In this channel')
    this.inThisInstanceText = this.i18n('In this instance')
  }

  getLabel () {
    return this.result.text
  }

  ngOnInit () {
    this.active = false
  }

  selectItem () {
    this.selected.emit(this.result)
  }
}