Refactor search service

This commit is contained in:
Geomitron
2020-03-11 22:51:24 -04:00
parent 3a3c2b5476
commit 18afa01e5c
9 changed files with 110 additions and 44 deletions

View File

@@ -1,24 +1,40 @@
import { Component, Input, Output, EventEmitter, ViewChildren, QueryList, ViewChild } from '@angular/core'
import { Component, Output, EventEmitter, ViewChildren, QueryList, ViewChild, OnInit } from '@angular/core'
import { SongResult } from '../../../../electron/shared/interfaces/search.interface'
import { ResultTableRowComponent } from './result-table-row/result-table-row.component'
import { CheckboxDirective } from 'src/app/core/directives/checkbox.directive'
import { SearchService } from 'src/app/core/services/search.service'
@Component({
selector: 'app-result-table',
templateUrl: './result-table.component.html',
styleUrls: ['./result-table.component.scss']
})
export class ResultTableComponent {
@Input() results: SongResult[]
export class ResultTableComponent implements OnInit {
@Output() rowClicked = new EventEmitter<SongResult>()
@Output() songChecked = new EventEmitter<SongResult>()
@Output() songUnchecked = new EventEmitter<SongResult>()
@ViewChild(CheckboxDirective, { static: true }) checkboxColumn: CheckboxDirective
@ViewChildren('tableRow') tableRows: QueryList<ResultTableRowComponent>
results: SongResult[]
constructor() { }
constructor(private searchService: SearchService) { }
ngOnInit() {
this.searchService.onNewSearch(() => {
this.checkboxColumn.check(false)
this.checkAll(false)
})
this.searchService.onSearchChanged(results => {
this.results = results
if (this.checkboxColumn.isChecked) {
this.checkAll(true)
}
})
}
onRowClicked(result: SongResult) {
this.rowClicked.emit(result)
@@ -39,8 +55,4 @@ export class ResultTableComponent {
onSongsDeselected(songs: SongResult['id'][]) {
this.tableRows.forEach(row => row.check(!songs.includes(row.songID)))
}
onNewSearch() {
this.checkboxColumn.check(false)
}
}