Skip to content

Commit

Permalink
feature: clone topic in chat frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker committed Oct 8, 2024
1 parent c06458b commit baefacd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions frontends/chat/src/components/Navbar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BiRegularPlus,
BiRegularTrash,
BiRegularX,
BiRegularDuplicate,
} from "solid-icons/bi";
import {
Accessor,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -218,13 +248,24 @@ export const Sidebar = (props: SidebarProps) => {
<div class="flex-1" />
{props.currentTopic()?.id === topic.id && (
<div class="flex flex-row items-center space-x-2">
<button
onClick={(e) => {
e.preventDefault();

Check failure on line 253 in frontends/chat/src/components/Navbar/Sidebar.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-floating-promises] Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.
cloneTopic();
}}
class="text-lg hover:text-blue-500"
title="Clone chat"
>
<BiRegularDuplicate />
</button>
<button
onClick={(e) => {
e.preventDefault();
setEditingTopic(topic.name);
setEditingIndex(index());
}}
class="text-lg hover:text-blue-500"
title="Edit topic name"
>
<BiRegularEdit />
</button>
Expand All @@ -234,6 +275,7 @@ export const Sidebar = (props: SidebarProps) => {
void deleteSelected();
}}
class="text-lg hover:text-red-500"
title="Delete chat"
>
<BiRegularTrash />
</button>
Expand Down

0 comments on commit baefacd

Please sign in to comment.