Feat: Implement temporary conversation removal logic in ConversationDropdown
This commit is contained in:
parent
4c8f9f0d77
commit
9cea04b114
3 changed files with 29 additions and 3 deletions
|
|
@ -14,16 +14,29 @@ import { useTranslation } from 'react-i18next';
|
|||
export function ConversationDropdown({
|
||||
children,
|
||||
conversation,
|
||||
removeTemporaryConversation,
|
||||
}: PropsWithChildren & {
|
||||
conversation: IConversation;
|
||||
removeTemporaryConversation?: (conversationId: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { removeConversation } = useRemoveConversation();
|
||||
|
||||
const handleDelete: MouseEventHandler<HTMLDivElement> = useCallback(() => {
|
||||
removeConversation([conversation.id]);
|
||||
}, [conversation.id, removeConversation]);
|
||||
// 如果是临时对话(is_new 为 true),则使用前端删除逻辑
|
||||
if (conversation.is_new && removeTemporaryConversation) {
|
||||
removeTemporaryConversation(conversation.id);
|
||||
removeConversation([]);
|
||||
} else {
|
||||
removeConversation([conversation.id]);
|
||||
}
|
||||
}, [
|
||||
conversation.id,
|
||||
conversation.is_new,
|
||||
removeConversation,
|
||||
removeTemporaryConversation,
|
||||
]);
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ export function Sessions({
|
|||
const {
|
||||
list: conversationList,
|
||||
addTemporaryConversation,
|
||||
removeTemporaryConversation,
|
||||
handleInputChange,
|
||||
searchString,
|
||||
} = useSelectDerivedConversationList();
|
||||
|
|
@ -97,7 +98,10 @@ export function Sessions({
|
|||
>
|
||||
<CardContent className="px-3 py-2 flex justify-between items-center group gap-1">
|
||||
<div className="truncate">{x.name}</div>
|
||||
<ConversationDropdown conversation={x}>
|
||||
<ConversationDropdown
|
||||
conversation={x}
|
||||
removeTemporaryConversation={removeTemporaryConversation}
|
||||
>
|
||||
<MoreButton></MoreButton>
|
||||
</ConversationDropdown>
|
||||
</CardContent>
|
||||
|
|
|
|||
|
|
@ -80,6 +80,14 @@ export const useSelectDerivedConversationList = () => {
|
|||
});
|
||||
}, [conversationList, dialogId, prologue, t, setNewConversationRouteParams]);
|
||||
|
||||
const removeTemporaryConversation = useCallback((conversationId: string) => {
|
||||
setList((prevList) => {
|
||||
return prevList.filter(
|
||||
(conversation) => conversation.id !== conversationId,
|
||||
);
|
||||
});
|
||||
}, []);
|
||||
|
||||
// When you first enter the page, select the top conversation card
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -89,6 +97,7 @@ export const useSelectDerivedConversationList = () => {
|
|||
return {
|
||||
list,
|
||||
addTemporaryConversation,
|
||||
removeTemporaryConversation,
|
||||
loading,
|
||||
handleInputChange,
|
||||
searchString,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue