From 7ea4c5b3379431d1991c8957a6227e368d4c681a Mon Sep 17 00:00:00 2001
From: pythongosssss <125205205+pythongosssss@users.noreply.github.com>
Date: Mon, 26 Aug 2024 21:19:50 +0100
Subject: [PATCH] Add loading spinner
---
.../sidebar/tabs/QueueSidebarTab.vue | 6 ++
src/stores/queueStore.ts | 79 ++++++++++---------
2 files changed, 49 insertions(+), 36 deletions(-)
diff --git a/src/components/sidebar/tabs/QueueSidebarTab.vue b/src/components/sidebar/tabs/QueueSidebarTab.vue
index 71180f61a..1649f4aeb 100644
--- a/src/components/sidebar/tabs/QueueSidebarTab.vue
+++ b/src/components/sidebar/tabs/QueueSidebarTab.vue
@@ -59,6 +59,11 @@
+
- tasks
- .map(
- (task: TaskItem) =>
- new TaskItemImpl(
- task.taskType,
- task.prompt,
- task['status'],
- task['outputs'] || {}
- )
+ this.loadingHistory = true
+ try {
+ const [queue, history] = await Promise.all([
+ api.getQueue(),
+ api.getHistory(this.maxHistoryItems)
+ ])
+
+ const toClassAll = (tasks: TaskItem[]): TaskItemImpl[] =>
+ tasks
+ .map(
+ (task: TaskItem) =>
+ new TaskItemImpl(
+ task.taskType,
+ task.prompt,
+ task['status'],
+ task['outputs'] || {}
+ )
+ )
+ // Desc order to show the latest tasks first
+ .sort((a, b) => b.queueIndex - a.queueIndex)
+
+ this.runningTasks = toClassAll(queue.Running)
+ this.pendingTasks = toClassAll(queue.Pending)
+
+ // Process history items
+ const allIndex = new Set(
+ history.History.map((item: TaskItem) => item.prompt[0])
+ )
+ const newHistoryItems = toClassAll(
+ history.History.filter(
+ (item) => item.prompt[0] > this.lastHistoryQueueIndex
)
- // Desc order to show the latest tasks first
- .sort((a, b) => b.queueIndex - a.queueIndex)
-
- this.runningTasks = toClassAll(queue.Running)
- this.pendingTasks = toClassAll(queue.Pending)
-
- // Process history items
- const allIndex = new Set(
- history.History.map((item: TaskItem) => item.prompt[0])
- )
- 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)
+ 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)
+ } finally {
+ this.loadingHistory = false
+ }
},
async clear() {
await Promise.all(