From 4defebc4ceef4e65e49aa619160c7fa0edc3c913 Mon Sep 17 00:00:00 2001 From: shatfield4 Date: Tue, 6 Feb 2024 11:39:44 -0800 Subject: [PATCH 1/4] use filter instead of ref to delete row from workspace chat component on delete/fix backend invalid json error --- .../src/pages/GeneralSettings/Chats/ChatRow/index.jsx | 10 +++------- frontend/src/pages/GeneralSettings/Chats/index.jsx | 8 +++++++- server/endpoints/system.js | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx b/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx index 3056e765938..a4cd3c1bcd0 100644 --- a/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx +++ b/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx @@ -5,8 +5,7 @@ import System from "@/models/system"; import ModalWrapper from "@/components/ModalWrapper"; import { useModal } from "@/hooks/useModal"; -export default function ChatRow({ chat }) { - const rowRef = useRef(null); +export default function ChatRow({ chat, onDelete }) { const { isOpen: isPromptOpen, openModal: openPromptModal, @@ -25,16 +24,13 @@ export default function ChatRow({ chat }) { ) ) return false; - rowRef?.current?.remove(); await System.deleteChat(chat.id); + onDelete(chat.id); }; return ( <> - + {chat.id} diff --git a/frontend/src/pages/GeneralSettings/Chats/index.jsx b/frontend/src/pages/GeneralSettings/Chats/index.jsx index f0ae8e97356..336aadccea3 100644 --- a/frontend/src/pages/GeneralSettings/Chats/index.jsx +++ b/frontend/src/pages/GeneralSettings/Chats/index.jsx @@ -142,6 +142,10 @@ function ChatsContainer() { setOffset(offset + 1); }; + const handleDeleteChat = (chatId) => { + setChats((prevChats) => prevChats.filter((chat) => chat.id !== chatId)); + }; + useEffect(() => { async function fetchChats() { const { chats: _chats, hasPages = false } = await System.chats(offset); @@ -196,7 +200,9 @@ function ChatsContainer() { {!!chats && - chats.map((chat) => )} + chats.map((chat) => ( + + ))}
diff --git a/server/endpoints/system.js b/server/endpoints/system.js index 4eb82fb0ac1..1b1b8ea9e36 100644 --- a/server/endpoints/system.js +++ b/server/endpoints/system.js @@ -774,7 +774,7 @@ function systemEndpoints(app) { try { const { id } = request.params; await WorkspaceChats.delete({ id: Number(id) }); - response.sendStatus(200).end(); + response.json({ success: true }); } catch (e) { console.error(e); response.sendStatus(500).end(); From a7154353bbb2d7e10928a4c24e698e6c205fa310 Mon Sep 17 00:00:00 2001 From: shatfield4 Date: Tue, 6 Feb 2024 12:43:10 -0800 Subject: [PATCH 2/4] remove ref from pagination on embed chats and fix white screen bug --- .../src/pages/GeneralSettings/Chats/ChatRow/index.jsx | 1 - .../pages/GeneralSettings/EmbedChats/ChatRow/index.jsx | 10 +++------- .../src/pages/GeneralSettings/EmbedChats/index.jsx | 8 +++++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx b/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx index a4cd3c1bcd0..5c0744f12f3 100644 --- a/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx +++ b/frontend/src/pages/GeneralSettings/Chats/ChatRow/index.jsx @@ -1,4 +1,3 @@ -import { useRef } from "react"; import truncate from "truncate"; import { X, Trash } from "@phosphor-icons/react"; import System from "@/models/system"; diff --git a/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx b/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx index cc0bc2a83a9..96f66d69510 100644 --- a/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx +++ b/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx @@ -6,8 +6,7 @@ import { useModal } from "@/hooks/useModal"; import paths from "@/utils/paths"; import Embed from "@/models/embed"; -export default function ChatRow({ chat }) { - const rowRef = useRef(null); +export default function ChatRow({ chat, onDelete }) { const { isOpen: isPromptOpen, openModal: openPromptModal, @@ -26,16 +25,13 @@ export default function ChatRow({ chat }) { ) ) return false; - rowRef?.current?.remove(); await Embed.deleteChat(chat.id); + onDelete(chat.id); }; return ( <> - + { + setChats((prevChats) => prevChats.filter((chat) => chat.id !== chatId)); + }; + useEffect(() => { async function fetchChats() { const { chats: _chats, hasPages = false } = await Embed.chats(offset); @@ -99,7 +103,9 @@ function ChatsContainer() { {!!chats && - chats.map((chat) => )} + chats.map((chat) => ( + + ))}
From 9519725324fba1904dc0501dea68f47959c8bd96 Mon Sep 17 00:00:00 2001 From: shatfield4 Date: Tue, 6 Feb 2024 12:44:55 -0800 Subject: [PATCH 3/4] remove unneeded import --- frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx b/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx index 96f66d69510..a9c125cf4fa 100644 --- a/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx +++ b/frontend/src/pages/GeneralSettings/EmbedChats/ChatRow/index.jsx @@ -1,4 +1,3 @@ -import { useRef } from "react"; import truncate from "truncate"; import { X, Trash, LinkSimple } from "@phosphor-icons/react"; import ModalWrapper from "@/components/ModalWrapper"; From 129c9e37d903c6c3a6c59e1bae79430b8f301786 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Tue, 6 Feb 2024 13:11:27 -0800 Subject: [PATCH 4/4] normalize response object --- server/endpoints/system.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/endpoints/system.js b/server/endpoints/system.js index 1b1b8ea9e36..100d0a4b68f 100644 --- a/server/endpoints/system.js +++ b/server/endpoints/system.js @@ -774,7 +774,7 @@ function systemEndpoints(app) { try { const { id } = request.params; await WorkspaceChats.delete({ id: Number(id) }); - response.json({ success: true }); + response.json({ success: true, error: null }); } catch (e) { console.error(e); response.sendStatus(500).end();