2025-03-19 06:04:06 +00:00
|
|
|
"use client";
|
2025-12-05 22:42:39 +09:00
|
|
|
import React, { useState, useEffect, useRef } from "react";
|
2025-03-26 00:30:00 +00:00
|
|
|
import { DrawIoEmbed } from "react-drawio";
|
2025-03-25 02:24:12 +00:00
|
|
|
import ChatPanel from "@/components/chat-panel";
|
2025-03-27 08:24:17 +00:00
|
|
|
import { useDiagram } from "@/contexts/diagram-context";
|
2025-12-03 21:49:34 +09:00
|
|
|
import { Monitor } from "lucide-react";
|
2025-12-05 22:42:39 +09:00
|
|
|
import {
|
|
|
|
|
ResizablePanelGroup,
|
|
|
|
|
ResizablePanel,
|
|
|
|
|
ResizableHandle,
|
|
|
|
|
} from "@/components/ui/resizable";
|
|
|
|
|
import type { ImperativePanelHandle } from "react-resizable-panels";
|
2025-03-19 06:04:06 +00:00
|
|
|
|
2025-03-27 08:17:54 +00:00
|
|
|
export default function Home() {
|
2025-03-26 00:30:00 +00:00
|
|
|
const { drawioRef, handleDiagramExport } = useDiagram();
|
2025-11-10 09:25:56 +09:00
|
|
|
const [isMobile, setIsMobile] = useState(false);
|
2025-11-15 12:09:32 +09:00
|
|
|
const [isChatVisible, setIsChatVisible] = useState(true);
|
2025-12-05 23:10:48 +09:00
|
|
|
const [drawioUi, setDrawioUi] = useState<"min" | "sketch">(() => {
|
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
|
const saved = localStorage.getItem("drawio-theme");
|
|
|
|
|
if (saved === "min" || saved === "sketch") return saved;
|
|
|
|
|
}
|
|
|
|
|
return "min";
|
|
|
|
|
});
|
2025-12-05 22:42:39 +09:00
|
|
|
const chatPanelRef = useRef<ImperativePanelHandle>(null);
|
2025-11-10 09:25:56 +09:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const checkMobile = () => {
|
|
|
|
|
setIsMobile(window.innerWidth < 768);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
checkMobile();
|
|
|
|
|
window.addEventListener("resize", checkMobile);
|
|
|
|
|
return () => window.removeEventListener("resize", checkMobile);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-12-05 22:42:39 +09:00
|
|
|
const toggleChatPanel = () => {
|
|
|
|
|
const panel = chatPanelRef.current;
|
|
|
|
|
if (panel) {
|
|
|
|
|
if (panel.isCollapsed()) {
|
|
|
|
|
panel.expand();
|
|
|
|
|
setIsChatVisible(true);
|
|
|
|
|
} else {
|
|
|
|
|
panel.collapse();
|
|
|
|
|
setIsChatVisible(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-15 12:09:32 +09:00
|
|
|
useEffect(() => {
|
|
|
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
2025-12-05 23:10:48 +09:00
|
|
|
if ((event.ctrlKey || event.metaKey) && event.key === "b") {
|
2025-11-15 12:09:32 +09:00
|
|
|
event.preventDefault();
|
2025-12-05 22:42:39 +09:00
|
|
|
toggleChatPanel();
|
2025-11-15 12:09:32 +09:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-05 23:10:48 +09:00
|
|
|
window.addEventListener("keydown", handleKeyDown);
|
|
|
|
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
2025-11-15 12:09:32 +09:00
|
|
|
}, []);
|
|
|
|
|
|
2025-12-05 18:42:36 +09:00
|
|
|
// Show confirmation dialog when user tries to leave the page
|
|
|
|
|
// This helps prevent accidental navigation from browser back gestures
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
|
|
|
|
event.preventDefault();
|
2025-12-05 23:10:48 +09:00
|
|
|
return "";
|
2025-12-05 18:42:36 +09:00
|
|
|
};
|
|
|
|
|
|
2025-12-05 23:10:48 +09:00
|
|
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
|
|
|
return () =>
|
|
|
|
|
window.removeEventListener("beforeunload", handleBeforeUnload);
|
2025-12-05 18:42:36 +09:00
|
|
|
}, []);
|
|
|
|
|
|
2025-11-17 15:18:29 +09:00
|
|
|
return (
|
2025-12-05 22:42:39 +09:00
|
|
|
<div className="h-screen bg-background relative overflow-hidden">
|
2025-12-03 21:49:34 +09:00
|
|
|
{/* Mobile warning overlay */}
|
2025-11-17 15:18:29 +09:00
|
|
|
{isMobile && (
|
2025-12-03 21:49:34 +09:00
|
|
|
<div className="absolute inset-0 z-50 flex items-center justify-center bg-background">
|
|
|
|
|
<div className="text-center p-8 max-w-sm mx-auto animate-fade-in">
|
|
|
|
|
<div className="w-16 h-16 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto mb-6">
|
|
|
|
|
<Monitor className="w-8 h-8 text-primary" />
|
|
|
|
|
</div>
|
|
|
|
|
<h1 className="text-xl font-semibold text-foreground mb-3">
|
|
|
|
|
Desktop Required
|
2025-11-17 15:18:29 +09:00
|
|
|
</h1>
|
2025-12-03 21:49:34 +09:00
|
|
|
<p className="text-sm text-muted-foreground leading-relaxed">
|
2025-12-05 23:10:48 +09:00
|
|
|
This application works best on desktop or laptop
|
|
|
|
|
devices. Please open it on a larger screen for the
|
|
|
|
|
full experience.
|
2025-12-03 21:49:34 +09:00
|
|
|
</p>
|
2025-11-17 15:18:29 +09:00
|
|
|
</div>
|
2025-11-10 09:25:56 +09:00
|
|
|
</div>
|
2025-11-17 15:18:29 +09:00
|
|
|
)}
|
2025-03-19 08:16:44 +00:00
|
|
|
|
2025-12-05 22:42:39 +09:00
|
|
|
<ResizablePanelGroup direction="horizontal" className="h-full">
|
|
|
|
|
{/* Draw.io Canvas */}
|
|
|
|
|
<ResizablePanel defaultSize={67} minSize={30}>
|
|
|
|
|
<div className="h-full relative p-2">
|
|
|
|
|
<div className="h-full rounded-xl overflow-hidden shadow-soft-lg border border-border/30 bg-white">
|
|
|
|
|
<DrawIoEmbed
|
2025-12-05 23:10:48 +09:00
|
|
|
key={drawioUi}
|
2025-12-05 22:42:39 +09:00
|
|
|
ref={drawioRef}
|
|
|
|
|
onExport={handleDiagramExport}
|
|
|
|
|
urlParameters={{
|
2025-12-05 23:10:48 +09:00
|
|
|
ui: drawioUi,
|
2025-12-05 22:42:39 +09:00
|
|
|
spin: true,
|
|
|
|
|
libraries: false,
|
|
|
|
|
saveAndExit: false,
|
|
|
|
|
noExitBtn: true,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</ResizablePanel>
|
2025-12-03 21:49:34 +09:00
|
|
|
|
2025-12-05 22:42:39 +09:00
|
|
|
<ResizableHandle withHandle />
|
|
|
|
|
|
|
|
|
|
{/* Chat Panel */}
|
|
|
|
|
<ResizablePanel
|
|
|
|
|
ref={chatPanelRef}
|
|
|
|
|
defaultSize={33}
|
|
|
|
|
minSize={15}
|
|
|
|
|
maxSize={50}
|
|
|
|
|
collapsible
|
|
|
|
|
collapsedSize={3}
|
|
|
|
|
onCollapse={() => setIsChatVisible(false)}
|
|
|
|
|
onExpand={() => setIsChatVisible(true)}
|
|
|
|
|
>
|
|
|
|
|
<div className="h-full py-2 pr-2">
|
|
|
|
|
<ChatPanel
|
|
|
|
|
isVisible={isChatVisible}
|
|
|
|
|
onToggleVisibility={toggleChatPanel}
|
2025-12-05 23:10:48 +09:00
|
|
|
drawioUi={drawioUi}
|
|
|
|
|
onToggleDrawioUi={() => {
|
|
|
|
|
const newTheme = drawioUi === "min" ? "sketch" : "min";
|
|
|
|
|
localStorage.setItem("drawio-theme", newTheme);
|
|
|
|
|
setDrawioUi(newTheme);
|
|
|
|
|
}}
|
2025-12-05 22:42:39 +09:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</ResizablePanel>
|
|
|
|
|
</ResizablePanelGroup>
|
2025-03-27 08:24:17 +00:00
|
|
|
</div>
|
2025-03-26 00:30:00 +00:00
|
|
|
);
|
|
|
|
|
}
|