mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-09 05:09:39 +00:00
Allowed search to recover after a connection failure
This commit is contained in:
@@ -17,8 +17,8 @@ export class SearchBarComponent implements AfterViewInit {
|
||||
$('#searchIcon').popup({
|
||||
onShow: () => this.isError // Only show the popup if there is an error
|
||||
})
|
||||
this.searchService.onSearchError(() => {
|
||||
this.isError = true
|
||||
this.searchService.onSearchErrorStateUpdate((isError) => {
|
||||
this.isError = isError
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export class SearchService {
|
||||
|
||||
private resultsChangedEmitter = new EventEmitter<SongResult[]>() // For when any results change
|
||||
private newResultsEmitter = new EventEmitter<SongResult[]>() // For when a new search happens
|
||||
private errorStateEmitter = new EventEmitter<boolean>() // To indicate the search's error state
|
||||
private results: SongResult[] = []
|
||||
private awaitingResults = false
|
||||
private currentQuery: SongSearch
|
||||
@@ -23,9 +24,11 @@ export class SearchService {
|
||||
this.currentQuery = { query, type: SearchType.Any, offset: 0, length: 50 + 1 } // TODO: make length a setting
|
||||
try {
|
||||
this.results = this.trimLastChart(await this.electronService.invoke('song-search', this.currentQuery))
|
||||
this.errorStateEmitter.emit(false)
|
||||
} catch (err) {
|
||||
this.results = []
|
||||
this.resultsChangedEmitter.error(undefined)
|
||||
console.log(err.message)
|
||||
this.errorStateEmitter.emit(true)
|
||||
}
|
||||
this.awaitingResults = false
|
||||
|
||||
@@ -55,11 +58,11 @@ export class SearchService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Event emitted when a search fails.
|
||||
* Event emitted when the error state of the search changes.
|
||||
* (emitted before `onSearchChanged`)
|
||||
*/
|
||||
onSearchError(callback: () => void) {
|
||||
this.resultsChangedEmitter.subscribe(() => { /** Do nothing */ }, callback)
|
||||
onSearchErrorStateUpdate(callback: (isError: boolean) => void) {
|
||||
this.errorStateEmitter.subscribe(callback)
|
||||
}
|
||||
|
||||
get resultCount() {
|
||||
|
||||
@@ -21,7 +21,7 @@ class SearchHandler implements IPCInvokeHandler<'song-search'> {
|
||||
offset: search.offset
|
||||
}, (err, response) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
reject(err.message)
|
||||
} else {
|
||||
resolve(response.body)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user