From a64ec345895f1d1e2cd4918a7ac492ad0ea675f0 Mon Sep 17 00:00:00 2001 From: Geomitron <22552797+Geomitron@users.noreply.github.com> Date: Thu, 12 Mar 2020 00:12:13 -0400 Subject: [PATCH] Simplified onScroll event listener --- src/app/components/browse/browse.component.ts | 16 ++++------- src/app/core/services/search.service.ts | 28 +++++++++---------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/app/components/browse/browse.component.ts b/src/app/components/browse/browse.component.ts index bbb0762..9965b01 100644 --- a/src/app/components/browse/browse.component.ts +++ b/src/app/components/browse/browse.component.ts @@ -19,17 +19,11 @@ export class BrowseComponent implements AfterViewInit { ngAfterViewInit() { const $tableColumn = $('#table-column') - $tableColumn.visibility({ - once: false, - continuous: true, - context: $tableColumn, - observeChanges: true, - onUpdate: () => { - let pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight - let max = $tableColumn[0].scrollHeight - if (pos >= max - 5) { - this.searchService.updateScroll() - } + $tableColumn.on('scroll', () => { + let pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight + let max = $tableColumn[0].scrollHeight + if (pos >= max - 5) { + this.searchService.updateScroll() } }) } diff --git a/src/app/core/services/search.service.ts b/src/app/core/services/search.service.ts index 8f542e4..cfffc1b 100644 --- a/src/app/core/services/search.service.ts +++ b/src/app/core/services/search.service.ts @@ -19,13 +19,7 @@ export class SearchService { async newSearch(query: string) { this.awaitingResults = true this.currentQuery = { query, type: SearchType.Any, offset: 0, length: 20 + 1 } // TODO: make length a setting - this.results = await this.electronService.invoke('song-search', this.currentQuery) - if (this.results.length > 20) { - this.results.splice(20, 1) - this.allResultsVisible = false - } else { - this.allResultsVisible = true - } + this.results = this.trimLastChart(await this.electronService.invoke('song-search', this.currentQuery)) this.awaitingResults = false this.newResultsEmitter.emit(this.results) @@ -48,17 +42,21 @@ export class SearchService { if (!this.awaitingResults && !this.allResultsVisible) { this.awaitingResults = true this.currentQuery.offset += 20 - const newResults = await this.electronService.invoke('song-search', this.currentQuery) - if (newResults.length > 20) { - newResults.splice(20, 1) - this.allResultsVisible = false - } else { - this.allResultsVisible = true - } - this.results.push(...newResults) + this.results.push(...this.trimLastChart(await this.electronService.invoke('song-search', this.currentQuery))) this.awaitingResults = false this.resultsChangedEmitter.emit(this.results) } } + + trimLastChart(results: SongResult[]) { + if (results.length > 20) { + results.splice(20, 1) + this.allResultsVisible = false + } else { + this.allResultsVisible = true + } + + return results + } }