Skip to content

Commit baefacd

Browse files
committed
feature: clone topic in chat frontend
1 parent c06458b commit baefacd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 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,35 @@ 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+
90+
const res = await fetch(`${apiHost}/topic/clone`, {
91+
method: "POST",
92+
headers: {
93+
"Content-Type": "application/json",
94+
"TR-Dataset": dataset.dataset.id,
95+
},
96+
body: JSON.stringify({
97+
topic_id: props.currentTopic()?.id,
98+
owner_id: userContext.user?.()?.id,
99+
}),
100+
credentials: "include",
101+
});
102+
103+
if (res.ok) {
104+
await props.refetchTopics();
105+
} else {
106+
createToast({
107+
type: "error",
108+
message: "Error deleting topic",
109+
});
110+
return;
111+
}
112+
};
113+
84114
const deleteSelected = async () => {
85115
const dataset = userContext.currentDataset?.();
86116
if (!dataset) return;
@@ -218,13 +248,24 @@ export const Sidebar = (props: SidebarProps) => {
218248
<div class="flex-1" />
219249
{props.currentTopic()?.id === topic.id && (
220250
<div class="flex flex-row items-center space-x-2">
251+
<button
252+
onClick={(e) => {
253+
e.preventDefault();
254+
cloneTopic();
255+
}}
256+
class="text-lg hover:text-blue-500"
257+
title="Clone chat"
258+
>
259+
<BiRegularDuplicate />
260+
</button>
221261
<button
222262
onClick={(e) => {
223263
e.preventDefault();
224264
setEditingTopic(topic.name);
225265
setEditingIndex(index());
226266
}}
227267
class="text-lg hover:text-blue-500"
268+
title="Edit topic name"
228269
>
229270
<BiRegularEdit />
230271
</button>
@@ -234,6 +275,7 @@ export const Sidebar = (props: SidebarProps) => {
234275
void deleteSelected();
235276
}}
236277
class="text-lg hover:text-red-500"
278+
title="Delete chat"
237279
>
238280
<BiRegularTrash />
239281
</button>

0 commit comments

Comments
 (0)