From b133e8fbe27db5e69cf8f1e75fe2d5e14381f3d4 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 10 Jul 2026 11:56:22 -0500 Subject: [PATCH] refac --- .../components/SidebarWorkspaceList.svelte | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/cptr/frontend/src/lib/components/SidebarWorkspaceList.svelte b/cptr/frontend/src/lib/components/SidebarWorkspaceList.svelte index 98d3a23..6275a49 100644 --- a/cptr/frontend/src/lib/components/SidebarWorkspaceList.svelte +++ b/cptr/frontend/src/lib/components/SidebarWorkspaceList.svelte @@ -4,7 +4,12 @@ import { workspaceList, removeWorkspace, reorderWorkspaces, sidebarOpen } from '$lib/stores'; import { chatEnabled } from '$lib/stores/chat'; import { socketStore } from '$lib/stores/socket.svelte'; - import { deleteChat as apiDeleteChat, getChats, type ChatInfo } from '$lib/apis/chat'; + import { + deleteChat as apiDeleteChat, + getChats, + updateChatTitle, + type ChatInfo + } from '$lib/apis/chat'; import { t } from '$lib/i18n'; import { tooltip } from '$lib/tooltip'; import Sortable from 'sortablejs'; @@ -123,6 +128,30 @@ } } + async function handleRenameChat() { + if (!chatMenu) return; + const { chatId, wsPath } = chatMenu; + const chat = (wsChatsCache.get(wsPath) ?? []).find((item) => item.id === chatId); + const title = window.prompt($t('files.rename'), chat?.title)?.trim(); + if (!title || title === chat?.title) return; + await updateChatTitle(chatId, title); + const chats = wsChatsCache.get(wsPath) ?? []; + wsChatsCache = new Map([ + ...wsChatsCache, + [wsPath, chats.map((item) => (item.id === chatId ? { ...item, title } : item))] + ]); + } + + function copyChatPath() { + if (!chatMenu) return; + const { chatId, wsPath } = chatMenu; + const chat = (wsChatsCache.get(wsPath) ?? []).find((item) => item.id === chatId); + if (!chat) return; + navigator.clipboard.writeText( + `${wsPath.replace(/\/$/, '')}/.cptr/chats/${chat.folder ? `${chat.folder}/` : ''}${chat.id}.json` + ); + } + const seenChatIds = new Set(); function handleChatEvent(data: { @@ -301,6 +330,16 @@ anchor={chatMenu.anchor} align="end" items={[ + { + label: $t('files.copyPath'), + icon: 'copy', + onclick: copyChatPath + }, + { + label: $t('files.rename'), + icon: 'pencil', + onclick: handleRenameChat + }, { label: $t('chat.history.delete'), icon: 'trash',