mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
Simplified onScroll event listener
This commit is contained in:
@@ -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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user