62 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-02-20 18:03:43 +07:00
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
2024-02-22 12:14:58 +00:00
} from "~/components/ui/resizable";
import WebPreview from "./components/web-preview";
import { usePortrait } from "~/hooks/usePortrait";
import Editor from "./components/editor";
2024-02-21 02:01:35 +07:00
import ProjectContext from "./context/project";
2024-02-22 12:14:58 +00:00
import { cn } from "~/lib/utils";
import { useParams, useSearchParams } from "~/renderer/hooks";
import { BASE_URL } from "~/lib/consts";
2024-02-20 18:03:43 +07:00
2024-02-21 02:01:35 +07:00
const ViewProjectPage = () => {
const isPortrait = usePortrait();
const searchParams = useSearchParams();
2024-02-22 12:14:58 +00:00
const params = useParams();
2024-02-21 02:01:35 +07:00
const isCompact =
searchParams.get("compact") === "1" || searchParams.get("embed") === "1";
2024-02-22 12:14:58 +00:00
const slug = params["slug"];
const previewUrl = BASE_URL + `/api/preview/${slug}/index.html`;
2024-02-20 18:03:43 +07:00
return (
2024-02-22 12:14:58 +00:00
<ProjectContext.Provider value={{ slug, isCompact }}>
2024-02-20 18:03:43 +07:00
<ResizablePanelGroup
autoSaveId="main-panel"
direction={isPortrait ? "vertical" : "horizontal"}
2024-02-22 12:14:58 +00:00
className={cn("w-full !h-dvh bg-slate-600", !isCompact ? "md:p-4" : "")}
2024-02-20 18:03:43 +07:00
>
<ResizablePanel
panelId={0}
2024-02-20 18:03:43 +07:00
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
panelId={1}
2024-02-20 18:03:43 +07:00
defaultSize={isPortrait ? 50 : 40}
collapsible
collapsedSize={0}
minSize={10}
>
2024-02-22 12:14:58 +00:00
<WebPreview url={previewUrl} />
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
);
};
export default ViewProjectPage;