61 lines
1.8 KiB
TypeScript
Raw Permalink 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 = Boolean(searchParams.get("compact"));
const isEmbed = Boolean(searchParams.get("embed"));
const hidePreview = searchParams.get("preview") === "0";
2024-02-22 20:59:20 +00:00
const previewUrl = getPreviewUrl(project, "index.html");
2024-02-20 18:03:43 +07:00
return (
<ProjectContext.Provider value={{ project, isCompact, isEmbed }}>
2024-02-20 18:03:43 +07:00
<ResizablePanelGroup
2024-03-03 18:24:00 +07:00
autoSaveId={!isEmbed ? "main-panel" : null}
2024-02-22 19:49:13 +00:00
direction={{ sm: "vertical", md: "horizontal" }}
2024-03-03 18:24:00 +07:00
className={cn("w-full !h-screen")}
2024-02-20 18:03:43 +07:00
>
<ResizablePanel
defaultSize={hidePreview ? 100 : 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>
2024-03-03 18:24:00 +07:00
<ResizableHandle withHandle={!isEmbed && !isCompact} />
2024-02-23 23:57:14 +00:00
<WebPreview
2024-02-22 19:49:13 +00:00
defaultSize={40}
defaultCollapsed={hidePreview}
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);