Refactor title update logic in App.tsx
This commit is contained in:
18
src/App.tsx
18
src/App.tsx
@@ -947,19 +947,11 @@ export default function App() {
|
|||||||
|
|
||||||
const applyTitleUpdate = useCallback((promptId: string, nextTitle: string) => {
|
const applyTitleUpdate = useCallback((promptId: string, nextTitle: string) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
setTexts((prev) => {
|
setTexts((prev) =>
|
||||||
let updated: Text | null = null;
|
prev.map((text) =>
|
||||||
const remaining: Text[] = [];
|
text.id === promptId ? { ...text, title: nextTitle, updated_at: now } : text
|
||||||
for (const text of prev) {
|
)
|
||||||
if (text.id === promptId) {
|
);
|
||||||
updated = { ...text, title: nextTitle, updated_at: now };
|
|
||||||
} else {
|
|
||||||
remaining.push(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!updated) return prev;
|
|
||||||
return [updated, ...remaining];
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleTitleChange = useCallback(
|
const handleTitleChange = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user