From 4639d675c2beeb7cb24f6d21017be5d4e123d632 Mon Sep 17 00:00:00 2001 From: cdxker Date: Tue, 8 Oct 2024 14:52:16 -0700 Subject: [PATCH] feature: clone topic in chat frontend --- .../chat/src/components/Navbar/Sidebar.tsx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/frontends/chat/src/components/Navbar/Sidebar.tsx b/frontends/chat/src/components/Navbar/Sidebar.tsx index dc6bbf2cf6..e9f295a05b 100644 --- a/frontends/chat/src/components/Navbar/Sidebar.tsx +++ b/frontends/chat/src/components/Navbar/Sidebar.tsx @@ -5,6 +5,7 @@ import { BiRegularPlus, BiRegularTrash, BiRegularX, + BiRegularDuplicate, } from "solid-icons/bi"; import { Accessor, @@ -81,6 +82,35 @@ export const Sidebar = (props: SidebarProps) => { await props.refetchTopics(); }; + const cloneTopic = async () => { + const dataset = userContext.currentDataset?.(); + if (!dataset) return; + + + const res = await fetch(`${apiHost}/topic/clone`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "TR-Dataset": dataset.dataset.id, + }, + body: JSON.stringify({ + topic_id: props.currentTopic()?.id, + owner_id: userContext.user?.()?.id, + }), + credentials: "include", + }); + + if (res.ok) { + await props.refetchTopics(); + } else { + createToast({ + type: "error", + message: "Error deleting topic", + }); + return; + } + }; + const deleteSelected = async () => { const dataset = userContext.currentDataset?.(); if (!dataset) return; @@ -218,6 +248,16 @@ export const Sidebar = (props: SidebarProps) => {
{props.currentTopic()?.id === topic.id && (
+ @@ -234,6 +275,7 @@ export const Sidebar = (props: SidebarProps) => { void deleteSelected(); }} class="text-lg hover:text-red-500" + title="Delete chat" >