fix(editor): change description when switching between tasks

This commit is contained in:
kolaente 2023-11-03 12:36:20 +01:00
parent 64a8dd189b
commit bde212d432
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 13 additions and 10 deletions

View File

@ -365,14 +365,14 @@ const editor = useEditor({
watch( watch(
() => modelValue, () => modelValue,
value => { value => {
inputHTML.value = modelValue inputHTML.value = value
if (!editor?.value) return if (!editor?.value) return
if (editor.value.getHTML() === value) { if (editor.value.getHTML() === value) {
return return
} }
editor.value.commands.setContent(value, false) editor.value.commands.setContent(value, false)
}, },
) )

View File

@ -22,10 +22,10 @@
:placeholder="$t('task.description.placeholder')" :placeholder="$t('task.description.placeholder')"
:show-save="true" :show-save="true"
edit-shortcut="e" edit-shortcut="e"
v-model="task.description" v-model="description"
@update:model-value="saveWithDelay" @update:model-value="saveWithDelay"
@save="save" @save="save"
:initial-mode="isEditorContentEmpty(task.description) ? 'preview' : 'edit'" :initial-mode="isEditorContentEmpty(description) ? 'preview' : 'edit'"
/> />
</div> </div>
</template> </template>
@ -55,7 +55,7 @@ const {
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const task = ref<ITask>(new TaskModel()) const description = ref<string>('')
const saved = ref(false) const saved = ref(false)
// Since loading is global state, this variable ensures we're only showing the saving icon when saving the description. // Since loading is global state, this variable ensures we're only showing the saving icon when saving the description.
@ -65,9 +65,9 @@ const taskStore = useTaskStore()
const loading = computed(() => taskStore.isLoading) const loading = computed(() => taskStore.isLoading)
watch( watch(
() => modelValue, () => modelValue.description,
(value) => { value => {
task.value = value description.value = value
}, },
{immediate: true}, {immediate: true},
) )
@ -93,8 +93,11 @@ async function save() {
try { try {
// FIXME: don't update state from internal. // FIXME: don't update state from internal.
task.value = await taskStore.update(task.value) const updated = await taskStore.update({
emit('update:modelValue', task.value) ...modelValue,
description: description.value,
})
emit('update:modelValue', updated)
saved.value = true saved.value = true
setTimeout(() => { setTimeout(() => {