From 00fe3515b9395430b95d26bd388aac330af231bd Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 14 Aug 2024 15:10:17 -0400 Subject: [PATCH] Fix delete queue item (#428) --- src/stores/queueStore.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/stores/queueStore.ts b/src/stores/queueStore.ts index 796728995..c3c1efdd2 100644 --- a/src/stores/queueStore.ts +++ b/src/stores/queueStore.ts @@ -198,16 +198,20 @@ export const useQueueStore = defineStore('queue', { this.pendingTasks = toClassAll(queue.Pending) // Process history items - const newHistoryItems = history.History.filter( - (item) => item.prompt[0] > this.lastHistoryQueueIndex + const allIndex = new Set( + history.History.map((item: TaskItem) => item.prompt[0]) ) - - if (newHistoryItems.length > 0) { - const newProcessedItems = toClassAll(newHistoryItems) - this.historyTasks = [...newProcessedItems, ...this.historyTasks] - .slice(0, this.maxHistoryItems) - .sort((a, b) => b.queueIndex - a.queueIndex) - } + const newHistoryItems = toClassAll( + history.History.filter( + (item) => item.prompt[0] > this.lastHistoryQueueIndex + ) + ) + const existingHistoryItems = this.historyTasks.filter( + (item: TaskItemImpl) => allIndex.has(item.queueIndex) + ) + this.historyTasks = [...newHistoryItems, ...existingHistoryItems] + .slice(0, this.maxHistoryItems) + .sort((a, b) => b.queueIndex - a.queueIndex) }, async clear() { await Promise.all(