Compare commits

..

No commits in common. "2ee0dcb0ed730f336de0b1f40f542839019c466e" and "9696b78728402634a048474b4dbd2296ae36221c" have entirely different histories.

2 changed files with 13 additions and 36 deletions

View File

@ -6,7 +6,7 @@ export default function createManifest(
const manifest: Record<string, unknown> = {
name: 'Queue',
description: 'A WebExtension for queueing links.',
version: '0.3.2',
version: '0.3.1',
permissions: ['contextMenus', 'storage'],
options_ui: {
page: 'options/index.html',

View File

@ -39,12 +39,10 @@ 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,
sortIndex: id,
text,
url,
};
@ -54,7 +52,7 @@ export class Settings {
[`qi${id}`]: {
added: item.added.toISOString(),
id,
sortIndex,
sortIndex: id,
text,
url,
},
@ -70,13 +68,19 @@ export class Settings {
throw new Error(`Failed to move item with ID: ${id}`);
}
const currentIndex = targetItem.sortIndex;
const targetIndex = this.nextQueueItemSortIndex(currentIndex, direction);
const previousIndex = targetItem.sortIndex;
let targetIndex = previousIndex;
if (direction === 'down') {
targetIndex += 1;
} else if (direction === 'up') {
targetIndex -= 1;
}
const existingItem = this.queue.find(
(item) => item.sortIndex === targetIndex,
);
if (existingItem !== undefined && targetIndex !== undefined) {
existingItem.sortIndex = currentIndex;
if (existingItem !== undefined) {
existingItem.sortIndex = previousIndex;
targetItem.sortIndex = targetIndex;
await this.save();
}
@ -87,37 +91,10 @@ 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];
}
public nextQueueItemSortIndex(
currentIndex: number,
direction: Queue.MoveDirection,
): number | undefined {
this.queue.sort((a, b) => {
return direction === 'up'
? b.sortIndex - a.sortIndex
: a.sortIndex - b.sortIndex;
});
let foundCurrent = false;
for (const item of this.queue) {
if (foundCurrent) {
return item.sortIndex;
}
if (item.sortIndex === currentIndex) {
foundCurrent = true;
}
}
}
public async removeQueueItem(id: number): Promise<void> {
const itemIndex = this.queue.findIndex((item) => item.id === id);
if (itemIndex === -1) {