Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to clear pending tasks #810

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading