Fixed "download all charts for each song" button

This commit is contained in:
Geomitron
2021-01-30 17:23:22 -05:00
parent 7af4af2771
commit 3078309d86
2 changed files with 5 additions and 5 deletions

View File

@@ -84,8 +84,8 @@ export class StatusBarComponent {
} }
downloadAllCharts() { downloadAllCharts() {
const chartGroups = groupBy(this.batchResults, 'chartID') const songChartGroups = groupBy(this.batchResults, 'songID', 'chartID')
for (const chart of chartGroups) { for (const chart of songChartGroups) {
this.searchService.sortChart(chart) this.searchService.sortChart(chart)
const downloadVersion = chart[0] const downloadVersion = chart[0]
const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID) const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID)

View File

@@ -35,12 +35,12 @@ export function interpolate(val: number, fromStart: number, fromEnd: number, toS
} }
/** /**
* @returns `objectList` split into multiple arrays, where each array contains the objects with matching `key` values. * @returns `objectList` split into multiple groups, where each group contains objects where every one of its values in `keys` matches.
*/ */
export function groupBy<T>(objectList: T[], key: keyof T) { export function groupBy<T>(objectList: T[], ...keys: (keyof T)[]) {
const results: T[][] = [] const results: T[][] = []
for (const object of objectList) { for (const object of objectList) {
const matchingGroup = results.find(result => result[0][key] == object[key]) const matchingGroup = results.find(result => keys.every(key => result[0][key] == object[key]))
if (matchingGroup != undefined) { if (matchingGroup != undefined) {
matchingGroup.push(object) matchingGroup.push(object)
} else { } else {