fix(task): only save description when clicking away if it actually changed

This commit is contained in:
kolaente 2025-09-11 15:53:27 +02:00
parent d147a01c18
commit 25b33102f1
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 17 additions and 0 deletions

View File

@ -60,8 +60,10 @@ const emit = defineEmits<{
}>()
const description = ref<string>('')
const hasChanges = ref(false)
watchEffect(() => {
description.value = props.modelValue.description
hasChanges.value = false
})
const saved = ref(false)
@ -79,6 +81,15 @@ onMounted(() => {
})
async function saveWithDelay() {
if (description.value === props.modelValue.description) {
hasChanges.value = false
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
return
}
hasChanges.value = true
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
@ -99,6 +110,11 @@ onBeforeUnmount(async () => {
onBeforeRouteLeave(() => save())
async function save() {
if (!hasChanges.value) {
return
}
hasChanges.value = false
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
@ -121,6 +137,7 @@ async function save() {
if (error?.response?.status === 404) {
return
}
hasChanges.value = true
// Re-throw other errors
throw error
} finally {