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> {
 | 
			
		||||
    const id = this.newQueueItemId();
 | 
			
		||||
    const sortIndex = this.newQueueItemSortIndex();
 | 
			
		||||
 | 
			
		||||
    const item: Queue.Item = {
 | 
			
		||||
      added: new Date(),
 | 
			
		||||
      id,
 | 
			
		||||
      sortIndex: id,
 | 
			
		||||
      sortIndex,
 | 
			
		||||
      text,
 | 
			
		||||
      url,
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			@ -52,7 +54,7 @@ export class Settings {
 | 
			
		|||
      [`qi${id}`]: {
 | 
			
		||||
        added: item.added.toISOString(),
 | 
			
		||||
        id,
 | 
			
		||||
        sortIndex: id,
 | 
			
		||||
        sortIndex,
 | 
			
		||||
        text,
 | 
			
		||||
        url,
 | 
			
		||||
      },
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +87,11 @@ export class Settings {
 | 
			
		|||
    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 {
 | 
			
		||||
    return this.queue.sort((a, b) => a.sortIndex - b.sortIndex)[0];
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue