fix(editor): check for empty content

This commit is contained in:
kolaente 2023-11-03 12:22:38 +01:00
parent e02a106c64
commit ba766a29af
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 7 additions and 2 deletions

View File

@ -173,6 +173,7 @@ import {Placeholder} from '@tiptap/extension-placeholder'
import {eventToHotkeyString} from '@github/hotkey'
import {mergeAttributes} from '@tiptap/core'
import {createRandomID} from '@/helpers/randomId'
import {isEditorContentEmpty} from '@/helpers/editorContentEmpty'
const {t} = useI18n()
@ -267,7 +268,7 @@ const {
const emit = defineEmits(['update:modelValue', 'save'])
const inputHTML = ref('')
const isEmpty = computed(() => inputHTML.value === '' || inputHTML.value === '<p></p>')
const isEmpty = computed(() => isEditorContentEmpty(inputHTML.value))
const internalMode = ref<Mode>(initialMode)
const isEditing = computed(() => internalMode.value === 'edit' && isEditEnabled)

View File

@ -25,7 +25,7 @@
v-model="task.description"
@update:model-value="saveWithDelay"
@save="save"
:initial-mode="task.description !== '' ? 'preview' : 'edit'"
:initial-mode="isEditorContentEmpty(task.description) ? 'preview' : 'edit'"
/>
</div>
</template>
@ -39,6 +39,7 @@ import Editor from '@/components/input/AsyncEditor'
import type {ITask} from '@/modelTypes/ITask'
import {useTaskStore} from '@/stores/tasks'
import TaskModel from '@/models/task'
import {isEditorContentEmpty} from '@/helpers/editorContentEmpty'
type AttachmentUploadFunction = (file: File, onSuccess: (attachmentUrl: string) => void) => Promise<string>

View File

@ -0,0 +1,3 @@
export function isEditorContentEmpty(content: string): boolean {
return content === '' || content === '<p></p>'
}