66 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 Editor from "./components/editor";
2024-02-21 02:01:35 +07:00
import ProjectContext from "./context/project";
2024-02-22 20:59:20 +00:00
import { cn, getPreviewUrl } from "~/lib/utils";
import { useData, useSearchParams } from "~/renderer/hooks";
2024-02-22 19:49:13 +00:00
import { withClientOnly } from "~/renderer/client-only";
import Spinner from "~/components/ui/spinner";
2024-02-22 20:59:20 +00:00
import { Data } from "./+data";
2024-02-20 18:03:43 +07:00
2024-02-21 02:01:35 +07:00
const ViewProjectPage = () => {
2024-02-22 20:59:20 +00:00
const { project } = useData<Data>();
2024-02-21 02:01:35 +07:00
const searchParams = useSearchParams();
const isCompact =
searchParams.get("compact") === "1" || searchParams.get("embed") === "1";
2024-02-22 20:59:20 +00:00
const previewUrl = getPreviewUrl(project, "index.html");
2024-02-20 18:03:43 +07:00
return (
2024-02-22 20:59:20 +00:00
<ProjectContext.Provider value={{ project, isCompact }}>
2024-02-20 18:03:43 +07:00
<ResizablePanelGroup
autoSaveId="main-panel"
2024-02-22 19:49:13 +00:00
direction={{ sm: "vertical", md: "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
2024-02-22 19:49:13 +00:00
defaultSize={60}
2024-02-20 18:03:43 +07:00
collapsible
collapsedSize={0}
2024-02-22 19:49:13 +00:00
minSize={30}
2024-02-20 18:03:43 +07:00
>
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
2024-02-23 23:57:14 +00:00
? "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 md:rounded-lg"
2024-02-21 02:01:35 +07:00
: "bg-slate-800"
}
2024-02-20 18:03:43 +07:00
/>
2024-02-23 23:57:14 +00:00
<WebPreview
2024-02-22 19:49:13 +00:00
defaultSize={40}
2024-02-20 18:03:43 +07:00
collapsible
collapsedSize={0}
minSize={10}
2024-02-23 23:57:14 +00:00
url={previewUrl}
/>
2024-02-20 18:03:43 +07:00
</ResizablePanelGroup>
2024-02-21 02:01:35 +07:00
</ProjectContext.Provider>
2024-02-20 18:03:43 +07:00
);
};
2024-02-22 19:49:13 +00:00
const LoadingPage = () => {
return (
<div className="flex w-full h-dvh items-center justify-center">
<Spinner />
</div>
);
};
export default withClientOnly(ViewProjectPage, LoadingPage);