Fix new queue items not being sorted properly.
This commit is contained in:
parent
ce7fbfe349
commit
1bf8f519c6
|
@ -39,10 +39,12 @@ export class Settings {
|
||||||
|
|
||||||
public async insertQueueItem(text: string, url: string): Promise<void> {
|
public async insertQueueItem(text: string, url: string): Promise<void> {
|
||||||
const id = this.newQueueItemId();
|
const id = this.newQueueItemId();
|
||||||
|
const sortIndex = this.newQueueItemSortIndex();
|
||||||
|
|
||||||
const item: Queue.Item = {
|
const item: Queue.Item = {
|
||||||
added: new Date(),
|
added: new Date(),
|
||||||
id,
|
id,
|
||||||
sortIndex: id,
|
sortIndex,
|
||||||
text,
|
text,
|
||||||
url,
|
url,
|
||||||
};
|
};
|
||||||
|
@ -52,7 +54,7 @@ export class Settings {
|
||||||
[`qi${id}`]: {
|
[`qi${id}`]: {
|
||||||
added: item.added.toISOString(),
|
added: item.added.toISOString(),
|
||||||
id,
|
id,
|
||||||
sortIndex: id,
|
sortIndex,
|
||||||
text,
|
text,
|
||||||
url,
|
url,
|
||||||
},
|
},
|
||||||
|
@ -85,6 +87,11 @@ export class Settings {
|
||||||
return item === undefined ? 1 : item.id + 1;
|
return item === undefined ? 1 : item.id + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public newQueueItemSortIndex(): number {
|
||||||
|
const item = this.queue.sort((a, b) => b.sortIndex - a.sortIndex)[0];
|
||||||
|
return item === undefined ? 1 : item.sortIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
public nextQueueItem(): Queue.Item | undefined {
|
public nextQueueItem(): Queue.Item | undefined {
|
||||||
return this.queue.sort((a, b) => a.sortIndex - b.sortIndex)[0];
|
return this.queue.sort((a, b) => a.sortIndex - b.sortIndex)[0];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue