2024-02-20 18:03:43 +07:00
|
|
|
"use client";
|
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
2024-02-20 18:03:43 +07:00
|
|
|
import {
|
|
|
|
ResizableHandle,
|
|
|
|
ResizablePanel,
|
|
|
|
ResizablePanelGroup,
|
|
|
|
} from "@/components/ui/resizable";
|
|
|
|
import WebPreview from "./_components/web-preview";
|
2024-02-21 02:01:35 +07:00
|
|
|
import { usePortrait } from "@/hooks/usePortrait";
|
|
|
|
import Editor from "./_components/editor";
|
|
|
|
import ProjectContext from "./context/project";
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import { useSearchParams } from "next/navigation";
|
2024-02-20 18:03:43 +07:00
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
const ViewProjectPage = () => {
|
2024-02-20 18:03:43 +07:00
|
|
|
const [isMounted, setMounted] = useState(false);
|
2024-02-21 02:01:35 +07:00
|
|
|
const isPortrait = usePortrait();
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
const isCompact =
|
|
|
|
searchParams.get("compact") === "1" || searchParams.get("embed") === "1";
|
2024-02-20 18:03:43 +07:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setMounted(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!isMounted) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-02-21 02:01:35 +07:00
|
|
|
<ProjectContext.Provider value={{ isCompact }}>
|
2024-02-20 18:03:43 +07:00
|
|
|
<ResizablePanelGroup
|
|
|
|
autoSaveId="main-panel"
|
|
|
|
direction={isPortrait ? "vertical" : "horizontal"}
|
2024-02-21 02:01:35 +07:00
|
|
|
className={cn("w-full !h-dvh", !isCompact ? "md:p-4" : "")}
|
2024-02-20 18:03:43 +07:00
|
|
|
>
|
|
|
|
<ResizablePanel
|
|
|
|
defaultSize={isPortrait ? 50 : 60}
|
|
|
|
collapsible
|
|
|
|
collapsedSize={0}
|
|
|
|
minSize={isPortrait ? 10 : 30}
|
|
|
|
>
|
2024-02-21 02:01:35 +07:00
|
|
|
<Editor />
|
2024-02-20 18:03:43 +07:00
|
|
|
</ResizablePanel>
|
|
|
|
<ResizableHandle
|
|
|
|
withHandle
|
2024-02-21 02:01:35 +07:00
|
|
|
className={
|
|
|
|
!isCompact
|
|
|
|
? "bg-slate-800 md:bg-transparent hover:bg-slate-500 transition-colors md:mx-1 w-2 md:data-[panel-group-direction=vertical]:h-2 rounded-lg"
|
|
|
|
: "bg-slate-800"
|
|
|
|
}
|
2024-02-20 18:03:43 +07:00
|
|
|
/>
|
|
|
|
<ResizablePanel
|
|
|
|
defaultSize={isPortrait ? 50 : 40}
|
|
|
|
collapsible
|
|
|
|
collapsedSize={0}
|
|
|
|
minSize={10}
|
|
|
|
>
|
2024-02-21 02:01:35 +07:00
|
|
|
<WebPreview />
|
2024-02-20 18:03:43 +07:00
|
|
|
</ResizablePanel>
|
|
|
|
</ResizablePanelGroup>
|
2024-02-21 02:01:35 +07:00
|
|
|
</ProjectContext.Provider>
|
2024-02-20 18:03:43 +07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
export default ViewProjectPage;
|