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...');
|
addDebugInfo('Auto-generating tags...');
|
||||||
const tags = await generateTags(content, noteIndex);
|
const tags = await generateTags(content, noteIndex);
|
||||||
if (noteIndex !== undefined) {
|
if (noteIndex !== undefined) {
|
||||||
// For existing notes
|
// For existing notes - preserve current content from state
|
||||||
const note = noteCache[noteIndex];
|
setPreviousNote(prev => prev ? { ...prev, tags } : null);
|
||||||
if (note) {
|
|
||||||
const updatedNote = { ...note, tags };
|
|
||||||
setPreviousNote(updatedNote);
|
|
||||||
setIsPreviousNoteModified(true);
|
setIsPreviousNoteModified(true);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// For current note
|
// For current note
|
||||||
setCurrentNoteTags(tags);
|
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);
|
console.error('Auto tag generation failed:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 300);
|
||||||
|
|
||||||
setTagGenerationTimeout(timeout);
|
setTagGenerationTimeout(timeout);
|
||||||
};
|
};
|
||||||
@@ -2059,7 +2055,10 @@ ${content}${context}`;
|
|||||||
const updatedNote = { ...previousNote, content: newContent };
|
const updatedNote = { ...previousNote, content: newContent };
|
||||||
setPreviousNote(updatedNote);
|
setPreviousNote(updatedNote);
|
||||||
setIsPreviousNoteModified(true);
|
setIsPreviousNoteModified(true);
|
||||||
|
// Debounced tag generation for previous notes
|
||||||
|
if (autoGenerateTags) {
|
||||||
debouncedGenerateTags(newContent, currentNoteIndex);
|
debouncedGenerateTags(newContent, currentNoteIndex);
|
||||||
|
}
|
||||||
if (newContent.trim() === '') {
|
if (newContent.trim() === '') {
|
||||||
deleteNote(previousNote.id);
|
deleteNote(previousNote.id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user