From 3c954ac7159ae8ff81fb0f444e6d85ef14189b0c Mon Sep 17 00:00:00 2001 From: haex Date: Fri, 20 Jun 2025 11:52:45 +0200 Subject: [PATCH] fixed unsaved changes --- src/components/haex/pass/group/composables.ts | 24 ++++ src/components/haex/pass/item/keyValue.vue | 2 +- .../[vaultId]/passwords/[[groupId]]/edit.vue | 21 +--- .../[vaultId]/passwords/[[groupId]]/index.vue | 4 +- .../passwords/[[groupId]]/item/[itemId].vue | 118 +++++------------- .../passwords/[[groupId]]/item/create.vue | 92 ++++++++------ src/stores/passwords/groups.ts | 54 ++++---- src/utils/helper.ts | 75 +++++++++++ 8 files changed, 223 insertions(+), 167 deletions(-) create mode 100644 src/components/haex/pass/group/composables.ts diff --git a/src/components/haex/pass/group/composables.ts b/src/components/haex/pass/group/composables.ts new file mode 100644 index 0000000..2d979aa --- /dev/null +++ b/src/components/haex/pass/group/composables.ts @@ -0,0 +1,24 @@ +import type { SelectHaexPasswordsGroups } from '~~/src-tauri/database/schemas/vault' + +export const usePasswordGroup = () => { + const areItemsEqual = ( + groupA: unknown | unknown[] | null, + groupB: unknown | unknown[] | null, + ) => { + if (groupA === null && groupB === null) return true + + if (Array.isArray(groupA) && Array.isArray(groupB)) { + console.log('compare object arrays', groupA, groupB) + if (groupA.length === groupB.length) return true + + return groupA.some((group, index) => { + return areObjectsEqual(group, groupA[index]) + }) + } + return areObjectsEqual(groupA, groupB) + } + + return { + areItemsEqual, + } +} diff --git a/src/components/haex/pass/item/keyValue.vue b/src/components/haex/pass/item/keyValue.vue index 88f23d9..fe16792 100644 --- a/src/components/haex/pass/item/keyValue.vue +++ b/src/components/haex/pass/item/keyValue.vue @@ -52,7 +52,7 @@ class="btn-primary btn-outline flex-1-1 min-w-40" > - + diff --git a/src/pages/vault/[vaultId]/passwords/[[groupId]]/edit.vue b/src/pages/vault/[vaultId]/passwords/[[groupId]]/edit.vue index b84341d..307be57 100644 --- a/src/pages/vault/[vaultId]/passwords/[[groupId]]/edit.vue +++ b/src/pages/vault/[vaultId]/passwords/[[groupId]]/edit.vue @@ -77,7 +77,7 @@ watch( try { const foundGroup = await readGroupAsync(currentGroupId.value) if (foundGroup) { - original.value = JSON.stringify(foundGroup) + original.value = JSON.parse(JSON.stringify(foundGroup)) group.value = foundGroup } } catch (error) { @@ -86,22 +86,11 @@ watch( }, { immediate: true }, ) -/* watch( - currentGroup, - (n, o) => { - console.log('currentGroup', currentGroup.value, n, o) - original.value = JSON.stringify(currentGroup.value) - group.value = JSON.parse(original.value) - ignoreChanges.value = false - }, - { immediate: true }, -) */ const read_only = ref(false) -const hasChanges = computed( - () => JSON.stringify(group.value) !== original.value, -) +const { areItemsEqual } = usePasswordGroup() +const hasChanges = computed(() => !!!areItemsEqual(group.value, original.value)) const onClose = () => { if (showConfirmDeleteDialog.value || showUnsavedChangesDialog.value) return @@ -121,7 +110,7 @@ const onSaveAsync = async () => { ignoreChanges.value = true await updateAsync(group.value) - await syncGroupItemsAsync(group.value.id) + await syncGroupItemsAsync() add({ type: 'success', text: t('change.success') }) onClose() } catch (error) { @@ -141,7 +130,7 @@ const onDeleteAsync = async () => { try { const parentId = group.value.parentId await deleteGroupAsync(group.value.id, inTrashGroup.value) - await syncGroupItemsAsync(parentId) + await syncGroupItemsAsync() showConfirmDeleteDialog.value = false ignoreChanges.value = true await navigateTo( diff --git a/src/pages/vault/[vaultId]/passwords/[[groupId]]/index.vue b/src/pages/vault/[vaultId]/passwords/[[groupId]]/index.vue index 0bca32b..9517037 100644 --- a/src/pages/vault/[vaultId]/passwords/[[groupId]]/index.vue +++ b/src/pages/vault/[vaultId]/passwords/[[groupId]]/index.vue @@ -194,7 +194,7 @@ const onPasteAsync = async () => { [...selectedGroupItems.value], currentGroupId.value, ) - await syncGroupItemsAsync(currentGroupId.value) + await syncGroupItemsAsync() selectedGroupItems.value = [] selectedItems.value.clear() } catch (error) { @@ -235,7 +235,7 @@ const onDeleteAsync = async () => { } } selectedItems.value.clear() - await syncGroupItemsAsync(currentGroupId.value) + await syncGroupItemsAsync() } const keys = useMagicKeys() watch(keys.delete, async () => { diff --git a/src/pages/vault/[vaultId]/passwords/[[groupId]]/item/[itemId].vue b/src/pages/vault/[vaultId]/passwords/[[groupId]]/item/[itemId].vue index 5ca489a..1019e8d 100644 --- a/src/pages/vault/[vaultId]/passwords/[[groupId]]/item/[itemId].vue +++ b/src/pages/vault/[vaultId]/passwords/[[groupId]]/item/[itemId].vue @@ -1,5 +1,11 @@