This commit is contained in:
alma 2026-01-11 23:15:15 +01:00
parent a31692f8b6
commit 8b8d2662b7

View File

@ -23,8 +23,8 @@ interface EditorProps {
} }
export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'Notes', onRefresh }) => { export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'Notes', onRefresh }) => {
const [title, setTitle] = useState(note?.title || ''); const [title, setTitle] = useState<string>(note?.title || '');
const [content, setContent] = useState(note?.content || ''); const [content, setContent] = useState<string>(note?.content || '');
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
@ -53,7 +53,7 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
const cachedContent = contentCache.current[note.id]; const cachedContent = contentCache.current[note.id];
if (cachedContent && (Date.now() - cachedContent.timestamp) < CACHE_EXPIRATION) { if (cachedContent && (Date.now() - cachedContent.timestamp) < CACHE_EXPIRATION) {
console.log(`Using cached content for note ${note.title}`); console.log(`Using cached content for note ${note.title}`);
setContent(cachedContent.content); setContent(cachedContent.content || '');
setIsLoading(false); setIsLoading(false);
return; return;
} }
@ -68,7 +68,7 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
if ((Date.now() - timestamp) < CACHE_EXPIRATION) { if ((Date.now() - timestamp) < CACHE_EXPIRATION) {
console.log(`Using localStorage cached content for note ${note.title}`); console.log(`Using localStorage cached content for note ${note.title}`);
setContent(content); setContent(content || '');
// Update in-memory cache // Update in-memory cache
contentCache.current[note.id] = { content, timestamp }; contentCache.current[note.id] = { content, timestamp };
@ -94,7 +94,7 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
throw new Error(`Failed to fetch note content: ${response.status} ${errorText}`); throw new Error(`Failed to fetch note content: ${response.status} ${errorText}`);
} }
const data = await response.json(); const data = await response.json();
setContent(data.content); setContent(data.content || '');
// Update both caches // Update both caches
const newTimestamp = Date.now(); const newTimestamp = Date.now();
@ -118,7 +118,7 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
}; };
if (note) { if (note) {
setTitle(note.title); setTitle(note.title || '');
if (note.id) { if (note.id) {
fetchNoteContent(); fetchNoteContent();
} else { } else {