fix: markdown-to-richtext conversion failure prevents type switch
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 46s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 46s
- If /api/ai/convert-markdown fails, abort the type change and show error toast - Only switch to richtext after successful content conversion - Switching back to markdown always works (no conversion needed) - Add i18n keys for conversion success/failure messages Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -497,11 +497,8 @@ export function NoteInlineEditor({
|
||||
value={noteType}
|
||||
onChange={async (newType) => {
|
||||
const oldType = noteType
|
||||
setNoteType(newType)
|
||||
if (newType === 'markdown') setShowMarkdownPreview(true)
|
||||
else setShowMarkdownPreview(false)
|
||||
|
||||
// When switching from markdown to richtext, convert content to HTML
|
||||
// markdown → richtext: convert content to HTML first
|
||||
if (oldType === 'markdown' && newType === 'richtext') {
|
||||
try {
|
||||
const res = await fetch('/api/ai/convert-markdown', {
|
||||
@@ -511,6 +508,8 @@ export function NoteInlineEditor({
|
||||
})
|
||||
if (res.ok) {
|
||||
const { html } = await res.json()
|
||||
setNoteType('richtext')
|
||||
setShowMarkdownPreview(false)
|
||||
setContent(html)
|
||||
saveInline(note.id, {
|
||||
type: 'richtext',
|
||||
@@ -518,13 +517,19 @@ export function NoteInlineEditor({
|
||||
content: html,
|
||||
}).catch(() => {})
|
||||
onChange?.(note.id, { type: 'richtext', isMarkdown: false, content: html })
|
||||
toast.success(t('notes.convertedToRichText') || 'Converted to rich text')
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
// Fall through to save without conversion
|
||||
}
|
||||
} catch {}
|
||||
// Conversion failed — abort the type change
|
||||
toast.error(t('notes.conversionFailed') || 'Conversion failed, staying in Markdown')
|
||||
return
|
||||
}
|
||||
|
||||
setNoteType(newType)
|
||||
if (newType === 'markdown') setShowMarkdownPreview(true)
|
||||
else setShowMarkdownPreview(false)
|
||||
|
||||
// Persist both type and isMarkdown immediately
|
||||
saveInline(note.id, {
|
||||
type: newType,
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "ماركداون",
|
||||
"typeRichText": "نص منسق",
|
||||
"typeChecklist": "قائمة مراجعة",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "اكتب ملاحظة...",
|
||||
"switchTypeTitle": "تغيير نوع الملاحظة؟",
|
||||
"switchTypeWarning": "قد يفقد بعض التنسيق عند التحويل إلى {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Rich Text",
|
||||
"typeChecklist": "Checkliste",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Notiz erstellen...",
|
||||
"switchTypeTitle": "Notiztyp ändern?",
|
||||
"switchTypeWarning": "Formatierung kann beim Wechsel zu {type} verloren gehen.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Rich Text",
|
||||
"typeChecklist": "Checklist",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Take a note...",
|
||||
"switchTypeTitle": "Switch note type?",
|
||||
"switchTypeWarning": "Some formatting may be lost when switching to {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Texto enriquecido",
|
||||
"typeChecklist": "Lista de tareas",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Escribe una nota...",
|
||||
"switchTypeTitle": "¿Cambiar tipo de nota?",
|
||||
"switchTypeWarning": "Se puede perder formato al cambiar a {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "مارکداون",
|
||||
"typeRichText": "متن غنی",
|
||||
"typeChecklist": "چکلیست",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "یادداشتی بنویسید...",
|
||||
"switchTypeTitle": "نوع یادداشت تغییر کند؟",
|
||||
"switchTypeWarning": "هنگام تغییر به {type} ممکن است برخی قالببندیها از بین بروند.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Texte riche",
|
||||
"typeChecklist": "Liste de tâches",
|
||||
"convertedToRichText": "Converti en texte enrichi",
|
||||
"conversionFailed": "Échec de la conversion, reste en Markdown",
|
||||
"richTextPlaceholder": "Prenez une note...",
|
||||
"switchTypeTitle": "Changer le type de note ?",
|
||||
"switchTypeWarning": "Certaines mises en forme peuvent être perdues lors du passage en {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "मार्कडाउन",
|
||||
"typeRichText": "रिच टेक्स्ट",
|
||||
"typeChecklist": "चेकलिस्ट",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "एक नोट लिखें...",
|
||||
"switchTypeTitle": "नोट प्रकार बदलें?",
|
||||
"switchTypeWarning": "{type} में बदलने पर कुछ फ़ॉर्मेटिंग खो सकती है।",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Testo formattato",
|
||||
"typeChecklist": "Lista di controllo",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Prendi una nota...",
|
||||
"switchTypeTitle": "Cambiare tipo di nota?",
|
||||
"switchTypeWarning": "Alcune formattazioni potrebbero andare perse con {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "リッチテキスト",
|
||||
"typeChecklist": "チェックリスト",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "メモを取る...",
|
||||
"switchTypeTitle": "ノートタイプを切り替えますか?",
|
||||
"switchTypeWarning": "{type} に切り替えると書式が失われる場合があります。",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "리치 텍스트",
|
||||
"typeChecklist": "체크리스트",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "노트를 작성하세요...",
|
||||
"switchTypeTitle": "노트 유형을 변경하시겠습니까?",
|
||||
"switchTypeWarning": "{type}(으)로 전환하면 일부 서식이 손실될 수 있습니다.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Rich Text",
|
||||
"typeChecklist": "Checklist",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Maak een notitie...",
|
||||
"switchTypeTitle": "Notitietype wijzigen?",
|
||||
"switchTypeWarning": "Opmaak kan verloren gaan bij wijziging naar {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Tekst sformatowany",
|
||||
"typeChecklist": "Lista kontrolna",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Zrób notatkę...",
|
||||
"switchTypeTitle": "Zmienić typ notatki?",
|
||||
"switchTypeWarning": "Niektóre formatowanie może zostać utracone przy zmianie na {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Texto rico",
|
||||
"typeChecklist": "Lista de verificação",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Tome uma nota...",
|
||||
"switchTypeTitle": "Alterar tipo de nota?",
|
||||
"switchTypeWarning": "Alguma formatação pode ser perdida ao mudar para {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "Форматированный текст",
|
||||
"typeChecklist": "Чек-лист",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "Сделайте заметку...",
|
||||
"switchTypeTitle": "Сменить тип заметки?",
|
||||
"switchTypeWarning": "Некоторое форматирование может быть потеряно при смене на {type}.",
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
"typeMarkdown": "Markdown",
|
||||
"typeRichText": "富文本",
|
||||
"typeChecklist": "待办清单",
|
||||
"convertedToRichText": "Converted to rich text",
|
||||
"conversionFailed": "Conversion failed, staying in Markdown",
|
||||
"richTextPlaceholder": "记笔记...",
|
||||
"switchTypeTitle": "切换笔记类型?",
|
||||
"switchTypeWarning": "切换到 {type} 可能会丢失部分格式。",
|
||||
|
||||
Reference in New Issue
Block a user