unify confirm API

This commit is contained in:
Hayden 2022-09-25 14:24:32 -08:00
parent 5a5326990c
commit 17966f8a18
4 changed files with 11 additions and 8 deletions

View file

@ -1,10 +1,11 @@
import { UseConfirmDialogReturn } from "@vueuse/core";
import { UseConfirmDialogRevealResult, UseConfirmDialogReturn } from "@vueuse/core";
import { Ref } from "vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Store = UseConfirmDialogReturn<any, boolean, boolean> & {
text: Ref<string>;
setup: boolean;
open: (text: string) => Promise<UseConfirmDialogRevealResult<boolean, boolean>>;
};
const store: Partial<Store> = {
@ -30,13 +31,13 @@ export function useConfirm(): Store {
store.cancel = cancel;
}
async function openDialog(msg: string) {
async function openDialog(msg: string): Promise<UseConfirmDialogRevealResult<boolean, boolean>> {
store.text.value = msg;
return await store.reveal();
}
return {
...(store as Store),
reveal: openDialog,
open: openDialog,
};
}

View file

@ -204,7 +204,7 @@
const confirm = useConfirm();
async function deleteAttachment(attachmentId: string) {
const confirmed = await confirm.reveal("Are you sure you want to delete this attachment?");
const confirmed = await confirm.open("Are you sure you want to delete this attachment?");
if (confirmed.isCanceled) {
return;

View file

@ -174,7 +174,7 @@
const confirm = useConfirm();
async function deleteItem() {
const confirmed = await confirm.reveal("Are you sure you want to delete this item?");
const confirmed = await confirm.open("Are you sure you want to delete this item?");
if (!confirmed.data) {
return;

View file

@ -58,10 +58,12 @@
return details;
});
const { reveal } = useConfirm();
const confirm = useConfirm();
async function confirmDelete() {
const { isCanceled } = await reveal("Are you sure you want to delete this label? This action cannot be undone.");
const { isCanceled } = await confirm.open(
"Are you sure you want to delete this label? This action cannot be undone."
);
if (isCanceled) {
return;
@ -154,7 +156,7 @@
<section v-if="label">
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
<div class="grid gap-2 grid-cols-2">
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2">
<ItemCard v-for="item in label.items" :key="item.id" :item="item" />
</div>
</section>