ee3ef73c2c8f617e37c662b2a41f7b053571ff29
[oweals/peertube.git] / client / src / app / header / suggestions.component.ts
1 import { Input, QueryList, Component, Output, AfterViewInit, EventEmitter, ViewChildren, ChangeDetectionStrategy } from '@angular/core'
2 import { SuggestionComponent } from './suggestion.component'
3
4 @Component({
5   selector: 'my-suggestions',
6   templateUrl: './suggestions.component.html',
7   changeDetection: ChangeDetectionStrategy.OnPush
8 })
9 export class SuggestionsComponent implements AfterViewInit {
10   @Input() results: any[]
11   @Input() highlight: string
12   @ViewChildren(SuggestionComponent) listItems: QueryList<SuggestionComponent>
13   @Output() init = new EventEmitter()
14
15   ngAfterViewInit () {
16     this.listItems.changes.subscribe(
17       _ => this.init.emit({ items: this.listItems })
18     )
19   }
20
21   hoverItem (index: number) {
22     this.init.emit({ items: this.listItems, index: index })
23   }
24 }