74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { useNavigate } from "react-router-dom";
|
|
import { ArrowLeft, Loader2, PanelLeftClose, PanelLeftOpen } from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Separator } from "@/components/ui/separator";
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip";
|
|
|
|
import { useCanvasThreadContext } from "../../contexts/CanvasThreadContext";
|
|
import { useCanvasGraphContext } from "../../contexts/CanvasGraphContext";
|
|
import { useCanvasUIContext } from "../../contexts/CanvasUIContext";
|
|
import { getCurrentArtifactContent } from "../../utils/artifact";
|
|
import { CanvasModelSelector } from "../selectors/CanvasModelSelector";
|
|
|
|
export function CanvasHeader() {
|
|
const navigate = useNavigate();
|
|
const { threadId } = useCanvasThreadContext();
|
|
const { artifact, isStreaming } = useCanvasGraphContext();
|
|
const { isChatCollapsed, setIsChatCollapsed } = useCanvasUIContext();
|
|
|
|
const currentContent = getCurrentArtifactContent(artifact);
|
|
const title = currentContent?.title ?? "新 Canvas";
|
|
|
|
return (
|
|
<div className="h-11 border-b flex items-center px-3 gap-2 shrink-0 bg-background">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-7 w-7 shrink-0"
|
|
onClick={() => navigate("/page/canvas")}
|
|
title="返回 Canvas 列表"
|
|
>
|
|
<ArrowLeft className="h-4 w-4" />
|
|
</Button>
|
|
|
|
<Separator orientation="vertical" className="h-4" />
|
|
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-7 w-7 shrink-0"
|
|
onClick={() => setIsChatCollapsed(!isChatCollapsed)}
|
|
>
|
|
{isChatCollapsed ? (
|
|
<PanelLeftOpen className="h-4 w-4" />
|
|
) : (
|
|
<PanelLeftClose className="h-4 w-4" />
|
|
)}
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">
|
|
{isChatCollapsed ? "展开聊天区" : "收起聊天区"}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
|
|
<Separator orientation="vertical" className="h-4" />
|
|
|
|
<div className="flex items-center gap-2 min-w-0 flex-1">
|
|
<span className="text-sm font-medium truncate">{title}</span>
|
|
{isStreaming && (
|
|
<Loader2 className="h-3.5 w-3.5 animate-spin text-muted-foreground shrink-0" />
|
|
)}
|
|
</div>
|
|
|
|
<CanvasModelSelector />
|
|
</div>
|
|
);
|
|
}
|