-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slide-to-confirm: added slide to confirm functionality
- Loading branch information
1 parent
864517d
commit 4f4e594
Showing
3 changed files
with
115 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ref, watch } from 'vue' // Adjust this import based on your Vue version | ||
|
||
// Reactive variables (if they are not provided from outside) | ||
export const showSlideToConfirm = ref(false) | ||
export const confirmed = ref(false) | ||
|
||
/** | ||
* Calls the provided action function if the user confirms through the slide-to-confirm component. | ||
* @param {() => void} actionFunc - A function representing the action to be confirmed. | ||
* @returns {Promise<void>} A Promise that resolves if the action is successfully executed or rejects in case of cancellation or errors. | ||
*/ | ||
export function slideToConfirm(actionFunc: () => void): Promise<void> { | ||
console.log('slideToConfirm') | ||
return new Promise((resolve, reject) => { | ||
// Show slide to confirm component | ||
showSlideToConfirm.value = true | ||
|
||
// Watch for changes on confirmed and showSlideToConfirm variables | ||
const stopWatching = watch([confirmed, showSlideToConfirm], ([newConfirmed, newShowSlideToConfirm]) => { | ||
if (newConfirmed) { | ||
stopWatching() | ||
confirmed.value = false | ||
try { | ||
actionFunc() | ||
resolve() | ||
} catch (error) { | ||
reject(error) | ||
} | ||
} else if (!newShowSlideToConfirm) { | ||
stopWatching() | ||
reject(new Error('User cancelled the action')) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters