dev: 复制会话id按钮和跳转新会话的按钮
This commit is contained in:
parent
cb56507767
commit
f209057b18
|
|
@ -3,6 +3,7 @@
|
||||||
import { MessageSquarePlus } from "lucide-react";
|
import { MessageSquarePlus } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
|
|
@ -11,14 +12,34 @@ import {
|
||||||
SidebarTrigger,
|
SidebarTrigger,
|
||||||
useSidebar,
|
useSidebar,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
|
import { useThreadChat } from "@/components/workspace/chats";
|
||||||
import { useI18n } from "@/core/i18n/hooks";
|
import { useI18n } from "@/core/i18n/hooks";
|
||||||
|
import { POST_MESSAGE_TYPES, sendToParent } from "@/core/iframe-messages";
|
||||||
import { env } from "@/env";
|
import { env } from "@/env";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { copyToClipboard } from "@/lib/utils";
|
||||||
|
|
||||||
export function WorkspaceHeader({ className }: { className?: string }) {
|
export function WorkspaceHeader({ className }: { className?: string }) {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { state } = useSidebar();
|
const { state } = useSidebar();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
const { threadId } = useThreadChat();
|
||||||
|
const threadUrl = threadId ? `/workspace/chats/${threadId}` : "";
|
||||||
|
|
||||||
|
const handleCopyThreadId = async () => {
|
||||||
|
if (!threadId) return;
|
||||||
|
sendToParent({
|
||||||
|
type: POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD,
|
||||||
|
text: threadId,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await copyToClipboard(threadId);
|
||||||
|
toast.success(t.clipboard.copiedToClipboard);
|
||||||
|
} catch {
|
||||||
|
toast.error(t.clipboard.failedToCopyToClipboard);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
|
|
@ -43,7 +64,33 @@ export function WorkspaceHeader({ className }: { className?: string }) {
|
||||||
) : (
|
) : (
|
||||||
<div className="text-primary ml-2 cursor-default font-serif">
|
<div className="text-primary ml-2 cursor-default font-serif">
|
||||||
{/* TODO: 测试标识 */}
|
{/* TODO: 测试标识 */}
|
||||||
XClaw <span className="text-sm text-ws-text-subtle-strong">v3.2.9</span>
|
XClaw{" "}
|
||||||
|
<span className="text-sm text-ws-text-subtle-strong">v3.2.9 </span>{" "}
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"text-xs font-mono",
|
||||||
|
threadId
|
||||||
|
? "cursor-pointer underline decoration-dotted underline-offset-4"
|
||||||
|
: "text-ws-text-subtle-strong",
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
void handleCopyThreadId();
|
||||||
|
}}
|
||||||
|
title={threadId ? t.clipboard.copyToClipboard : undefined}
|
||||||
|
>
|
||||||
|
id:{threadId ? threadId.slice(0, 5) : "-"}
|
||||||
|
</span>
|
||||||
|
{" "}
|
||||||
|
{threadId && (
|
||||||
|
<a
|
||||||
|
href={threadUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-xs underline decoration-dotted underline-offset-4"
|
||||||
|
>
|
||||||
|
打开
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<SidebarTrigger />
|
<SidebarTrigger />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue