Fix JS pass by copy/reference issue.

This commit is contained in:
Bauke 2022-10-25 12:55:07 +02:00
parent e591db7bcf
commit f6571b895b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 6 additions and 5 deletions

View File

@ -69,21 +69,22 @@ export class Settings {
} }
const previousIndex = targetItem.sortIndex; const previousIndex = targetItem.sortIndex;
let targetIndex = previousIndex;
if (direction === 'down') { if (direction === 'down') {
targetItem.sortIndex += 1; targetIndex += 1;
} else if (direction === 'up') { } else if (direction === 'up') {
targetItem.sortIndex -= 1; targetIndex -= 1;
} }
const existingItem = this.queue.find( const existingItem = this.queue.find(
(item) => item.sortIndex === targetItem.sortIndex, (item) => item.sortIndex === targetIndex,
); );
if (existingItem !== undefined) { if (existingItem !== undefined) {
existingItem.sortIndex = previousIndex; existingItem.sortIndex = previousIndex;
} targetItem.sortIndex = targetIndex;
await this.save(); await this.save();
} }
}
public newQueueItemId(): number { public newQueueItemId(): number {
const item = this.queue.sort((a, b) => b.id - a.id)[0]; const item = this.queue.sort((a, b) => b.id - a.id)[0];