2024-05-06 22:59:49 -07:00
|
|
|
"use client";
|
2024-04-06 19:03:04 -04:00
|
|
|
|
2024-05-12 02:10:31 -07: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";
|
2024-05-06 22:59:49 -07:00
|
|
|
import { toast } from "sonner";
|
2024-05-03 13:53:21 -07:00
|
|
|
|
2024-05-12 02:10:31 -07:00
|
|
|
const CodeEditor = dynamic(() => import("@/components/editor/editor"), {
|
|
|
|
ssr: false,
|
|
|
|
loading: () => <Loading />,
|
|
|
|
});
|
2024-04-06 19:03:04 -04:00
|
|
|
|
2024-05-12 02:10:31 -07:00
|
|
|
export default function Editor({
|
2024-05-01 01:53:49 -04:00
|
|
|
userData,
|
2024-05-05 00:06:10 -07:00
|
|
|
sandboxData,
|
2024-05-12 02:10:31 -07:00
|
|
|
}: {
|
2024-05-06 22:59:49 -07:00
|
|
|
userData: User;
|
|
|
|
sandboxData: Sandbox;
|
2024-04-26 22:34:56 -04:00
|
|
|
}) {
|
2024-05-12 02:10:31 -07:00
|
|
|
const [isServerRunning, setIsServerRunning] = useState(false);
|
2024-05-12 22:06:11 -07:00
|
|
|
const [didFail, setDidFail] = useState(false);
|
2024-05-12 02:10:31 -07:00
|
|
|
|
2024-05-12 22:06:11 -07:00
|
|
|
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);
|
|
|
|
// };
|
2024-05-12 22:06:11 -07:00
|
|
|
}, []);
|
2024-05-12 02:10:31 -07:00
|
|
|
|
|
|
|
if (!isServerRunning)
|
2024-05-12 22:06:11 -07:00
|
|
|
return <Loading didFail={didFail} text="Creating your sandbox resources" />;
|
2024-05-07 21:19:32 -07:00
|
|
|
|
2024-05-12 02:10:31 -07:00
|
|
|
return <CodeEditor userData={userData} sandboxData={sandboxData} />;
|
2024-04-06 19:03:04 -04:00
|
|
|
}
|