Migrated useConfirm to internally uses useDialog for eventual migration

This commit is contained in:
arabcoders 2025-09-01 17:33:21 +03:00
parent cf382f0963
commit 2695bb40fc
10 changed files with 60 additions and 33 deletions

View file

@ -343,7 +343,7 @@ const importItem = async (): Promise<void> => {
return
}
if ((form.filter || form.cli) && !box.confirm('Overwrite the current form fields?', true)) {
if ((form.filter || form.cli) && !(await box.confirm('Overwrite the current form fields?', true))) {
return
}

View file

@ -588,7 +588,7 @@ const hasDownloaded = computed(() => {
return false
})
const deleteSelectedItems = () => {
const deleteSelectedItems = async () => {
if (selectedElms.value.length < 1) {
toast.error('No items selected.')
return
@ -597,7 +597,7 @@ const deleteSelectedItems = () => {
if (true === config.app.remove_files) {
msg += ' This will remove any associated files if they exists.'
}
if (false === box.confirm(msg, config.app.remove_files)) {
if (false === (await box.confirm(msg, config.app.remove_files))) {
return
}
for (const key in selectedElms.value) {
@ -614,9 +614,9 @@ const deleteSelectedItems = () => {
selectedElms.value = []
}
const clearCompleted = () => {
const clearCompleted = async () => {
let msg = 'Clear all completed downloads?'
if (false === box.confirm(msg)) {
if (false === (await box.confirm(msg))) {
return
}
for (const key in stateStore.history) {
@ -626,8 +626,8 @@ const clearCompleted = () => {
}
}
const clearIncomplete = () => {
if (false === box.confirm('Clear all in-complete downloads?')) {
const clearIncomplete = async () => {
if (false === (await box.confirm('Clear all in-complete downloads?'))) {
return
}
for (const key in stateStore.history) {
@ -706,8 +706,8 @@ const setStatus = (item: StoreItem) => {
return item.status
}
const retryIncomplete = () => {
if (false === box.confirm('Retry all incomplete downloads?')) {
const retryIncomplete = async () => {
if (false === (await box.confirm('Retry all incomplete downloads?'))) {
return false
}
for (const key in stateStore.history) {
@ -746,12 +746,12 @@ const archiveItem = async (item: StoreItem, opts = {}) => {
socket.emit('item_delete', { id: item._id, remove_file: false })
}
const removeItem = (item: StoreItem) => {
const removeItem = async (item: StoreItem) => {
let msg = `${config.app.remove_files ? 'Remove' : 'Clear'} '${item.title || item.id || item.url || '??'}'?`
if (item.status === 'finished' && config.app.remove_files) {
msg += ' This will remove any associated files if they exists.'
}
if (false === box.confirm(msg, Boolean(item.filename && config.app.remove_files))) {
if (false === (await box.confirm(msg, Boolean(item.filename && config.app.remove_files)))) {
return false
}
socket.emit('item_delete', {

View file

@ -373,7 +373,7 @@ const importItem = async () => {
}
if (form.name || form.request?.url) {
if (false === box.confirm('Overwrite the current form fields?', true)) {
if (false === (await box.confirm('Overwrite the current form fields?', true))) {
return
}
}

View file

@ -507,16 +507,16 @@ const updateProgress = (item: StoreItem): string => {
return string
}
const confirmCancel = (item: StoreItem) => {
if (true !== box.confirm(`Cancel '${item.title}'?`)) {
const confirmCancel = async (item: StoreItem) => {
if (true !== (await box.confirm(`Cancel '${item.title}'?`))) {
return false
}
cancelItems(item._id)
return true
}
const cancelSelected = () => {
if (true !== box.confirm(`Cancel '${selectedElms.value.length}' selected items?`)) {
const cancelSelected = async () => {
if (true !== (await box.confirm(`Cancel '${selectedElms.value.length}' selected items?`))) {
return false
}
cancelItems(selectedElms.value)
@ -543,7 +543,7 @@ const cancelItems = (item: string | string[]) => {
const startItem = (item: StoreItem) => socket.emit('item_start', item._id)
const pauseItem = (item: StoreItem) => socket.emit('item_pause', item._id)
const startItems = () => {
const startItems = async () => {
if (1 > selectedElms.value.length) {
return
}
@ -559,13 +559,13 @@ const startItems = () => {
toast.error('No eligible items to start.')
return
}
if (true !== box.confirm(`Start '${filtered.length}' selected items?`)) {
if (true !== (await box.confirm(`Start '${filtered.length}' selected items?`))) {
return false
}
filtered.forEach(id => socket.emit('item_start', id))
}
const pauseSelected = () => {
const pauseSelected = async () => {
if (1 > selectedElms.value.length) {
return
}
@ -581,7 +581,7 @@ const pauseSelected = () => {
toast.error('No eligible items to pause.')
return
}
if (true !== box.confirm(`Pause '${filtered.length}' selected items?`)) {
if (true !== (await box.confirm(`Pause '${filtered.length}' selected items?`))) {
return false
}
filtered.forEach(id => socket.emit('item_pause', id))

View file

@ -409,7 +409,7 @@ const importItem = async (): Promise<void> => {
}
if (form.url || form.timer) {
if (false === box.confirm('Overwrite the current form fields?', true)) {
if (false === (await box.confirm('Overwrite the current form fields?', true))) {
return
}
}

View file

@ -1,21 +1,48 @@
import { useStorage } from '@vueuse/core'
import { useDialog } from './useDialog'
const dialog = useDialog()
const reduceConfirm = useStorage<boolean>('reduce_confirm', false)
function confirm(msg: string, force: boolean = false): boolean {
const confirm = async (msg: string, force: boolean = false) => {
if (false === force && true === reduceConfirm.value) {
return true
}
return window.confirm(msg)
const { status } = await dialog.confirmDialog({
title: 'Please Confirm',
message: msg,
cancelText: 'Cancel',
confirmText: 'OK',
})
return status
}
function alert(msg: string): boolean {
return window.confirm(msg)
const alert = async (msg: string) => {
const { status } = await dialog.alertDialog({
title: 'Alert',
message: msg,
confirmText: 'OK',
})
return status
}
function prompt(msg: string, defaultValue: string = ''): string | null {
return window.prompt(msg, defaultValue)
const prompt = async (msg: string, defaultValue: string = '') => {
const { status, value } = await dialog.promptDialog({
title: 'Input Required',
message: msg,
initial: defaultValue,
cancelText: 'Cancel',
confirmText: 'OK',
})
if (status) {
return value
}
return null
}
export default function useConfirm() {

View file

@ -222,7 +222,7 @@ const updateItems = async (newItems: ConditionItem[]): Promise<boolean> => {
}
const deleteItem = async (cond: ConditionItem): Promise<void> => {
if (!box.confirm(`Delete '${cond.name}'?`, true)) {
if (true !== (await box.confirm(`Delete '${cond.name}'?`, true))) {
return
}

View file

@ -312,7 +312,7 @@ const updateData = async (items: notification[]) => {
}
const deleteItem = async (item: notification) => {
if (true !== box.confirm(`Delete '${item.name}'?`)) {
if (true !== (await box.confirm(`Delete '${item.name}'?`))) {
return
}
@ -373,7 +373,7 @@ const join_events = (events: string[]) =>
!events || events.length < 1 ? 'ALL' : events.map(e => ucFirst(e)).join(', ')
const sendTest = async () => {
if (true !== box.confirm('Send test notification?')) {
if (true !== (await box.confirm('Send test notification?'))) {
return
}

View file

@ -311,7 +311,7 @@ const updatePresets = async (items: Preset[]): Promise<boolean | undefined> => {
}
const deleteItem = async (item: Preset) => {
if (true !== box.confirm(`Delete preset '${item.name}'?`, true)) {
if (true !== (await box.confirm(`Delete preset '${item.name}'?`, true))) {
return
}

View file

@ -579,7 +579,7 @@ const deleteSelected = async () => {
}
const deleteItem = async (item: task_item) => {
if (true !== box.confirm(`Delete '${item.name}' task?`, true)) {
if (true !== (await box.confirm(`Delete '${item.name}' task?`, true))) {
return
}
@ -696,7 +696,7 @@ const runSelected = async () => {
}
const runNow = async (item: task_item, mass: boolean = false) => {
if (!mass && true !== box.confirm(`Run '${item.name}' now? it will also run at the scheduled time.`)) {
if (!mass && true !== (await box.confirm(`Run '${item.name}' now? it will also run at the scheduled time.`))) {
return
}