refactor(Index.tsx): simplify tag update logic and improve debounced tag generation

This commit is contained in:
2025-08-29 11:47:27 +02:00
parent 4eba612a38
commit 10d005dd74

View File

@@ -288,13 +288,9 @@ Keep tags concise, use lowercase, and separate words with hyphens if needed.`);
addDebugInfo('Auto-generating tags...');
const tags = await generateTags(content, noteIndex);
if (noteIndex !== undefined) {
// For existing notes
const note = noteCache[noteIndex];
if (note) {
const updatedNote = { ...note, tags };
setPreviousNote(updatedNote);
// For existing notes - preserve current content from state
setPreviousNote(prev => prev ? { ...prev, tags } : null);
setIsPreviousNoteModified(true);
}
} else {
// For current note
setCurrentNoteTags(tags);
@@ -303,7 +299,7 @@ Keep tags concise, use lowercase, and separate words with hyphens if needed.`);
console.error('Auto tag generation failed:', error);
}
}
}, 200);
}, 300);
setTagGenerationTimeout(timeout);
};
@@ -2059,7 +2055,10 @@ ${content}${context}`;
const updatedNote = { ...previousNote, content: newContent };
setPreviousNote(updatedNote);
setIsPreviousNoteModified(true);
// Debounced tag generation for previous notes
if (autoGenerateTags) {
debouncedGenerateTags(newContent, currentNoteIndex);
}
if (newContent.trim() === '') {
deleteNote(previousNote.id);
}