fix: carregar conteúdo da nota no editor após término do carregamento
This commit is contained in:
parent
51b70e567a
commit
a81a7ca00d
1 changed files with 24 additions and 16 deletions
|
|
@ -75,13 +75,10 @@ export const NotepadPage: React.FC = () => {
|
||||||
if (!mounted) return
|
if (!mounted) return
|
||||||
const content = note?.content || ''
|
const content = note?.content || ''
|
||||||
setInitialContent(content)
|
setInitialContent(content)
|
||||||
|
initialContentRef.current = content
|
||||||
if (note?.updatedAt) {
|
if (note?.updatedAt) {
|
||||||
setLastSavedAt(new Date(note.updatedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }))
|
setLastSavedAt(new Date(note.updatedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }))
|
||||||
}
|
}
|
||||||
if (editorRef.current) {
|
|
||||||
editorRef.current.innerHTML = content
|
|
||||||
updateStats()
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erro ao carregar bloco de notas:', err)
|
console.error('Erro ao carregar bloco de notas:', err)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -92,7 +89,18 @@ export const NotepadPage: React.FC = () => {
|
||||||
return () => {
|
return () => {
|
||||||
mounted = false
|
mounted = false
|
||||||
}
|
}
|
||||||
}, [updateStats])
|
}, [])
|
||||||
|
|
||||||
|
// Sync loaded content into the editor DOM
|
||||||
|
useEffect(() => {
|
||||||
|
if (editorRef.current && !loading) {
|
||||||
|
editorRef.current.innerHTML = initialContent
|
||||||
|
const text = editorRef.current.innerText || ''
|
||||||
|
const isEmpty = text.trim() === '' && !editorRef.current.querySelector('img, hr')
|
||||||
|
editorRef.current.setAttribute('data-empty', isEmpty ? 'true' : 'false')
|
||||||
|
updateStats()
|
||||||
|
}
|
||||||
|
}, [loading, initialContent, updateStats])
|
||||||
|
|
||||||
// Handle editor input
|
// Handle editor input
|
||||||
const handleInput = () => {
|
const handleInput = () => {
|
||||||
|
|
@ -149,6 +157,7 @@ export const NotepadPage: React.FC = () => {
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
const saved = await noteService.saveNote(content)
|
const saved = await noteService.saveNote(content)
|
||||||
setInitialContent(content)
|
setInitialContent(content)
|
||||||
|
initialContentRef.current = content
|
||||||
setIsDirty(false)
|
setIsDirty(false)
|
||||||
const timeStr = saved.updatedAt
|
const timeStr = saved.updatedAt
|
||||||
? new Date(saved.updatedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
? new Date(saved.updatedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
||||||
|
|
@ -625,21 +634,20 @@ export const NotepadPage: React.FC = () => {
|
||||||
|
|
||||||
{/* Editor Area */}
|
{/* Editor Area */}
|
||||||
<div className="flex-1 p-5 sm:p-7 relative overflow-y-auto cursor-text">
|
<div className="flex-1 p-5 sm:p-7 relative overflow-y-auto cursor-text">
|
||||||
{loading ? (
|
{loading && (
|
||||||
<div className="h-64 flex flex-col items-center justify-center gap-3 text-muted">
|
<div className="absolute inset-0 bg-surface/80 backdrop-blur-xs z-10 flex flex-col items-center justify-center gap-3 text-muted">
|
||||||
<Loader2 className="w-6 h-6 animate-spin text-brand" />
|
<Loader2 className="w-6 h-6 animate-spin text-brand" />
|
||||||
<p className="text-xs font-semibold">Carregando suas anotações...</p>
|
<p className="text-xs font-semibold">Carregando suas anotações...</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
)}
|
||||||
<div
|
<div
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
contentEditable
|
contentEditable={!loading}
|
||||||
suppressContentEditableWarning
|
suppressContentEditableWarning
|
||||||
onInput={handleInput}
|
onInput={handleInput}
|
||||||
data-placeholder="Escreva suas anotações aqui... Você pode usar a barra de ferramentas para formatar com títulos, negrito, listas e códigos."
|
data-placeholder="Escreva suas anotações aqui... Você pode usar a barra de ferramentas para formatar com títulos, negrito, listas e códigos."
|
||||||
className="notepad-editor min-h-[460px] text-base focus:outline-none"
|
className="notepad-editor min-h-[460px] text-base focus:outline-none"
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Footer Statistics Bar */}
|
{/* Footer Statistics Bar */}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue