From 8ee77956e84240f2b4116429531388373acedf70 Mon Sep 17 00:00:00 2001 From: Sepehr Ramezani Date: Fri, 1 May 2026 16:50:51 +0200 Subject: [PATCH] fix: markdown-to-richtext conversion failure prevents type switch - 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 --- .../components/note-inline-editor.tsx | 19 ++++++++++++------- memento-note/locales/ar.json | 2 ++ memento-note/locales/de.json | 2 ++ memento-note/locales/en.json | 2 ++ memento-note/locales/es.json | 2 ++ memento-note/locales/fa.json | 2 ++ memento-note/locales/fr.json | 2 ++ memento-note/locales/hi.json | 2 ++ memento-note/locales/it.json | 2 ++ memento-note/locales/ja.json | 2 ++ memento-note/locales/ko.json | 2 ++ memento-note/locales/nl.json | 2 ++ memento-note/locales/pl.json | 2 ++ memento-note/locales/pt.json | 2 ++ memento-note/locales/ru.json | 2 ++ memento-note/locales/zh.json | 2 ++ 16 files changed, 42 insertions(+), 7 deletions(-) diff --git a/memento-note/components/note-inline-editor.tsx b/memento-note/components/note-inline-editor.tsx index b09c4e8..e5dcaa5 100644 --- a/memento-note/components/note-inline-editor.tsx +++ b/memento-note/components/note-inline-editor.tsx @@ -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, diff --git a/memento-note/locales/ar.json b/memento-note/locales/ar.json index d5d0c9d..9e54181 100644 --- a/memento-note/locales/ar.json +++ b/memento-note/locales/ar.json @@ -207,6 +207,8 @@ "typeMarkdown": "ماركداون", "typeRichText": "نص منسق", "typeChecklist": "قائمة مراجعة", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "اكتب ملاحظة...", "switchTypeTitle": "تغيير نوع الملاحظة؟", "switchTypeWarning": "قد يفقد بعض التنسيق عند التحويل إلى {type}.", diff --git a/memento-note/locales/de.json b/memento-note/locales/de.json index a6cf0ac..a590db7 100644 --- a/memento-note/locales/de.json +++ b/memento-note/locales/de.json @@ -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.", diff --git a/memento-note/locales/en.json b/memento-note/locales/en.json index 528a2b3..951f554 100644 --- a/memento-note/locales/en.json +++ b/memento-note/locales/en.json @@ -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}.", diff --git a/memento-note/locales/es.json b/memento-note/locales/es.json index 3ab8c97..3978769 100644 --- a/memento-note/locales/es.json +++ b/memento-note/locales/es.json @@ -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}.", diff --git a/memento-note/locales/fa.json b/memento-note/locales/fa.json index 83e7534..1aa2f4f 100644 --- a/memento-note/locales/fa.json +++ b/memento-note/locales/fa.json @@ -207,6 +207,8 @@ "typeMarkdown": "مارکداون", "typeRichText": "متن غنی", "typeChecklist": "چک‌لیست", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "یادداشتی بنویسید...", "switchTypeTitle": "نوع یادداشت تغییر کند؟", "switchTypeWarning": "هنگام تغییر به {type} ممکن است برخی قالب‌بندی‌ها از بین بروند.", diff --git a/memento-note/locales/fr.json b/memento-note/locales/fr.json index e3728e5..fc452d8 100644 --- a/memento-note/locales/fr.json +++ b/memento-note/locales/fr.json @@ -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}.", diff --git a/memento-note/locales/hi.json b/memento-note/locales/hi.json index 18c8112..852e0c0 100644 --- a/memento-note/locales/hi.json +++ b/memento-note/locales/hi.json @@ -207,6 +207,8 @@ "typeMarkdown": "मार्कडाउन", "typeRichText": "रिच टेक्स्ट", "typeChecklist": "चेकलिस्ट", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "एक नोट लिखें...", "switchTypeTitle": "नोट प्रकार बदलें?", "switchTypeWarning": "{type} में बदलने पर कुछ फ़ॉर्मेटिंग खो सकती है।", diff --git a/memento-note/locales/it.json b/memento-note/locales/it.json index 4448763..f2b5637 100644 --- a/memento-note/locales/it.json +++ b/memento-note/locales/it.json @@ -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}.", diff --git a/memento-note/locales/ja.json b/memento-note/locales/ja.json index b63bc5b..0cbf426 100644 --- a/memento-note/locales/ja.json +++ b/memento-note/locales/ja.json @@ -207,6 +207,8 @@ "typeMarkdown": "Markdown", "typeRichText": "リッチテキスト", "typeChecklist": "チェックリスト", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "メモを取る...", "switchTypeTitle": "ノートタイプを切り替えますか?", "switchTypeWarning": "{type} に切り替えると書式が失われる場合があります。", diff --git a/memento-note/locales/ko.json b/memento-note/locales/ko.json index 1a35e99..53f0f24 100644 --- a/memento-note/locales/ko.json +++ b/memento-note/locales/ko.json @@ -207,6 +207,8 @@ "typeMarkdown": "Markdown", "typeRichText": "리치 텍스트", "typeChecklist": "체크리스트", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "노트를 작성하세요...", "switchTypeTitle": "노트 유형을 변경하시겠습니까?", "switchTypeWarning": "{type}(으)로 전환하면 일부 서식이 손실될 수 있습니다.", diff --git a/memento-note/locales/nl.json b/memento-note/locales/nl.json index 81b02fc..c12e3b8 100644 --- a/memento-note/locales/nl.json +++ b/memento-note/locales/nl.json @@ -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}.", diff --git a/memento-note/locales/pl.json b/memento-note/locales/pl.json index b63ce57..c88aa19 100644 --- a/memento-note/locales/pl.json +++ b/memento-note/locales/pl.json @@ -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}.", diff --git a/memento-note/locales/pt.json b/memento-note/locales/pt.json index 5b14597..6df148c 100644 --- a/memento-note/locales/pt.json +++ b/memento-note/locales/pt.json @@ -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}.", diff --git a/memento-note/locales/ru.json b/memento-note/locales/ru.json index e19358f..f392eb6 100644 --- a/memento-note/locales/ru.json +++ b/memento-note/locales/ru.json @@ -207,6 +207,8 @@ "typeMarkdown": "Markdown", "typeRichText": "Форматированный текст", "typeChecklist": "Чек-лист", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "Сделайте заметку...", "switchTypeTitle": "Сменить тип заметки?", "switchTypeWarning": "Некоторое форматирование может быть потеряно при смене на {type}.", diff --git a/memento-note/locales/zh.json b/memento-note/locales/zh.json index 54a6314..0ee6bf4 100644 --- a/memento-note/locales/zh.json +++ b/memento-note/locales/zh.json @@ -207,6 +207,8 @@ "typeMarkdown": "Markdown", "typeRichText": "富文本", "typeChecklist": "待办清单", + "convertedToRichText": "Converted to rich text", + "conversionFailed": "Conversion failed, staying in Markdown", "richTextPlaceholder": "记笔记...", "switchTypeTitle": "切换笔记类型?", "switchTypeWarning": "切换到 {type} 可能会丢失部分格式。",