mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-05 09:10:26 +00:00
unify confirm API
This commit is contained in:
parent
5a5326990c
commit
17966f8a18
4 changed files with 11 additions and 8 deletions
|
@ -1,10 +1,11 @@
|
||||||
import { UseConfirmDialogReturn } from "@vueuse/core";
|
import { UseConfirmDialogRevealResult, UseConfirmDialogReturn } from "@vueuse/core";
|
||||||
import { Ref } from "vue";
|
import { Ref } from "vue";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type Store = UseConfirmDialogReturn<any, boolean, boolean> & {
|
type Store = UseConfirmDialogReturn<any, boolean, boolean> & {
|
||||||
text: Ref<string>;
|
text: Ref<string>;
|
||||||
setup: boolean;
|
setup: boolean;
|
||||||
|
open: (text: string) => Promise<UseConfirmDialogRevealResult<boolean, boolean>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const store: Partial<Store> = {
|
const store: Partial<Store> = {
|
||||||
|
@ -30,13 +31,13 @@ export function useConfirm(): Store {
|
||||||
store.cancel = cancel;
|
store.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openDialog(msg: string) {
|
async function openDialog(msg: string): Promise<UseConfirmDialogRevealResult<boolean, boolean>> {
|
||||||
store.text.value = msg;
|
store.text.value = msg;
|
||||||
return await store.reveal();
|
return await store.reveal();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...(store as Store),
|
...(store as Store),
|
||||||
reveal: openDialog,
|
open: openDialog,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
|
|
||||||
async function deleteAttachment(attachmentId: string) {
|
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) {
|
if (confirmed.isCanceled) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -174,7 +174,7 @@
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
|
|
||||||
async function deleteItem() {
|
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) {
|
if (!confirmed.data) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -58,10 +58,12 @@
|
||||||
return details;
|
return details;
|
||||||
});
|
});
|
||||||
|
|
||||||
const { reveal } = useConfirm();
|
const confirm = useConfirm();
|
||||||
|
|
||||||
async function confirmDelete() {
|
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) {
|
if (isCanceled) {
|
||||||
return;
|
return;
|
||||||
|
@ -154,7 +156,7 @@
|
||||||
|
|
||||||
<section v-if="label">
|
<section v-if="label">
|
||||||
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
|
<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" />
|
<ItemCard v-for="item in label.items" :key="item.id" :item="item" />
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue