From 9dafd9ef53b116ecf0d0c3a3e48ab6fec506183c Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Tue, 1 Aug 2023 11:05:43 +0200 Subject: [PATCH] fix update folder items --- .ui-dev/src/components/Chatbar/index.tsx | 25 ++++++++++++++++++++-- .ui-dev/src/components/Promptbar/index.tsx | 25 ++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.ui-dev/src/components/Chatbar/index.tsx b/.ui-dev/src/components/Chatbar/index.tsx index 5914681..4a624f3 100644 --- a/.ui-dev/src/components/Chatbar/index.tsx +++ b/.ui-dev/src/components/Chatbar/index.tsx @@ -127,7 +127,15 @@ const Chatbar: React.FC = ({ const list = [...items]; if (currentFolder) { - currentFolder.conversations.push(newConversation); + [...list].forEach((item, itemIndex) => { + if ('conversations' in item && item.id === currentFolder.id) { + list[itemIndex] = { + ...item, + + conversations: [...currentFolder.conversations, newConversation] + }; + } + }); } else { list.push(newConversation); } @@ -157,11 +165,24 @@ const Chatbar: React.FC = ({ }, [handleItemsUpdate, items, onConversationDelete]); const handleUpdateConversation = useCallback((newData: IChatConversation) => { - const folder = folders.find((f) => { + let folder = folders.find((f) => { return f.id === newData.folderId; }); const newList = [...items]; + if (folder) { + folder = { + ...folder, + + conversations: [...folder.conversations] + }; + + [...newList].forEach((item, itemIndex) => { + if ('conversations' in item && item.id === folder!.id) { + newList[itemIndex] = folder!; + } + }); + } const list = folder ? folder.conversations : newList; [...list].forEach((item, itemIndex) => { diff --git a/.ui-dev/src/components/Promptbar/index.tsx b/.ui-dev/src/components/Promptbar/index.tsx index 5604692..cb59bf7 100644 --- a/.ui-dev/src/components/Promptbar/index.tsx +++ b/.ui-dev/src/components/Promptbar/index.tsx @@ -94,7 +94,15 @@ const Promptbar: React.FC = ({ const list = [...items]; if (currentFolder) { - currentFolder.prompts.push(newPrompt); + [...list].forEach((item, itemIndex) => { + if ('prompts' in item && item.id === currentFolder.id) { + list[itemIndex] = { + ...item, + + prompts: [...currentFolder.prompts, newPrompt] + }; + } + }); } else { list.push(newPrompt); } @@ -108,11 +116,24 @@ const Promptbar: React.FC = ({ }, []); const handleUpdatePrompt = useCallback((newData: IChatPrompt) => { - const folder = folders.find((f) => { + let folder = folders.find((f) => { return f.id === newData.folderId; }); const newList = [...items]; + if (folder) { + folder = { + ...folder, + + prompts: [...folder.prompts] + }; + + [...newList].forEach((item, itemIndex) => { + if ('prompts' in item && item.id === folder!.id) { + newList[itemIndex] = folder!; + } + }); + } const list = folder ? folder.prompts : newList; [...list].forEach((item, itemIndex) => {