fix: create article on title blur instead of debounce (#14037)

This commit is contained in:
Sivin Varghese
2026-04-13 23:23:25 +05:30
committed by GitHub
parent f422c83c26
commit a8c8b38f51
2 changed files with 19 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed } from 'vue'; import { computed, ref } from 'vue';
import { debounce } from '@chatwoot/utils'; import { debounce } from '@chatwoot/utils';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { ARTICLE_EDITOR_MENU_OPTIONS } from 'dashboard/constants/editor'; import { ARTICLE_EDITOR_MENU_OPTIONS } from 'dashboard/constants/editor';
@@ -32,6 +32,7 @@ const emit = defineEmits([
'setAuthor', 'setAuthor',
'setCategory', 'setCategory',
'previewArticle', 'previewArticle',
'createArticle',
]); ]);
const { t } = useI18n(); const { t } = useI18n();
@@ -57,16 +58,10 @@ const quickSave = debounce(
// Only use to save for existing articles // Only use to save for existing articles
const saveAndSyncDebounced = debounce(saveAndSync, 2500, false); const saveAndSyncDebounced = debounce(saveAndSync, 2500, false);
// Debounced save for new articles
const quickSaveNewArticle = debounce(saveAndSync, 400, false);
const handleSave = value => { const handleSave = value => {
if (isNewArticle.value) { if (isNewArticle.value) return;
quickSaveNewArticle(value); quickSave(value);
} else { saveAndSyncDebounced(value);
quickSave(value);
saveAndSyncDebounced(value);
}
}; };
const articleTitle = computed({ const articleTitle = computed({
@@ -76,9 +71,12 @@ const articleTitle = computed({
}, },
}); });
const localContent = ref(props.article.content || '');
const articleContent = computed({ const articleContent = computed({
get: () => props.article.content, get: () => props.article.content,
set: content => { set: content => {
localContent.value = content;
handleSave({ content }); handleSave({ content });
}, },
}); });
@@ -98,6 +96,14 @@ const setCategoryId = categoryId => {
const previewArticle = () => { const previewArticle = () => {
emit('previewArticle'); emit('previewArticle');
}; };
const handleCreateArticle = event => {
if (!isNewArticle.value) return;
const title = event?.target?.value || '';
if (title.trim()) {
emit('createArticle', { title, content: localContent.value });
}
};
</script> </script>
<template> <template>
@@ -122,6 +128,7 @@ const previewArticle = () => {
custom-text-area-wrapper-class="border-0 !bg-transparent dark:!bg-transparent !py-0 !px-0" custom-text-area-wrapper-class="border-0 !bg-transparent dark:!bg-transparent !py-0 !px-0"
placeholder="Title" placeholder="Title"
autofocus autofocus
@blur="handleCreateArticle"
/> />
<ArticleEditorControls <ArticleEditorControls
:article="article" :article="article"

View File

@@ -39,7 +39,7 @@ const createNewArticle = async ({ title, content }) => {
if (title) article.value.title = title; if (title) article.value.title = title;
if (content) article.value.content = content; if (content) article.value.content = content;
if (!article.value.title) return; if (!article.value.title || isUpdating.value) return;
isUpdating.value = true; isUpdating.value = true;
try { try {
@@ -86,7 +86,7 @@ const goBackToArticles = () => {
:article="article" :article="article"
:is-updating="isUpdating" :is-updating="isUpdating"
:is-saved="isSaved" :is-saved="isSaved"
@save-article="createNewArticle" @create-article="createNewArticle"
@go-back="goBackToArticles" @go-back="goBackToArticles"
@set-author="setAuthorId" @set-author="setAuthorId"
@set-category="setCategoryId" @set-category="setCategoryId"