Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
4e4bf51b
Unverified
提交
4e4bf51b
authored
5月 02, 2025
作者:
Will Chen
提交者:
GitHub
5月 02, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete chat (#77)
上级
b9dc2cc0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
103 行增加
和
25 行删除
+103
-25
ChatList.tsx
src/components/ChatList.tsx
+78
-24
chat_handlers.ts
src/ipc/handlers/chat_handlers.ts
+11
-0
ipc_client.ts
src/ipc/ipc_client.ts
+13
-1
preload.ts
src/preload.ts
+1
-0
没有找到文件。
src/components/ChatList.tsx
浏览文件 @
4e4bf51b
...
...
@@ -2,12 +2,12 @@ import { useEffect } from "react";
import
{
useNavigate
,
useRouterState
}
from
"@tanstack/react-router"
;
import
type
{
ChatSummary
}
from
"@/lib/schemas"
;
import
{
formatDistanceToNow
}
from
"date-fns"
;
import
{
PlusCircle
}
from
"lucide-react"
;
import
{
PlusCircle
,
MoreVertical
,
Trash2
}
from
"lucide-react"
;
import
{
useAtom
}
from
"jotai"
;
import
{
selectedChatIdAtom
}
from
"@/atoms/chatAtoms"
;
import
{
selectedAppIdAtom
}
from
"@/atoms/appAtoms"
;
import
{
IpcClient
}
from
"@/ipc/ipc_client"
;
import
{
showError
}
from
"@/lib/toast"
;
import
{
showError
,
showSuccess
}
from
"@/lib/toast"
;
import
{
SidebarGroup
,
SidebarGroupContent
,
...
...
@@ -16,6 +16,12 @@ import {
SidebarMenuItem
,
}
from
"@/components/ui/sidebar"
;
import
{
Button
}
from
"@/components/ui/button"
;
import
{
DropdownMenu
,
DropdownMenuContent
,
DropdownMenuItem
,
DropdownMenuTrigger
,
}
from
"@/components/ui/dropdown-menu"
;
import
{
useChats
}
from
"@/hooks/useChats"
;
export
function
ChatList
({
show
}:
{
show
?:
boolean
})
{
...
...
@@ -82,6 +88,28 @@ export function ChatList({ show }: { show?: boolean }) {
}
};
const
handleDeleteChat
=
async
(
chatId
:
number
)
=>
{
try
{
const
result
=
await
IpcClient
.
getInstance
().
deleteChat
(
chatId
);
if
(
!
result
.
success
)
{
showError
(
"Failed to delete chat"
);
return
;
}
showSuccess
(
"Chat deleted successfully"
);
// If the deleted chat was selected, navigate to home
if
(
selectedChatId
===
chatId
)
{
setSelectedChatId
(
null
);
navigate
({
to
:
"/chat"
});
}
// Refresh the chat list
await
refreshChats
();
}
catch
(
error
)
{
showError
(
`Failed to delete chat:
${(
error
as
any
).
toString
()}
`
);
}
};
return
(
<
SidebarGroup
className=
"overflow-y-auto h-[calc(100vh-112px)]"
>
<
SidebarGroupLabel
>
Recent Chats
</
SidebarGroupLabel
>
...
...
@@ -108,28 +136,54 @@ export function ChatList({ show }: { show?: boolean }) {
<
SidebarMenu
className=
"space-y-1"
>
{
chats
.
map
((
chat
)
=>
(
<
SidebarMenuItem
key=
{
chat
.
id
}
className=
"mb-1"
>
<
Button
variant=
"ghost"
onClick=
{
()
=>
handleChatClick
({
chatId
:
chat
.
id
,
appId
:
chat
.
appId
})
}
className=
{
`justify-start w-full text-left py-3 hover:bg-sidebar-accent/80 ${
selectedChatId === chat.id
? "bg-sidebar-accent text-sidebar-accent-foreground"
: ""
}`
}
>
<
div
className=
"flex flex-col w-full"
>
<
span
className=
"truncate"
>
{
chat
.
title
||
"New Chat"
}
</
span
>
<
span
className=
"text-xs text-gray-500"
>
{
formatDistanceToNow
(
new
Date
(
chat
.
createdAt
),
{
addSuffix
:
true
,
})
}
</
span
>
</
div
>
</
Button
>
<
div
className=
"flex w-[185px] items-center"
>
<
Button
variant=
"ghost"
onClick=
{
()
=>
handleChatClick
({
chatId
:
chat
.
id
,
appId
:
chat
.
appId
})
}
className=
{
`justify-start w-full text-left py-3 pr-1 hover:bg-sidebar-accent/80 ${
selectedChatId === chat.id
? "bg-sidebar-accent text-sidebar-accent-foreground"
: ""
}`
}
>
<
div
className=
"flex flex-col w-full"
>
<
span
className=
"truncate"
>
{
chat
.
title
||
"New Chat"
}
</
span
>
<
span
className=
"text-xs text-gray-500"
>
{
formatDistanceToNow
(
new
Date
(
chat
.
createdAt
),
{
addSuffix
:
true
,
})
}
</
span
>
</
div
>
</
Button
>
{
selectedChatId
===
chat
.
id
&&
(
<
DropdownMenu
>
<
DropdownMenuTrigger
asChild
>
<
Button
variant=
"ghost"
size=
"icon"
className=
"ml-1 w-4"
onClick=
{
(
e
)
=>
e
.
stopPropagation
()
}
>
<
MoreVertical
className=
"h-4 w-4"
/>
</
Button
>
</
DropdownMenuTrigger
>
<
DropdownMenuContent
align=
"end"
>
<
DropdownMenuItem
variant=
"destructive"
onClick=
{
()
=>
handleDeleteChat
(
chat
.
id
)
}
>
<
Trash2
className=
"mr-2 h-4 w-4"
/>
<
span
>
Delete Chat
</
span
>
</
DropdownMenuItem
>
</
DropdownMenuContent
>
</
DropdownMenu
>
)
}
</
div
>
</
SidebarMenuItem
>
))
}
</
SidebarMenu
>
...
...
src/ipc/handlers/chat_handlers.ts
浏览文件 @
4e4bf51b
...
...
@@ -63,4 +63,15 @@ export function registerChatHandlers() {
return
allChats
;
}
);
ipcMain
.
handle
(
"delete-chat"
,
async
(
_
,
chatId
:
number
)
=>
{
try
{
// Delete the chat and its associated messages
await
db
.
delete
(
chats
).
where
(
eq
(
chats
.
id
,
chatId
));
return
{
success
:
true
};
}
catch
(
error
)
{
console
.
error
(
"Error deleting chat:"
,
error
);
return
{
success
:
false
,
error
:
(
error
as
Error
).
message
};
}
});
}
src/ipc/ipc_client.ts
浏览文件 @
4e4bf51b
...
...
@@ -277,7 +277,19 @@ export class IpcClient {
public
async
createChat
(
appId
:
number
):
Promise
<
number
>
{
try
{
const
chatId
=
await
this
.
ipcRenderer
.
invoke
(
"create-chat"
,
appId
);
return
chatId
;
return
chatId
as
number
;
}
catch
(
error
)
{
showError
(
error
);
throw
error
;
}
}
public
async
deleteChat
(
chatId
:
number
):
Promise
<
{
success
:
boolean
}
>
{
try
{
const
result
=
(
await
this
.
ipcRenderer
.
invoke
(
"delete-chat"
,
chatId
))
as
{
success
:
boolean
;
};
return
result
;
}
catch
(
error
)
{
showError
(
error
);
throw
error
;
...
...
src/preload.ts
浏览文件 @
4e4bf51b
...
...
@@ -56,6 +56,7 @@ const validInvokeChannels = [
"window:close"
,
"window:get-platform"
,
"upload-to-signed-url"
,
"delete-chat"
,
]
as
const
;
// Add valid receive channels
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论