Skip to content

Commit 71c20d6

Browse files
cdxkerskeptrunedev
authored andcommitted
feature: clone topic in chat frontend
1 parent 4471cb8 commit 71c20d6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

frontends/chat/src/components/Navbar/Sidebar.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BiRegularPlus,
66
BiRegularTrash,
77
BiRegularX,
8+
BiRegularDuplicate,
89
} from "solid-icons/bi";
910
import {
1011
Accessor,
@@ -81,6 +82,34 @@ export const Sidebar = (props: SidebarProps) => {
8182
await props.refetchTopics();
8283
};
8384

85+
const cloneTopic = async () => {
86+
const dataset = userContext.currentDataset?.();
87+
if (!dataset) return;
88+
89+
const res = await fetch(`${apiHost}/topic/clone`, {
90+
method: "POST",
91+
headers: {
92+
"Content-Type": "application/json",
93+
"TR-Dataset": dataset.dataset.id,
94+
},
95+
body: JSON.stringify({
96+
topic_id: props.currentTopic()?.id,
97+
owner_id: userContext.user?.()?.id,
98+
}),
99+
credentials: "include",
100+
});
101+
102+
if (res.ok) {
103+
await props.refetchTopics();
104+
} else {
105+
createToast({
106+
type: "error",
107+
message: "Error deleting topic",
108+
});
109+
return;
110+
}
111+
};
112+
84113
const deleteSelected = async () => {
85114
const dataset = userContext.currentDataset?.();
86115
if (!dataset) return;
@@ -218,13 +247,24 @@ export const Sidebar = (props: SidebarProps) => {
218247
<div class="flex-1" />
219248
{props.currentTopic()?.id === topic.id && (
220249
<div class="flex flex-row items-center space-x-2">
250+
<button
251+
onClick={(e) => {
252+
e.preventDefault();
253+
void cloneTopic();
254+
}}
255+
class="text-lg hover:text-blue-500"
256+
title="Clone chat"
257+
>
258+
<BiRegularDuplicate />
259+
</button>
221260
<button
222261
onClick={(e) => {
223262
e.preventDefault();
224263
setEditingTopic(topic.name);
225264
setEditingIndex(index());
226265
}}
227266
class="text-lg hover:text-blue-500"
267+
title="Edit topic name"
228268
>
229269
<BiRegularEdit />
230270
</button>
@@ -234,6 +274,7 @@ export const Sidebar = (props: SidebarProps) => {
234274
void deleteSelected();
235275
}}
236276
class="text-lg hover:text-red-500"
277+
title="Delete chat"
237278
>
238279
<BiRegularTrash />
239280
</button>

0 commit comments

Comments
 (0)