mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
Fix checkboxes and bulk download
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { EventEmitter, Injectable, NgZone } from '@angular/core'
|
||||
|
||||
import { assign } from 'lodash'
|
||||
import { ChartData } from 'src-shared/interfaces/search.interface'
|
||||
import { removeStyleTags } from 'src-shared/UtilFunctions'
|
||||
|
||||
import { DownloadProgress } from '../../../../src-shared/interfaces/download.interface'
|
||||
|
||||
@@ -16,7 +18,7 @@ export class DownloadService {
|
||||
window.electron.on.downloadQueueUpdate(download => zone.run(() => {
|
||||
const downloadIndex = this.downloads.findIndex(d => d.md5 === download.md5)
|
||||
if (download.type === 'cancel') {
|
||||
this.downloads = this.downloads.filter(d => d.md5 !== this.downloads[downloadIndex].md5)
|
||||
this.downloads = this.downloads.filter(d => d.md5 !== this.downloads[downloadIndex]?.md5)
|
||||
} else if (downloadIndex === -1) {
|
||||
this.downloads.push(download)
|
||||
} else {
|
||||
@@ -50,13 +52,16 @@ export class DownloadService {
|
||||
return this.downloads.find(download => download.type === 'error') ? true : false
|
||||
}
|
||||
|
||||
addDownload(md5: string, chartName: string) {
|
||||
if (!this.downloads.find(d => d.md5 === md5)) { // Don't download something twice
|
||||
addDownload(chart: ChartData) {
|
||||
if (!this.downloads.find(d => d.md5 === chart.md5)) { // Don't download something twice
|
||||
if (this.downloads.every(d => d.type === 'done')) { // Reset overall progress bar if it finished
|
||||
this.downloads.forEach(d => d.stale = true)
|
||||
}
|
||||
const chartName = `${removeStyleTags(chart.artist ?? 'Unknown Artist')
|
||||
} - ${removeStyleTags(chart.name ?? 'Unknown Name')
|
||||
} (${removeStyleTags(chart.charter ?? 'Unknown Charter')})`
|
||||
this.downloads.push({
|
||||
md5,
|
||||
md5: chart.md5,
|
||||
chartName,
|
||||
header: 'Waiting for other downloads to finish...',
|
||||
body: '',
|
||||
@@ -64,7 +69,7 @@ export class DownloadService {
|
||||
type: 'good',
|
||||
isPath: false,
|
||||
})
|
||||
window.electron.emit.download({ action: 'add', md5, chartName })
|
||||
window.electron.emit.download({ action: 'add', md5: chart.md5, chartName })
|
||||
}
|
||||
this.downloadCountChanges.emit(this.downloadCount)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ export class SearchService {
|
||||
public searchLoading = false
|
||||
public songsResponse: Partial<SearchResult>
|
||||
public currentPage = 1
|
||||
public searchUpdated = new EventEmitter<Partial<SearchResult>>()
|
||||
public newSearch = new EventEmitter<Partial<SearchResult>>()
|
||||
public updateSearch = new EventEmitter<Partial<SearchResult>>()
|
||||
public isDefaultSearch = true
|
||||
|
||||
public groupedSongs: ChartData[][]
|
||||
@@ -115,7 +116,11 @@ export class SearchService {
|
||||
.value()
|
||||
)
|
||||
|
||||
this.searchUpdated.emit(response)
|
||||
if (nextPage) {
|
||||
this.updateSearch.emit(response)
|
||||
} else {
|
||||
this.newSearch.emit(response)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -154,7 +159,7 @@ export class SearchService {
|
||||
.value()
|
||||
)
|
||||
|
||||
this.searchUpdated.emit(response)
|
||||
this.newSearch.emit(response)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,34 +2,29 @@ import { EventEmitter, Injectable } from '@angular/core'
|
||||
|
||||
import { SearchService } from './search.service'
|
||||
|
||||
// Note: this class prevents event cycles by only emitting events if the checkbox changes
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SelectionService {
|
||||
|
||||
private allSelected = false
|
||||
private selectAllChangedEmitter = new EventEmitter<boolean>()
|
||||
|
||||
public selections: { [groupId: number]: boolean | undefined } = {}
|
||||
|
||||
constructor(searchService: SearchService) {
|
||||
searchService.searchUpdated.subscribe(() => {
|
||||
searchService.newSearch.subscribe(() => {
|
||||
this.selections = {}
|
||||
this.deselectAll()
|
||||
})
|
||||
}
|
||||
|
||||
getSelectedResults() {
|
||||
// TODO
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return [] as any[] // this.searchResults.filter(result => this.selections[result.id] === true)
|
||||
}
|
||||
|
||||
onSelectAllChanged(callback: (selected: boolean) => void) {
|
||||
this.selectAllChangedEmitter.subscribe(callback)
|
||||
isAllSelected() {
|
||||
return this.allSelected
|
||||
}
|
||||
|
||||
deselectAll() {
|
||||
this.allSelected = false
|
||||
for (const groupId in this.selections) {
|
||||
this.selections[groupId] = false
|
||||
}
|
||||
@@ -37,6 +32,7 @@ export class SelectionService {
|
||||
}
|
||||
|
||||
selectAll() {
|
||||
this.allSelected = true
|
||||
for (const groupId in this.selections) {
|
||||
this.selections[groupId] = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user