mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
feat: add show/hide chat panel with Ctrl+B shortcut
- Add toggle button in chat panel header - Implement collapsed state with thin vertical strip - Add Ctrl+B keyboard shortcut to toggle visibility - Canvas expands to full width when chat is hidden - Smooth 300ms transition animation
This commit is contained in:
26
app/page.tsx
26
app/page.tsx
@@ -7,6 +7,7 @@ import { useDiagram } from "@/contexts/diagram-context";
|
|||||||
export default function Home() {
|
export default function Home() {
|
||||||
const { drawioRef, handleDiagramExport } = useDiagram();
|
const { drawioRef, handleDiagramExport } = useDiagram();
|
||||||
const [isMobile, setIsMobile] = useState(false);
|
const [isMobile, setIsMobile] = useState(false);
|
||||||
|
const [isChatVisible, setIsChatVisible] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkMobile = () => {
|
const checkMobile = () => {
|
||||||
@@ -23,6 +24,22 @@ export default function Home() {
|
|||||||
return () => window.removeEventListener("resize", checkMobile);
|
return () => window.removeEventListener("resize", checkMobile);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Add keyboard shortcut for toggling chat panel (Ctrl+B)
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key === 'b') {
|
||||||
|
event.preventDefault();
|
||||||
|
setIsChatVisible((prev) => !prev);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', handleKeyDown);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center h-screen bg-gray-100">
|
<div className="flex items-center justify-center h-screen bg-gray-100">
|
||||||
@@ -37,7 +54,7 @@ export default function Home() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-gray-100">
|
<div className="flex h-screen bg-gray-100">
|
||||||
<div className="w-2/3 p-1 h-full relative">
|
<div className={`${isChatVisible ? 'w-2/3' : 'w-full'} p-1 h-full relative transition-all duration-300 ease-in-out`}>
|
||||||
<DrawIoEmbed
|
<DrawIoEmbed
|
||||||
ref={drawioRef}
|
ref={drawioRef}
|
||||||
onExport={handleDiagramExport}
|
onExport={handleDiagramExport}
|
||||||
@@ -49,8 +66,11 @@ export default function Home() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/3 h-full p-1">
|
<div className={`${isChatVisible ? 'w-1/3' : 'w-12'} h-full p-1 transition-all duration-300 ease-in-out`}>
|
||||||
<ChatPanel />
|
<ChatPanel
|
||||||
|
isVisible={isChatVisible}
|
||||||
|
onToggleVisibility={() => setIsChatVisible(!isChatVisible)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import type React from "react";
|
import type React from "react";
|
||||||
import { useRef, useEffect, useState } from "react";
|
import { useRef, useEffect, useState } from "react";
|
||||||
import { FaGithub } from "react-icons/fa";
|
import { FaGithub } from "react-icons/fa";
|
||||||
|
import { PanelRightClose, PanelRightOpen } from "lucide-react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@@ -17,8 +18,14 @@ import { ChatInput } from "@/components/chat-input";
|
|||||||
import { ChatMessageDisplay } from "./chat-message-display";
|
import { ChatMessageDisplay } from "./chat-message-display";
|
||||||
import { useDiagram } from "@/contexts/diagram-context";
|
import { useDiagram } from "@/contexts/diagram-context";
|
||||||
import { replaceNodes, formatXML } from "@/lib/utils";
|
import { replaceNodes, formatXML } from "@/lib/utils";
|
||||||
|
import { ButtonWithTooltip } from "@/components/button-with-tooltip";
|
||||||
|
|
||||||
export default function ChatPanel() {
|
interface ChatPanelProps {
|
||||||
|
isVisible: boolean;
|
||||||
|
onToggleVisibility: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ChatPanel({ isVisible, onToggleVisibility }: ChatPanelProps) {
|
||||||
const {
|
const {
|
||||||
loadDiagram: onDisplayChart,
|
loadDiagram: onDisplayChart,
|
||||||
handleExport: onExport,
|
handleExport: onExport,
|
||||||
@@ -187,10 +194,42 @@ Please retry with an adjusted search pattern or use display_diagram if retries a
|
|||||||
setFiles(newFiles);
|
setFiles(newFiles);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Collapsed view when chat is hidden
|
||||||
|
if (!isVisible) {
|
||||||
|
return (
|
||||||
|
<Card className="h-full flex flex-col rounded-none py-0 gap-0 items-center justify-start pt-4">
|
||||||
|
<ButtonWithTooltip
|
||||||
|
tooltipContent="Show chat panel (Ctrl+B)"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={onToggleVisibility}
|
||||||
|
>
|
||||||
|
<PanelRightOpen className="h-5 w-5" />
|
||||||
|
</ButtonWithTooltip>
|
||||||
|
<div
|
||||||
|
className="text-sm text-gray-500 mt-8"
|
||||||
|
style={{ writingMode: 'vertical-rl', transform: 'rotate(180deg)' }}
|
||||||
|
>
|
||||||
|
Chat
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Full view when chat is visible
|
||||||
return (
|
return (
|
||||||
<Card className="h-full flex flex-col rounded-none py-0 gap-0">
|
<Card className="h-full flex flex-col rounded-none py-0 gap-0">
|
||||||
<CardHeader className="p-4 flex justify-between items-center">
|
<CardHeader className="p-4 flex flex-row justify-between items-center">
|
||||||
<CardTitle>Next-AI-Drawio</CardTitle>
|
<CardTitle>Next-AI-Drawio</CardTitle>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<ButtonWithTooltip
|
||||||
|
tooltipContent="Hide chat panel (Ctrl+B)"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={onToggleVisibility}
|
||||||
|
>
|
||||||
|
<PanelRightClose className="h-5 w-5" />
|
||||||
|
</ButtonWithTooltip>
|
||||||
<a
|
<a
|
||||||
href="https://github.com/DayuanJiang/next-ai-draw-io"
|
href="https://github.com/DayuanJiang/next-ai-draw-io"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -199,6 +238,7 @@ Please retry with an adjusted search pattern or use display_diagram if retries a
|
|||||||
>
|
>
|
||||||
<FaGithub className="w-6 h-6" />
|
<FaGithub className="w-6 h-6" />
|
||||||
</a>
|
</a>
|
||||||
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex-grow overflow-hidden px-2">
|
<CardContent className="flex-grow overflow-hidden px-2">
|
||||||
<ChatMessageDisplay
|
<ChatMessageDisplay
|
||||||
|
|||||||
Reference in New Issue
Block a user