fixed group reactivity

This commit is contained in:
2025-06-17 09:45:01 +02:00
parent 2972bb9e91
commit 4796dfc095
5 changed files with 43 additions and 27 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<UiCard <UiCard
v-if="modelValue" v-if="group"
:title="mode === 'create' ? t('title.create') : t('title.edit')" :title="mode === 'create' ? t('title.create') : t('title.edit')"
icon="mdi:folder-plus-outline" icon="mdi:folder-plus-outline"
@close="$emit('close')" @close="$emit('close')"
@ -14,12 +14,12 @@
:label="t('name')" :label="t('name')"
:placeholder="t('name')" :placeholder="t('name')"
autofocus autofocus
v-model="modelValue.name" v-model="group.name"
ref="nameRef" ref="nameRef"
/> />
<UiInput <UiInput
v-model="modelValue.description" v-model="group.description"
:check-input="check" :check-input="check"
:label="t('description')" :label="t('description')"
:placeholder="t('description')" :placeholder="t('description')"
@ -27,11 +27,11 @@
<div class="flex gap-4"> <div class="flex gap-4">
<UiSelectIcon <UiSelectIcon
v-model="modelValue.icon" v-model="group.icon"
default-icon="mdi:folder-outline" default-icon="mdi:folder-outline"
/> />
<UiSelectColor v-model="modelValue.color" /> <UiSelectColor v-model="group.color" />
</div> </div>
<div class="flex flex-wrap justify-end gap-4"> <div class="flex flex-wrap justify-end gap-4">
@ -58,9 +58,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { SelectHaexPasswordsGroups } from '~~/src-tauri/database/schemas/vault' import type { SelectHaexPasswordsGroups } from '~~/src-tauri/database/schemas/vault'
defineModel<SelectHaexPasswordsGroups | null>() const group = defineModel<SelectHaexPasswordsGroups | null>()
defineEmits(['close', 'submit', 'back']) defineEmits(['close', 'submit', 'back'])
defineProps<{ mode: 'create' | 'edit' }>() defineProps<{ mode: 'create' | 'edit' }>()
const { t } = useI18n() const { t } = useI18n()
const check = ref<boolean>(false) const check = ref<boolean>(false)

View File

@ -16,23 +16,24 @@
<div class="input-floating grow"> <div class="input-floating grow">
<input <input
:autofocus
:id :id
ref="inputRef"
v-model="input"
:name="name ?? id" :name="name ?? id"
:placeholder="placeholder || label" :placeholder="placeholder || label"
:type
:autofocus
class="ps-3"
:readonly="read_only" :readonly="read_only"
:type
class="ps-3"
ref="inputRef"
v-model="input"
/> />
<label <label
class="input-floating-label"
:for="id" :for="id"
class="input-floating-label"
> >
{{ label }} {{ label }}
</label> </label>
</div> </div>
{{ input }}
<Icon <Icon
v-if="appendIcon" v-if="appendIcon"

View File

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<HaexPassGroup <HaexPassGroup
v-model="currentGroup" v-model="group"
mode="edit" mode="edit"
@close="onClose" @close="onClose"
@submit="onSaveAsync" @submit="onSaveAsync"
@ -10,6 +10,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import type { SelectHaexPasswordsGroups } from '~~/src-tauri/database/schemas/vault'
definePageMeta({ definePageMeta({
name: 'passwordGroupEdit', name: 'passwordGroupEdit',
}) })
@ -20,7 +22,15 @@ const check = ref(false)
const { currentGroup } = storeToRefs(usePasswordGroupStore()) const { currentGroup } = storeToRefs(usePasswordGroupStore())
//const group = computed(() => currentGroup.value) const group = ref<SelectHaexPasswordsGroups>()
watch(
currentGroup,
(newGroup) => {
group.value = JSON.parse(JSON.stringify(newGroup))
},
{ immediate: true },
)
const errors = ref({ const errors = ref({
name: [], name: [],
@ -36,14 +46,14 @@ const { add } = useSnackbar()
const onSaveAsync = async () => { const onSaveAsync = async () => {
try { try {
check.value = true check.value = true
if (!currentGroup.value) return if (!group.value) return
console.log('onSave', errors.value) console.log('onSave', errors.value)
if (errors.value.name.length || errors.value.description.length) return if (errors.value.name.length || errors.value.description.length) return
const { updateAsync } = usePasswordGroupStore() const { updateAsync } = usePasswordGroupStore()
await updateAsync(currentGroup.value) await updateAsync(group.value)
add({ type: 'success', text: t('change.success') }) add({ type: 'success', text: t('change.success') })
onClose() onClose()

View File

@ -161,16 +161,20 @@ const item = reactive<{
const { currentItem } = storeToRefs(usePasswordItemStore()) const { currentItem } = storeToRefs(usePasswordItemStore())
watch(currentItem, () => { watch(
item.details = JSON.parse(JSON.stringify(currentItem.value?.details)) currentItem,
item.keyValues = JSON.parse(JSON.stringify(currentItem.value?.keyValues)) (newItem) => {
item.history = JSON.parse(JSON.stringify(currentItem.value?.history)) item.details = JSON.parse(JSON.stringify(newItem?.details))
item.keyValuesAdd = [] item.keyValues = JSON.parse(JSON.stringify(newItem?.keyValues))
item.keyValuesDelete = [] item.history = JSON.parse(JSON.stringify(newItem?.history))
item.originalDetails = JSON.stringify(currentItem.value?.details) item.keyValuesAdd = []
item.originalKeyValues = JSON.stringify(currentItem.value?.keyValues) item.keyValuesDelete = []
ignoreChanges.value = false item.originalDetails = JSON.stringify(newItem?.details)
}) item.originalKeyValues = JSON.stringify(newItem?.keyValues)
ignoreChanges.value = false
},
{ immediate: true },
)
const { add } = useSnackbar() const { add } = useSnackbar()
const { deleteAsync, updateAsync } = usePasswordItemStore() const { deleteAsync, updateAsync } = usePasswordItemStore()

View File

@ -68,7 +68,7 @@ export const getSingleRouteParam = (
param: string | string[] | LocationQueryValue | LocationQueryValue[], param: string | string[] | LocationQueryValue | LocationQueryValue[],
): string => { ): string => {
const _param = Array.isArray(param) ? param.at(0) ?? '' : param ?? '' const _param = Array.isArray(param) ? param.at(0) ?? '' : param ?? ''
console.log('getSingleRouteParam found:', _param, param) //console.log('getSingleRouteParam found:', _param, param)
return decodeURIComponent(_param) return decodeURIComponent(_param)
} }