Merge pull request #7 from DayuanJiang/feature/toggle-chat-panel

feat: add show/hide chat panel with Ctrl+B shortcut
This commit is contained in:
Dayuan Jiang
2025-11-15 12:16:43 +09:00
committed by GitHub
2 changed files with 73 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ import { useDiagram } from "@/contexts/diagram-context";
export default function Home() {
const { drawioRef, handleDiagramExport } = useDiagram();
const [isMobile, setIsMobile] = useState(false);
const [isChatVisible, setIsChatVisible] = useState(true);
useEffect(() => {
const checkMobile = () => {
@@ -23,6 +24,22 @@ export default function Home() {
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) {
return (
<div className="flex items-center justify-center h-screen bg-gray-100">
@@ -37,7 +54,7 @@ export default function Home() {
return (
<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
ref={drawioRef}
onExport={handleDiagramExport}
@@ -49,8 +66,11 @@ export default function Home() {
}}
/>
</div>
<div className="w-1/3 h-full p-1">
<ChatPanel />
<div className={`${isChatVisible ? 'w-1/3' : 'w-12'} h-full p-1 transition-all duration-300 ease-in-out`}>
<ChatPanel
isVisible={isChatVisible}
onToggleVisibility={() => setIsChatVisible(!isChatVisible)}
/>
</div>
</div>
);

View File

@@ -3,6 +3,7 @@
import type React from "react";
import { useRef, useEffect, useState } from "react";
import { FaGithub } from "react-icons/fa";
import { PanelRightClose, PanelRightOpen } from "lucide-react";
import {
Card,
@@ -17,8 +18,14 @@ import { ChatInput } from "@/components/chat-input";
import { ChatMessageDisplay } from "./chat-message-display";
import { useDiagram } from "@/contexts/diagram-context";
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 {
loadDiagram: onDisplayChart,
handleExport: onExport,
@@ -187,18 +194,51 @@ Please retry with an adjusted search pattern or use display_diagram if retries a
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 (
<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>
<a
href="https://github.com/DayuanJiang/next-ai-draw-io"
target="_blank"
rel="noopener noreferrer"
className="text-gray-600 hover:text-gray-900 transition-colors"
>
<FaGithub className="w-6 h-6" />
</a>
<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
href="https://github.com/DayuanJiang/next-ai-draw-io"
target="_blank"
rel="noopener noreferrer"
className="text-gray-600 hover:text-gray-900 transition-colors"
>
<FaGithub className="w-6 h-6" />
</a>
</div>
</CardHeader>
<CardContent className="flex-grow overflow-hidden px-2">
<ChatMessageDisplay