2024-04-16 16:25:21 -04:00
|
|
|
import Navbar from "@/components/editor/navbar"
|
2024-04-27 00:28:00 -04:00
|
|
|
import { Sandbox, User } from "@/lib/types"
|
2024-04-18 15:32:27 -04:00
|
|
|
import { currentUser } from "@clerk/nextjs"
|
2024-04-09 00:26:22 -04:00
|
|
|
import dynamic from "next/dynamic"
|
2024-04-26 22:34:56 -04:00
|
|
|
import { redirect } from "next/navigation"
|
2024-04-09 00:26:22 -04:00
|
|
|
|
|
|
|
const CodeEditor = dynamic(() => import("@/components/editor"), {
|
|
|
|
ssr: false,
|
|
|
|
})
|
|
|
|
|
2024-04-26 00:10:53 -04:00
|
|
|
const getUserData = async (id: string) => {
|
|
|
|
const userRes = await fetch(`http://localhost:8787/api/user?id=${id}`)
|
|
|
|
const userData: User = await userRes.json()
|
|
|
|
return userData
|
|
|
|
}
|
|
|
|
|
2024-04-27 00:28:00 -04:00
|
|
|
const getSandboxData = async (id: string) => {
|
|
|
|
const sandboxRes = await fetch(`http://localhost:8787/api/sandbox?id=${id}`)
|
|
|
|
const sandboxData: Sandbox = await sandboxRes.json()
|
|
|
|
return sandboxData
|
|
|
|
}
|
|
|
|
|
2024-04-26 00:10:53 -04:00
|
|
|
export default async function CodePage({ params }: { params: { id: string } }) {
|
2024-04-18 15:32:27 -04:00
|
|
|
const user = await currentUser()
|
2024-04-26 00:10:53 -04:00
|
|
|
const sandboxId = params.id
|
2024-04-18 15:32:27 -04:00
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
redirect("/")
|
|
|
|
}
|
|
|
|
|
2024-04-26 00:10:53 -04:00
|
|
|
const userData = await getUserData(user.id)
|
2024-04-27 00:28:00 -04:00
|
|
|
const sandboxData = await getSandboxData(sandboxId)
|
2024-04-11 03:34:58 -04:00
|
|
|
|
2024-04-09 00:26:22 -04:00
|
|
|
return (
|
2024-04-09 00:50:48 -04:00
|
|
|
<div className="overflow-hidden overscroll-none w-screen flex flex-col h-screen bg-background">
|
2024-04-27 00:28:00 -04:00
|
|
|
<Navbar userData={userData} sandboxData={sandboxData} />
|
2024-04-09 00:26:22 -04:00
|
|
|
<div className="w-screen flex grow">
|
2024-04-26 22:34:56 -04:00
|
|
|
<CodeEditor userId={user.id} sandboxId={sandboxId} />
|
2024-04-09 00:26:22 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|