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,
|
||||
|
||||
Reference in New Issue
Block a user