Simplified onScroll event listener

This commit is contained in:
Geomitron
2020-03-12 00:12:13 -04:00
parent f055097df9
commit a64ec34589
2 changed files with 18 additions and 26 deletions

View File

@@ -19,17 +19,11 @@ export class BrowseComponent implements AfterViewInit {
ngAfterViewInit() { ngAfterViewInit() {
const $tableColumn = $('#table-column') const $tableColumn = $('#table-column')
$tableColumn.visibility({ $tableColumn.on('scroll', () => {
once: false, let pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight
continuous: true, let max = $tableColumn[0].scrollHeight
context: $tableColumn, if (pos >= max - 5) {
observeChanges: true, this.searchService.updateScroll()
onUpdate: () => {
let pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight
let max = $tableColumn[0].scrollHeight
if (pos >= max - 5) {
this.searchService.updateScroll()
}
} }
}) })
} }

View File

@@ -19,13 +19,7 @@ export class SearchService {
async newSearch(query: string) { async newSearch(query: string) {
this.awaitingResults = true this.awaitingResults = true
this.currentQuery = { query, type: SearchType.Any, offset: 0, length: 20 + 1 } // TODO: make length a setting 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) this.results = this.trimLastChart(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.awaitingResults = false this.awaitingResults = false
this.newResultsEmitter.emit(this.results) this.newResultsEmitter.emit(this.results)
@@ -48,17 +42,21 @@ export class SearchService {
if (!this.awaitingResults && !this.allResultsVisible) { if (!this.awaitingResults && !this.allResultsVisible) {
this.awaitingResults = true this.awaitingResults = true
this.currentQuery.offset += 20 this.currentQuery.offset += 20
const newResults = await this.electronService.invoke('song-search', this.currentQuery) this.results.push(...this.trimLastChart(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.awaitingResults = false this.awaitingResults = false
this.resultsChangedEmitter.emit(this.results) 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
}
} }