45 lines
1.1 KiB
TypeScript
Raw Normal View History

"use client";
2024-04-06 19:03:04 -04:00
import dynamic from "next/dynamic";
import Loading from "@/components/editor/loading";
import { Sandbox, User } from "@/lib/types";
import { useEffect, useState } from "react";
2024-05-13 03:00:15 -07:00
import { startServer } from "@/lib/utils";
import { toast } from "sonner";
2024-05-03 13:53:21 -07:00
const CodeEditor = dynamic(() => import("@/components/editor/editor"), {
ssr: false,
loading: () => <Loading />,
});
2024-04-06 19:03:04 -04:00
export default function Editor({
2024-05-01 01:53:49 -04:00
userData,
2024-05-05 00:06:10 -07:00
sandboxData,
}: {
userData: User;
sandboxData: Sandbox;
2024-04-26 22:34:56 -04:00
}) {
const [isServerRunning, setIsServerRunning] = useState(false);
const [didFail, setDidFail] = useState(false);
useEffect(() => {
startServer(sandboxData.id, userData.id, (success: boolean) => {
if (!success) {
toast.error("Failed to start server.");
setDidFail(true);
} else {
setIsServerRunning(true);
}
});
2024-05-13 03:00:15 -07:00
// return () => {
// stopServer(sandboxData.id, userData.id);
// };
}, []);
if (!isServerRunning)
return <Loading didFail={didFail} text="Creating your sandbox resources" />;
2024-05-07 21:19:32 -07:00
return <CodeEditor userData={userData} sandboxData={sandboxData} />;
2024-04-06 19:03:04 -04:00
}