forked from mirrors/homebox
feat: add support for create + add more for all create modals and support k… (#526)
* add support for create + add more for all create modals and support keyboard bindings * listen for esc to close modals
This commit is contained in:
parent
8c7d91ea52
commit
22bbaae08f
4 changed files with 124 additions and 33 deletions
|
@ -32,6 +32,12 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function escClose(e: KeyboardEvent) {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
if (props.readonly) {
|
if (props.readonly) {
|
||||||
emit("cancel");
|
emit("cancel");
|
||||||
|
@ -42,4 +48,12 @@
|
||||||
|
|
||||||
const modalId = useId();
|
const modalId = useId();
|
||||||
const modal = useVModel(props, "modelValue", emit);
|
const modal = useVModel(props, "modelValue", emit);
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
if (modal.value) {
|
||||||
|
document.addEventListener("keydown", escClose);
|
||||||
|
} else {
|
||||||
|
document.removeEventListener("keydown", escClose);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<BaseModal v-model="modal">
|
<BaseModal v-model="modal">
|
||||||
<template #title> Create Item </template>
|
<template #title> Create Item </template>
|
||||||
<form @submit.prevent="create(true)">
|
<div @keyup="keySubmit">
|
||||||
<LocationSelector v-model="form.location" />
|
<LocationSelector v-model="form.location" />
|
||||||
<FormTextField
|
<FormTextField ref="nameInput" v-model="form.name" :trigger-focus="focused" :autofocus="true" label="Item Name" />
|
||||||
ref="locationNameRef"
|
|
||||||
v-model="form.name"
|
|
||||||
:trigger-focus="focused"
|
|
||||||
:autofocus="true"
|
|
||||||
label="Item Name"
|
|
||||||
/>
|
|
||||||
<FormTextArea v-model="form.description" label="Item Description" />
|
<FormTextArea v-model="form.description" label="Item Description" />
|
||||||
<FormMultiselect v-model="form.labels" label="Labels" :items="labels ?? []" />
|
<FormMultiselect v-model="form.labels" label="Labels" :items="labels ?? []" />
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
<BaseButton ref="submitBtn" type="submit" class="rounded-r-none" :loading="loading">
|
<BaseButton class="rounded-r-none" :loading="loading" @click="create(true)">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<Icon name="mdi-package-variant" class="swap-off h-5 w-5" />
|
<Icon name="mdi-package-variant" class="swap-off h-5 w-5" />
|
||||||
<Icon name="mdi-package-variant-closed" class="swap-on h-5 w-5" />
|
<Icon name="mdi-package-variant-closed" class="swap-on h-5 w-5" />
|
||||||
|
@ -26,12 +20,17 @@
|
||||||
<Icon class="h-5 w-5" name="mdi-chevron-down" />
|
<Icon class="h-5 w-5" name="mdi-chevron-down" />
|
||||||
</label>
|
</label>
|
||||||
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-64">
|
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-64">
|
||||||
<li><button @click.prevent="create(false)">Create and Add Another</button></li>
|
<li>
|
||||||
|
<button type="button" @click.prevent="create(false)">Create and Add Another</button>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
<p class="text-sm text-center mt-4">
|
||||||
|
use <kbd class="kbd kbd-xs">Shift</kbd> + <kbd class="kbd kbd-xs"> Enter </kbd> to create and add another
|
||||||
|
</p>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -47,6 +46,15 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const api = useUserApi();
|
||||||
|
const toast = useNotifier();
|
||||||
|
|
||||||
|
const locationsStore = useLocationStore();
|
||||||
|
const locations = computed(() => locationsStore.allLocations);
|
||||||
|
|
||||||
|
const labelStore = useLabelStore();
|
||||||
|
const labels = computed(() => labelStore.labels);
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const labelId = computed(() => {
|
const labelId = computed(() => {
|
||||||
|
@ -63,16 +71,7 @@
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
const api = useUserApi();
|
const nameInput = ref<HTMLInputElement | null>(null);
|
||||||
const toast = useNotifier();
|
|
||||||
|
|
||||||
const locationsStore = useLocationStore();
|
|
||||||
const locations = computed(() => locationsStore.allLocations);
|
|
||||||
|
|
||||||
const labelStore = useLabelStore();
|
|
||||||
const labels = computed(() => labelStore.labels);
|
|
||||||
|
|
||||||
const submitBtn = ref(null);
|
|
||||||
|
|
||||||
const modal = useVModel(props, "modelValue");
|
const modal = useVModel(props, "modelValue");
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
@ -136,4 +135,18 @@
|
||||||
navigateTo(`/item/${data.id}`);
|
navigateTo(`/item/${data.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function keySubmit(e: KeyboardEvent) {
|
||||||
|
// Shift + Enter
|
||||||
|
if (e.shiftKey && e.key === "Enter") {
|
||||||
|
console.log("Shift + Enter");
|
||||||
|
e.preventDefault();
|
||||||
|
await create(false);
|
||||||
|
focused.value = true;
|
||||||
|
} else if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log("Enter");
|
||||||
|
await create(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<BaseModal v-model="modal">
|
<BaseModal v-model="modal">
|
||||||
<template #title> Create Label </template>
|
<template #title> Create Label </template>
|
||||||
<form @submit.prevent="create">
|
<div @keyup="keySubmit">
|
||||||
<FormTextField
|
<FormTextField
|
||||||
ref="locationNameRef"
|
ref="locationNameRef"
|
||||||
v-model="form.name"
|
v-model="form.name"
|
||||||
|
@ -11,9 +11,26 @@
|
||||||
/>
|
/>
|
||||||
<FormTextArea v-model="form.description" label="Label Description" />
|
<FormTextArea v-model="form.description" label="Label Description" />
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<BaseButton type="submit" :loading="loading"> Create </BaseButton>
|
<div class="flex justify-center">
|
||||||
|
<BaseButton class="rounded-r-none" type="submit" :loading="loading" @click.prevent="create(true)">
|
||||||
|
Create
|
||||||
|
</BaseButton>
|
||||||
|
<div class="dropdown dropdown-top">
|
||||||
|
<label tabindex="0" class="btn rounded-l-none rounded-r-xl">
|
||||||
|
<Icon class="h-5 w-5" name="mdi-chevron-down" />
|
||||||
|
</label>
|
||||||
|
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-64">
|
||||||
|
<li>
|
||||||
|
<button @click.prevent="create(false)">Create and Add Another</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
<p class="text-sm text-center mt-4">
|
||||||
|
use <kbd class="kbd kbd-xs">Shift</kbd> + <kdb class="kbd kbd-xs"> Enter </kdb> to create and add another
|
||||||
|
</p>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -39,7 +56,6 @@
|
||||||
form.description = "";
|
form.description = "";
|
||||||
form.color = "";
|
form.color = "";
|
||||||
focused.value = false;
|
focused.value = false;
|
||||||
modal.value = false;
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +69,7 @@
|
||||||
const api = useUserApi();
|
const api = useUserApi();
|
||||||
const toast = useNotifier();
|
const toast = useNotifier();
|
||||||
|
|
||||||
async function create() {
|
async function create(close: boolean) {
|
||||||
const { error, data } = await api.labels.create(form);
|
const { error, data } = await api.labels.create(form);
|
||||||
if (error) {
|
if (error) {
|
||||||
toast.error("Couldn't create label");
|
toast.error("Couldn't create label");
|
||||||
|
@ -62,6 +78,22 @@
|
||||||
|
|
||||||
toast.success("Label created");
|
toast.success("Label created");
|
||||||
reset();
|
reset();
|
||||||
navigateTo(`/label/${data.id}`);
|
|
||||||
|
if (close) {
|
||||||
|
modal.value = false;
|
||||||
|
navigateTo(`/label/${data.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function keySubmit(e: KeyboardEvent) {
|
||||||
|
// Shift + Enter
|
||||||
|
if (e.shiftKey && e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
await create(false);
|
||||||
|
focused.value = true;
|
||||||
|
} else if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
await create(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<BaseModal v-model="modal">
|
<BaseModal v-model="modal">
|
||||||
<template #title> Create Location </template>
|
<template #title> Create Location </template>
|
||||||
<form @submit.prevent="create">
|
<div @keyup="keySubmit">
|
||||||
<FormTextField
|
<FormTextField
|
||||||
ref="locationNameRef"
|
ref="locationNameRef"
|
||||||
v-model="form.name"
|
v-model="form.name"
|
||||||
|
@ -12,9 +12,26 @@
|
||||||
<FormTextArea v-model="form.description" label="Location Description" />
|
<FormTextArea v-model="form.description" label="Location Description" />
|
||||||
<LocationSelector v-model="form.parent" />
|
<LocationSelector v-model="form.parent" />
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<BaseButton type="submit" :loading="loading"> Create </BaseButton>
|
<div class="flex justify-center">
|
||||||
|
<BaseButton class="rounded-r-none" type="submit" :loading="loading" @click="create(true)">
|
||||||
|
Create
|
||||||
|
</BaseButton>
|
||||||
|
<div class="dropdown dropdown-top">
|
||||||
|
<label tabindex="0" class="btn rounded-l-none rounded-r-xl">
|
||||||
|
<Icon class="h-5 w-5" name="mdi-chevron-down" />
|
||||||
|
</label>
|
||||||
|
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-64">
|
||||||
|
<li>
|
||||||
|
<button @click.prevent="create(false)">Create and Add Another</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
<p class="text-sm text-center mt-4">
|
||||||
|
use <kbd class="kbd kbd-xs">Shift</kbd> + <kbd class="kbd kbd-xs"> Enter </kbd> to create and add another
|
||||||
|
</p>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -48,14 +65,13 @@
|
||||||
form.description = "";
|
form.description = "";
|
||||||
form.parent = null;
|
form.parent = null;
|
||||||
focused.value = false;
|
focused.value = false;
|
||||||
modal.value = false;
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = useUserApi();
|
const api = useUserApi();
|
||||||
const toast = useNotifier();
|
const toast = useNotifier();
|
||||||
|
|
||||||
async function create() {
|
async function create(close: boolean) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|
||||||
const { data, error } = await api.locations.create({
|
const { data, error } = await api.locations.create({
|
||||||
|
@ -72,6 +88,22 @@
|
||||||
toast.success("Location created");
|
toast.success("Location created");
|
||||||
}
|
}
|
||||||
reset();
|
reset();
|
||||||
navigateTo(`/location/${data.id}`);
|
|
||||||
|
if (close) {
|
||||||
|
modal.value = false;
|
||||||
|
navigateTo(`/location/${data.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function keySubmit(e: KeyboardEvent) {
|
||||||
|
// Shift + Enter
|
||||||
|
if (e.shiftKey && e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
await create(false);
|
||||||
|
focused.value = true;
|
||||||
|
} else if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
await create(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue