Skip to content

Commit

Permalink
Add button to clear pending tasks (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Sep 13, 2024
1 parent 880ac4f commit d8d6fa8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/components/sidebar/tabs/QueueSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
class="toggle-expanded-button"
v-tooltip="$t('sideToolbar.queueTab.showFlatList')"
/>
<Button
v-if="queueStore.hasPendingTasks"
icon="pi pi-stop"
text
severity="danger"
@click="clearPendingTasks"
class="clear-pending-button"
v-tooltip="$t('sideToolbar.queueTab.clearPendingTasks')"
/>
<Button
icon="pi pi-trash"
text
Expand Down Expand Up @@ -221,6 +230,16 @@ const confirmRemoveAll = (event: Event) => {
})
}
const clearPendingTasks = async () => {
await queueStore.clear(['queue'])
toast.add({
severity: 'info',
summary: 'Confirmed',
detail: 'Pending tasks deleted',
life: 3000
})
}
const onStatus = async () => {
await queueStore.update()
updateVisibleTasks()
Expand Down
6 changes: 4 additions & 2 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const messages = {
showFlatList: 'Show Flat List',
backToAllTasks: 'Back to All Tasks',
containImagePreview: 'Fill Image Preview',
coverImagePreview: 'Fit Image Preview'
coverImagePreview: 'Fit Image Preview',
clearPendingTasks: 'Clear Pending Tasks'
}
}
},
Expand Down Expand Up @@ -97,7 +98,8 @@ const messages = {
},
queueTab: {
showFlatList: '平铺结果',
backToAllTasks: '返回'
backToAllTasks: '返回',
clearPendingTasks: '清除待处理任务'
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/stores/queueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ export const useQueueStore = defineStore('queue', {
},
lastHistoryQueueIndex(state) {
return state.historyTasks.length ? state.historyTasks[0].queueIndex : -1
},
hasPendingTasks(state) {
return state.pendingTasks.length > 0
}
},
actions: {
Expand Down Expand Up @@ -325,10 +328,11 @@ export const useQueueStore = defineStore('queue', {
this.isLoading = false
}
},
async clear() {
await Promise.all(
['queue', 'history'].map((type) => api.clearItems(type))
)
async clear(targets: ('queue' | 'history')[] = ['queue', 'history']) {
if (targets.length === 0) {
return
}
await Promise.all(targets.map((type) => api.clearItems(type)))
await this.update()
},
async delete(task: TaskItemImpl) {
Expand Down

0 comments on commit d8d6fa8

Please sign in to comment.