mirror of
https://github.com/mroxso/zelo-news.git
synced 2026-06-05 18:11:10 +02:00
Fix empty article content in edit mode by deferring editor initialization
Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com>
This commit is contained in:
@@ -64,6 +64,7 @@ export function ProfessionalBlogPostForm({ editIdentifier }: ProfessionalBlogPos
|
||||
hashtags: '',
|
||||
});
|
||||
const [showMetadata, setShowMetadata] = useState(true);
|
||||
const [isEditorReady, setIsEditorReady] = useState(false);
|
||||
|
||||
// Load existing post data when editing
|
||||
useEffect(() => {
|
||||
@@ -126,8 +127,15 @@ export function ProfessionalBlogPostForm({ editIdentifier }: ProfessionalBlogPos
|
||||
console.error('Failed to parse existing content:', error);
|
||||
}
|
||||
}
|
||||
setIsEditorReady(true);
|
||||
} else if (!editIdentifier) {
|
||||
// In create mode, editor is ready immediately
|
||||
setIsEditorReady(true);
|
||||
} else if (editIdentifier && !isLoadingPost && !existingPost) {
|
||||
// Post not found, but we should still allow rendering
|
||||
setIsEditorReady(true);
|
||||
}
|
||||
}, [existingPost, editIdentifier]);
|
||||
}, [existingPost, editIdentifier, isLoadingPost]);
|
||||
|
||||
const handleMetadataChange = (field: keyof typeof metadata, value: string) => {
|
||||
setMetadata(prev => ({ ...prev, [field]: value }));
|
||||
@@ -437,12 +445,19 @@ export function ProfessionalBlogPostForm({ editIdentifier }: ProfessionalBlogPos
|
||||
<CardTitle className="text-lg">Content</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div >
|
||||
<Editor
|
||||
editorSerializedState={editorState}
|
||||
onSerializedChange={(value) => setEditorState(value)}
|
||||
/>
|
||||
</div>
|
||||
{isEditorReady ? (
|
||||
<div >
|
||||
<Editor
|
||||
key={editIdentifier ? `edit-${editIdentifier}` : 'create'}
|
||||
editorSerializedState={editorState}
|
||||
onSerializedChange={(value) => setEditorState(value)}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-4">
|
||||
Write your article using the rich text editor. Markdown formatting is supported.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user