refactor(Index.tsx): simplify tag update logic and improve debounced tag generation
This commit is contained in:
@@ -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);
|
||||
setIsPreviousNoteModified(true);
|
||||
}
|
||||
// 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);
|
||||
debouncedGenerateTags(newContent, currentNoteIndex);
|
||||
// Debounced tag generation for previous notes
|
||||
if (autoGenerateTags) {
|
||||
debouncedGenerateTags(newContent, currentNoteIndex);
|
||||
}
|
||||
if (newContent.trim() === '') {
|
||||
deleteNote(previousNote.id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user