Add duplicate assistant functionality to AssistantPage component
Implement a new feature that allows users to create a copy of an existing assistant. The duplicate is inserted after the original, with the name suffixed by "副本" and the updated timestamp. Update the state management to handle the list of assistants accordingly, and add a dropdown menu item for triggering the duplication.
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
Boxes,
|
||||
Brain,
|
||||
Check,
|
||||
Copy,
|
||||
Database,
|
||||
MessageSquareText,
|
||||
MoreHorizontal,
|
||||
@@ -296,6 +297,8 @@ export function AssistantPage() {
|
||||
voice: "晓宁",
|
||||
enableInterrupt: true,
|
||||
});
|
||||
const [assistants, setAssistants] =
|
||||
useState<AssistantListItem[]>(mockAssistants);
|
||||
const [view, setView] = useState<
|
||||
| "list"
|
||||
| "choose"
|
||||
@@ -369,7 +372,34 @@ export function AssistantPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const filteredAssistants = mockAssistants.filter((assistant) => {
|
||||
// 复制助手:在原助手之后插入一份拷贝,名称追加“副本”,并刷新更新时间
|
||||
function handleDuplicate(assistant: AssistantListItem) {
|
||||
const now = new Date();
|
||||
const pad = (value: number) => String(value).padStart(2, "0");
|
||||
const timestamp = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(
|
||||
now.getDate(),
|
||||
)} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
|
||||
|
||||
setAssistants((prev) => {
|
||||
const index = prev.findIndex((item) => item.id === assistant.id);
|
||||
const copy: AssistantListItem = {
|
||||
id: `asst_${Date.now().toString().slice(-6)}`,
|
||||
name: `${assistant.name} 副本`,
|
||||
type: assistant.type,
|
||||
updatedAt: timestamp,
|
||||
};
|
||||
|
||||
if (index === -1) {
|
||||
return [copy, ...prev];
|
||||
}
|
||||
|
||||
const next = [...prev];
|
||||
next.splice(index + 1, 0, copy);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
const filteredAssistants = assistants.filter((assistant) => {
|
||||
if (typeFilter !== "全部" && assistant.type !== typeFilter) {
|
||||
return false;
|
||||
}
|
||||
@@ -567,6 +597,13 @@ export function AssistantPage() {
|
||||
align="end"
|
||||
className="w-32 min-w-32 rounded-xl border border-hairline bg-popover p-1"
|
||||
>
|
||||
<DropdownMenuItem
|
||||
className="rounded-lg"
|
||||
onSelect={() => handleDuplicate(assistant)}
|
||||
>
|
||||
<Copy size={14} />
|
||||
复制
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
variant="destructive"
|
||||
className="rounded-lg"
|
||||
|
||||
Reference in New Issue
Block a user