Skip to content

Commit a297ffc

Browse files
committed
Add button to clear pending tasks
1 parent 880ac4f commit a297ffc

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/components/sidebar/tabs/QueueSidebarTab.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
class="toggle-expanded-button"
3232
v-tooltip="$t('sideToolbar.queueTab.showFlatList')"
3333
/>
34+
<Button
35+
v-if="queueStore.hasPendingTasks"
36+
icon="pi pi-stop"
37+
text
38+
severity="danger"
39+
@click="clearPendingTasks"
40+
class="clear-pending-button"
41+
v-tooltip="$t('sideToolbar.queueTab.clearPendingTasks')"
42+
/>
3443
<Button
3544
icon="pi pi-trash"
3645
text
@@ -221,6 +230,16 @@ const confirmRemoveAll = (event: Event) => {
221230
})
222231
}
223232
233+
const clearPendingTasks = async () => {
234+
await queueStore.clear(['queue'])
235+
toast.add({
236+
severity: 'info',
237+
summary: 'Confirmed',
238+
detail: 'Pending tasks deleted',
239+
life: 3000
240+
})
241+
}
242+
224243
const onStatus = async () => {
225244
await queueStore.update()
226245
updateVisibleTasks()

src/i18n.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const messages = {
5454
showFlatList: 'Show Flat List',
5555
backToAllTasks: 'Back to All Tasks',
5656
containImagePreview: 'Fill Image Preview',
57-
coverImagePreview: 'Fit Image Preview'
57+
coverImagePreview: 'Fit Image Preview',
58+
clearPendingTasks: 'Clear Pending Tasks'
5859
}
5960
}
6061
},
@@ -97,7 +98,8 @@ const messages = {
9798
},
9899
queueTab: {
99100
showFlatList: '平铺结果',
100-
backToAllTasks: '返回'
101+
backToAllTasks: '返回',
102+
clearPendingTasks: '清除待处理任务'
101103
}
102104
}
103105
}

src/stores/queueStore.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ export const useQueueStore = defineStore('queue', {
277277
},
278278
lastHistoryQueueIndex(state) {
279279
return state.historyTasks.length ? state.historyTasks[0].queueIndex : -1
280+
},
281+
hasPendingTasks(state) {
282+
return state.pendingTasks.length > 0
280283
}
281284
},
282285
actions: {
@@ -325,10 +328,11 @@ export const useQueueStore = defineStore('queue', {
325328
this.isLoading = false
326329
}
327330
},
328-
async clear() {
329-
await Promise.all(
330-
['queue', 'history'].map((type) => api.clearItems(type))
331-
)
331+
async clear(targets: ('queue' | 'history')[] = ['queue', 'history']) {
332+
if (targets.length === 0) {
333+
return
334+
}
335+
await Promise.all(targets.map((type) => api.clearItems(type)))
332336
await this.update()
333337
},
334338
async delete(task: TaskItemImpl) {

0 commit comments

Comments
 (0)