Skip to content

Commit 20174b1

Browse files
committed
feat: Enables editing of conversation names
Allows users to rename existing conversations in the chat sidebar. This change introduces an edit dialog to the conversation item, allowing users to input a new name for the conversation. The name is then updated in the store.
1 parent 5de7bc6 commit 20174b1

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

tools/server/webui/src/lib/components/app/chat/ChatSidebar/ChatSidebar.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
33
import { ChatSidebarConversationItem } from '$lib/components/app';
4-
import { conversations, deleteConversation } from '$lib/stores/chat.svelte';
4+
import { conversations, deleteConversation, updateConversationName } from '$lib/stores/chat.svelte';
55
import { goto } from '$app/navigation';
66
import { page } from '$app/state';
77
import { useSidebar } from '$lib/components/ui/sidebar';
@@ -28,8 +28,8 @@
2828
return conversations();
2929
});
3030
31-
async function editConversation(id: string) {
32-
console.log('Editing conversation:', id);
31+
async function editConversation(id: string, name: string) {
32+
await updateConversationName(id, name);
3333
}
3434
3535
async function handleDeleteConversation(id: string) {

tools/server/webui/src/lib/components/app/chat/ChatSidebar/ChatSidebarConversationItem.svelte

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<script lang="ts">
22
import * as AlertDialog from '$lib/components/ui/alert-dialog';
33
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
4+
import Input from '$lib/components/ui/input/input.svelte';
45
import { Trash2, Pencil, MoreHorizontal } from '@lucide/svelte';
56
67
interface Props {
78
conversation: DatabaseConversation;
89
isActive?: boolean;
910
onSelect?: (id: string) => void;
10-
onEdit?: (id: string) => void;
11+
onEdit?: (id: string, name: string) => void;
1112
onDelete?: (id: string) => void;
1213
showLastModified?: boolean;
1314
}
@@ -22,7 +23,9 @@
2223
}: Props = $props();
2324
2425
let showDeleteDialog = $state(false);
26+
let showEditDialog = $state(false);
2527
let showDropdown = $state(false);
28+
let editedName = $state('');
2629
2730
function formatLastModified(timestamp: number) {
2831
const now = Date.now();
@@ -43,7 +46,13 @@
4346
4447
function handleEdit(event: Event) {
4548
event.stopPropagation();
46-
onEdit?.(conversation.id);
49+
editedName = conversation.name;
50+
showEditDialog = true;
51+
}
52+
53+
function handleConfirmEdit() {
54+
if (!editedName.trim()) return;
55+
onEdit?.(conversation.id, editedName);
4756
}
4857
4958
function handleConfirmDelete() {
@@ -123,6 +132,33 @@
123132
</AlertDialog.Footer>
124133
</AlertDialog.Content>
125134
</AlertDialog.Root>
135+
136+
<AlertDialog.Root bind:open={showEditDialog}>
137+
<AlertDialog.Content>
138+
<AlertDialog.Header>
139+
<AlertDialog.Title>Edit Conversation Name</AlertDialog.Title>
140+
<AlertDialog.Description>
141+
<Input
142+
class="mt-4 text-foreground"
143+
onkeydown={(e) => {
144+
if (e.key === 'Enter') {
145+
e.preventDefault();
146+
handleConfirmEdit();
147+
showEditDialog = false;
148+
}
149+
}}
150+
placeholder="Enter a new name"
151+
type="text"
152+
bind:value={editedName}
153+
/>
154+
</AlertDialog.Description>
155+
</AlertDialog.Header>
156+
<AlertDialog.Footer>
157+
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
158+
<AlertDialog.Action onclick={handleConfirmEdit}>Save</AlertDialog.Action>
159+
</AlertDialog.Footer>
160+
</AlertDialog.Content>
161+
</AlertDialog.Root>
126162
</div>
127163
</button>
128164

0 commit comments

Comments
 (0)