1
0

fix: bubble changes from the editor immediately and move the delay to callers

This gives the callers more control over when to save data and show/hide additional controls based on the input text
This commit is contained in:
kolaente
2023-06-02 12:40:21 +02:00
parent 68fd4698ac
commit f4a7943680
3 changed files with 64 additions and 33 deletions

View File

@ -74,9 +74,13 @@
@update:model-value="
() => {
toggleEdit(c)
editComment()
editCommentWithDelay()
}
"
@save="() => {
toggleEdit(c)
editComment()
}"
:bottom-actions="actions[c.id]"
:show-save="true"
/>
@ -279,10 +283,26 @@ function toggleDelete(commentId: ITaskComment['id']) {
commentToDelete.id = commentId
}
const changeTimeout = ref<ReturnType<typeof setTimeout> | null>(null)
async function editCommentWithDelay() {
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
changeTimeout.value = setTimeout(async () => {
await editComment()
}, 5000)
}
async function editComment() {
if (commentEdit.comment === '') {
return
}
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
saving.value = commentEdit.id

View File

@ -25,7 +25,8 @@
:show-save="true"
edit-shortcut="e"
v-model="task.description"
@update:model-value="save"
@update:model-value="saveWithDelay"
@save="save"
/>
</div>
</template>
@ -40,7 +41,6 @@ import type {ITask} from '@/modelTypes/ITask'
import {useTaskStore} from '@/stores/tasks'
import TaskModel from '@/models/task'
const props = defineProps({
modelValue: {
type: Object as PropType<ITask>,
@ -74,7 +74,23 @@ watch(
{immediate: true},
)
const changeTimeout = ref<ReturnType<typeof setTimeout> | null>(null)
async function saveWithDelay() {
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
changeTimeout.value = setTimeout(async () => {
await save()
}, 5000)
}
async function save() {
if (changeTimeout.value !== null) {
clearTimeout(changeTimeout.value)
}
saving.value = true
try {