Ensure expandedPromptId is valid when aiPromptTemplates change
This commit is contained in:
15
src/App.tsx
15
src/App.tsx
@@ -560,6 +560,21 @@ export default function App() {
|
||||
);
|
||||
}, [aiPromptTemplates]);
|
||||
|
||||
useEffect(() => {
|
||||
if (aiPromptTemplates.length === 0) {
|
||||
if (expandedPromptId !== null) {
|
||||
setExpandedPromptId(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
expandedPromptId === null ||
|
||||
!aiPromptTemplates.some((template) => template.id === expandedPromptId)
|
||||
) {
|
||||
setExpandedPromptId(aiPromptTemplates[0].id);
|
||||
}
|
||||
}, [aiPromptTemplates, expandedPromptId]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(
|
||||
"textdb.expandedFolders",
|
||||
|
||||
Reference in New Issue
Block a user