Skip to content

Commit 3f72ed4

Browse files
authored
Add rename and delete context menu (#29)
1 parent 703db5e commit 3f72ed4

File tree

3 files changed

+278
-46
lines changed

3 files changed

+278
-46
lines changed

src/app/chat/chat-title.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ export interface ChatTitleProps {
77
active: boolean;
88
title: string;
99
onChatSelected: (id: string | undefined) => void;
10+
onContextMenu?: (event: React.MouseEvent<HTMLDivElement>) => void;
1011
}
1112

1213
export const ChatTitle = React.forwardRef<HTMLDivElement, ChatTitleProps>(
13-
function ChatTitleInner({ id, active, title, onChatSelected }, ref) {
14+
function ChatTitleInner({ id, active, title, onChatSelected, onContextMenu }, ref) {
1415
return (
1516
<div
1617
ref={ref}
1718
onClick={() => onChatSelected(id)}
19+
onContextMenu={event => {
20+
if (onContextMenu) {
21+
event.preventDefault();
22+
onContextMenu(event);
23+
}
24+
}}
1825
className={`flex items-center px-3 py-2 rounded-md cursor-pointer text-sm transition-colors ${
1926
active
2027
? "bg-primary text-primary-foreground"

src/app/chat/page.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ export default function ChatPage() {
4343
setNewChatUserMessage(message);
4444
}, []);
4545

46+
const onDeleteChat = useCallback((chatId: string) => {
47+
setChatList(prevList => {
48+
return prevList.filter(chat => chat.id !== chatId);
49+
});
50+
if (activeChatId === chatId) {
51+
setActiveChatId(undefined);
52+
}
53+
}, [activeChatId]);
54+
4655
const onSetChatTitle = useCallback((chatId: string, title: string) => {
4756
setChatList(prevList => {
4857
return prevList.map(chat => {
@@ -154,6 +163,8 @@ export default function ChatPage() {
154163
onSwitchChat={onSwitchChat}
155164
requestChatListUpdateAsync={updateChatListDedupAsync}
156165
onChatDisplayRangeChange={onChatDisplayRangeChange}
166+
onSetChatTitle={onSetChatTitle}
167+
onDeleteChat={onDeleteChat}
157168
chatList={chatList}
158169
activeChatId={activeChatId}
159170
onHideSidebar={() => setIsSidebarVisible(false)}

0 commit comments

Comments
 (0)