67 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-05-26 12:18:09 -07:00
"use client"
2024-04-06 19:03:04 -04:00
2024-05-26 12:18:09 -07:00
import dynamic from "next/dynamic"
import Loading from "@/components/editor/loading"
import { Sandbox, User } from "@/lib/types"
import { useEffect, useState } from "react"
import { toast } from "sonner"
import { getTaskIp, startServer } from "@/lib/actions"
import { checkServiceStatus, setupServer } from "@/lib/utils"
2024-05-03 13:53:21 -07:00
const CodeEditor = dynamic(() => import("@/components/editor/editor"), {
ssr: false,
loading: () => <Loading />,
2024-05-26 12:18:09 -07:00
})
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,
}: {
2024-05-26 12:18:09 -07:00
userData: User
sandboxData: Sandbox
2024-04-26 22:34:56 -04:00
}) {
2024-05-26 12:18:09 -07:00
const isDev = process.env.VERCEL_ENV === "development"
const [isServiceRunning, setIsServiceRunning] = useState(false)
const [isDeploymentActive, setIsDeploymentActive] = useState(false)
const [taskIp, setTaskIp] = useState<string>()
const [didFail, setDidFail] = useState(false)
useEffect(() => {
2024-05-26 12:18:09 -07:00
if (isDev) {
setIsServiceRunning(true)
setIsDeploymentActive(true)
setTaskIp("localhost")
return
2024-05-23 01:35:08 -07:00
}
2024-05-26 12:18:09 -07:00
setupServer({
sandboxId: sandboxData.id,
setIsServiceRunning,
setIsDeploymentActive,
setTaskIp,
setDidFail,
toast,
})
}, [])
2024-05-26 12:18:09 -07:00
if (didFail) return <Loading didFail={didFail} />
2024-05-25 20:13:31 -07:00
if (!isServiceRunning || !isDeploymentActive || !taskIp)
return (
<Loading
text="Creating sandbox resources"
description={
isDeploymentActive
? "Preparing server networking..."
: isServiceRunning
? "Initializing server, this could take a minute..."
: "Requesting your server creation..."
}
/>
2024-05-26 12:18:09 -07:00
)
2024-05-07 21:19:32 -07:00
2024-05-23 01:35:08 -07:00
return (
2024-05-25 20:13:31 -07:00
<CodeEditor ip={taskIp} userData={userData} sandboxData={sandboxData} />
2024-05-26 12:18:09 -07:00
)
2024-04-06 19:03:04 -04:00
}