fix: comment out live collaboration features
This commit is contained in:
parent
9c3787b99d
commit
b796f46dc2
@ -1,4 +1,4 @@
|
||||
import { Room } from "@/components/editor/live/room"
|
||||
// import { Room } from "@/components/editor/live/room"
|
||||
import Loading from "@/components/editor/loading"
|
||||
import Navbar from "@/components/editor/navbar"
|
||||
import { TerminalProvider } from "@/context/TerminalContext"
|
||||
@ -93,7 +93,7 @@ export default async function CodePage({ params }: { params: { id: string } }) {
|
||||
return (
|
||||
<>
|
||||
<div className="overflow-hidden overscroll-none w-screen flex flex-col h-screen bg-background">
|
||||
<Room id={sandboxId}>
|
||||
{/* <Room id={sandboxId}> */}
|
||||
<TerminalProvider>
|
||||
<Navbar
|
||||
userData={userData}
|
||||
@ -106,7 +106,7 @@ export default async function CodePage({ params }: { params: { id: string } }) {
|
||||
<CodeEditor userData={userData} sandboxData={sandboxData} />
|
||||
</div>
|
||||
</TerminalProvider>
|
||||
</Room>
|
||||
{/* </Room> */}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
@ -1,57 +1,61 @@
|
||||
import { colors } from "@/lib/colors"
|
||||
import { User } from "@/lib/types"
|
||||
// import { colors } from "@/lib/colors"
|
||||
// import { User } from "@/lib/types"
|
||||
import { currentUser } from "@clerk/nextjs"
|
||||
import { Liveblocks } from "@liveblocks/node"
|
||||
// import { Liveblocks } from "@liveblocks/node"
|
||||
import { NextRequest } from "next/server"
|
||||
|
||||
const API_KEY = process.env.LIVEBLOCKS_SECRET_KEY!
|
||||
// const API_KEY = process.env.LIVEBLOCKS_SECRET_KEY!
|
||||
|
||||
const liveblocks = new Liveblocks({
|
||||
secret: API_KEY!,
|
||||
})
|
||||
// const liveblocks = new Liveblocks({
|
||||
// secret: API_KEY!,
|
||||
// })
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const clerkUser = await currentUser()
|
||||
// Temporarily return unauthorized while Liveblocks is disabled
|
||||
return new Response("Liveblocks collaboration temporarily disabled", { status: 503 })
|
||||
|
||||
if (!clerkUser) {
|
||||
return new Response("Unauthorized", { status: 401 })
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user?id=${clerkUser.id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `${process.env.NEXT_PUBLIC_WORKERS_KEY}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
const user = (await res.json()) as User
|
||||
|
||||
const colorNames = Object.keys(colors)
|
||||
const randomColor = colorNames[
|
||||
Math.floor(Math.random() * colorNames.length)
|
||||
] as keyof typeof colors
|
||||
const code = colors[randomColor]
|
||||
|
||||
// Create a session for the current user
|
||||
// userInfo is made available in Liveblocks presence hooks, e.g. useOthers
|
||||
const session = liveblocks.prepareSession(user.id, {
|
||||
userInfo: {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
color: randomColor,
|
||||
},
|
||||
})
|
||||
|
||||
// Give the user access to the room
|
||||
user.sandbox.forEach((sandbox) => {
|
||||
session.allow(`${sandbox.id}`, session.FULL_ACCESS)
|
||||
})
|
||||
user.usersToSandboxes.forEach((userToSandbox) => {
|
||||
session.allow(`${userToSandbox.sandboxId}`, session.FULL_ACCESS)
|
||||
})
|
||||
|
||||
// Authorize the user and return the result
|
||||
const { body, status } = await session.authorize()
|
||||
return new Response(body, { status })
|
||||
// Original implementation commented out:
|
||||
// const clerkUser = await currentUser()
|
||||
//
|
||||
// if (!clerkUser) {
|
||||
// return new Response("Unauthorized", { status: 401 })
|
||||
// }
|
||||
//
|
||||
// const res = await fetch(
|
||||
// `${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user?id=${clerkUser.id}`,
|
||||
// {
|
||||
// headers: {
|
||||
// Authorization: `${process.env.NEXT_PUBLIC_WORKERS_KEY}`,
|
||||
// },
|
||||
// }
|
||||
// )
|
||||
// const user = (await res.json()) as User
|
||||
//
|
||||
// const colorNames = Object.keys(colors)
|
||||
// const randomColor = colorNames[
|
||||
// Math.floor(Math.random() * colorNames.length)
|
||||
// ] as keyof typeof colors
|
||||
// const code = colors[randomColor]
|
||||
//
|
||||
// // Create a session for the current user
|
||||
// // userInfo is made available in Liveblocks presence hooks, e.g. useOthers
|
||||
// const session = liveblocks.prepareSession(user.id, {
|
||||
// userInfo: {
|
||||
// name: user.name,
|
||||
// email: user.email,
|
||||
// color: randomColor,
|
||||
// },
|
||||
// })
|
||||
//
|
||||
// // Give the user access to the room
|
||||
// user.sandbox.forEach((sandbox) => {
|
||||
// session.allow(`${sandbox.id}`, session.FULL_ACCESS)
|
||||
// })
|
||||
// user.usersToSandboxes.forEach((userToSandbox) => {
|
||||
// session.allow(`${userToSandbox.sandboxId}`, session.FULL_ACCESS)
|
||||
// })
|
||||
//
|
||||
// // Authorize the user and return the result
|
||||
// const { body, status } = await session.authorize()
|
||||
// return new Response(body, { status })
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ export default function Dashboard({
|
||||
<FolderDot className="w-4 h-4 mr-2" />
|
||||
My Projects
|
||||
</Button>
|
||||
<Button
|
||||
{/* <Button
|
||||
variant="ghost"
|
||||
onClick={() => setScreen("shared")}
|
||||
className={activeScreen("shared")}
|
||||
>
|
||||
<Users className="w-4 h-4 mr-2" />
|
||||
Shared With Me
|
||||
</Button>
|
||||
</Button> */}
|
||||
{/* <Button
|
||||
variant="ghost"
|
||||
onClick={() => setScreen("settings")}
|
||||
|
@ -7,11 +7,11 @@ import * as monaco from "monaco-editor"
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { TypedLiveblocksProvider, useRoom, useSelf } from "@/liveblocks.config"
|
||||
import LiveblocksProvider from "@liveblocks/yjs"
|
||||
import { MonacoBinding } from "y-monaco"
|
||||
import { Awareness } from "y-protocols/awareness"
|
||||
import * as Y from "yjs"
|
||||
// import { TypedLiveblocksProvider, useRoom, useSelf } from "@/liveblocks.config"
|
||||
// import LiveblocksProvider from "@liveblocks/yjs"
|
||||
// import { MonacoBinding } from "y-monaco"
|
||||
// import { Awareness } from "y-protocols/awareness"
|
||||
// import * as Y from "yjs"
|
||||
|
||||
import {
|
||||
ResizableHandle,
|
||||
@ -45,7 +45,7 @@ import { Button } from "../ui/button"
|
||||
import Tab from "../ui/tab"
|
||||
import AIChat from "./AIChat"
|
||||
import GenerateInput from "./generate"
|
||||
import { Cursors } from "./live/cursors"
|
||||
// import { Cursors } from "./live/cursors"
|
||||
import DisableAccessModal from "./live/disableModal"
|
||||
import Loading from "./loading"
|
||||
import PreviewWindow from "./preview"
|
||||
@ -146,20 +146,20 @@ export default function CodeEditor({
|
||||
const isOwner = sandboxData.userId === userData.id
|
||||
const clerk = useClerk()
|
||||
|
||||
// Liveblocks hooks
|
||||
const room = useRoom()
|
||||
const [provider, setProvider] = useState<TypedLiveblocksProvider>()
|
||||
const userInfo = useSelf((me) => me.info)
|
||||
// // Liveblocks hooks
|
||||
// const room = useRoom()
|
||||
// const [provider, setProvider] = useState<TypedLiveblocksProvider>()
|
||||
// const userInfo = useSelf((me) => me.info)
|
||||
|
||||
// Liveblocks providers map to prevent reinitializing providers
|
||||
type ProviderData = {
|
||||
provider: LiveblocksProvider<never, never, never, never>
|
||||
yDoc: Y.Doc
|
||||
yText: Y.Text
|
||||
binding?: MonacoBinding
|
||||
onSync: (isSynced: boolean) => void
|
||||
}
|
||||
const providersMap = useRef(new Map<string, ProviderData>())
|
||||
// // Liveblocks providers map to prevent reinitializing providers
|
||||
// type ProviderData = {
|
||||
// provider: LiveblocksProvider<never, never, never, never>
|
||||
// yDoc: Y.Doc
|
||||
// yText: Y.Text
|
||||
// binding?: MonacoBinding
|
||||
// onSync: (isSynced: boolean) => void
|
||||
// }
|
||||
// const providersMap = useRef(new Map<string, ProviderData>())
|
||||
|
||||
// Refs for libraries / features
|
||||
const editorContainerRef = useRef<HTMLDivElement>(null)
|
||||
@ -573,82 +573,82 @@ export default function CodeEditor({
|
||||
}
|
||||
}, [activeFileId, tabs, debouncedSaveData, setIsAIChatOpen, editorRef])
|
||||
|
||||
// Liveblocks live collaboration setup effect
|
||||
useEffect(() => {
|
||||
const tab = tabs.find((t) => t.id === activeFileId)
|
||||
const model = editorRef?.getModel()
|
||||
// // Liveblocks live collaboration setup effect
|
||||
// useEffect(() => {
|
||||
// const tab = tabs.find((t) => t.id === activeFileId)
|
||||
// const model = editorRef?.getModel()
|
||||
|
||||
if (!editorRef || !tab || !model) return
|
||||
// if (!editorRef || !tab || !model) return
|
||||
|
||||
let providerData: ProviderData
|
||||
// let providerData: ProviderData
|
||||
|
||||
// When a file is opened for the first time, create a new provider and store in providersMap.
|
||||
if (!providersMap.current.has(tab.id)) {
|
||||
const yDoc = new Y.Doc()
|
||||
const yText = yDoc.getText(tab.id)
|
||||
const yProvider = new LiveblocksProvider(room, yDoc)
|
||||
// // When a file is opened for the first time, create a new provider and store in providersMap.
|
||||
// if (!providersMap.current.has(tab.id)) {
|
||||
// const yDoc = new Y.Doc()
|
||||
// const yText = yDoc.getText(tab.id)
|
||||
// const yProvider = new LiveblocksProvider(room, yDoc)
|
||||
|
||||
// Inserts the file content into the editor once when the tab is changed.
|
||||
const onSync = (isSynced: boolean) => {
|
||||
if (isSynced) {
|
||||
const text = yText.toString()
|
||||
if (text === "") {
|
||||
if (activeFileContent) {
|
||||
yText.insert(0, activeFileContent)
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
yText.insert(0, editorRef.getValue())
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Inserts the file content into the editor once when the tab is changed.
|
||||
// const onSync = (isSynced: boolean) => {
|
||||
// if (isSynced) {
|
||||
// const text = yText.toString()
|
||||
// if (text === "") {
|
||||
// if (activeFileContent) {
|
||||
// yText.insert(0, activeFileContent)
|
||||
// } else {
|
||||
// setTimeout(() => {
|
||||
// yText.insert(0, editorRef.getValue())
|
||||
// }, 0)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
yProvider.on("sync", onSync)
|
||||
// yProvider.on("sync", onSync)
|
||||
|
||||
// Save the provider to the map.
|
||||
providerData = { provider: yProvider, yDoc, yText, onSync }
|
||||
providersMap.current.set(tab.id, providerData)
|
||||
} else {
|
||||
// When a tab is opened that has been open before, reuse the existing provider.
|
||||
providerData = providersMap.current.get(tab.id)!
|
||||
}
|
||||
// // Save the provider to the map.
|
||||
// providerData = { provider: yProvider, yDoc, yText, onSync }
|
||||
// providersMap.current.set(tab.id, providerData)
|
||||
// } else {
|
||||
// // When a tab is opened that has been open before, reuse the existing provider.
|
||||
// providerData = providersMap.current.get(tab.id)!
|
||||
// }
|
||||
|
||||
const binding = new MonacoBinding(
|
||||
providerData.yText,
|
||||
model,
|
||||
new Set([editorRef]),
|
||||
providerData.provider.awareness as unknown as Awareness
|
||||
)
|
||||
// const binding = new MonacoBinding(
|
||||
// providerData.yText,
|
||||
// model,
|
||||
// new Set([editorRef]),
|
||||
// providerData.provider.awareness as unknown as Awareness
|
||||
// )
|
||||
|
||||
providerData.binding = binding
|
||||
setProvider(providerData.provider)
|
||||
// providerData.binding = binding
|
||||
// setProvider(providerData.provider)
|
||||
|
||||
return () => {
|
||||
// Cleanup logic
|
||||
if (binding) {
|
||||
binding.destroy()
|
||||
}
|
||||
if (providerData.binding) {
|
||||
providerData.binding = undefined
|
||||
}
|
||||
}
|
||||
}, [room, activeFileContent])
|
||||
// return () => {
|
||||
// // Cleanup logic
|
||||
// if (binding) {
|
||||
// binding.destroy()
|
||||
// }
|
||||
// if (providerData.binding) {
|
||||
// providerData.binding = undefined
|
||||
// }
|
||||
// }
|
||||
// }, [room, activeFileContent])
|
||||
|
||||
// Added this effect to clean up when the component unmounts
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
// Clean up all providers when the component unmounts
|
||||
providersMap.current.forEach((data) => {
|
||||
if (data.binding) {
|
||||
data.binding.destroy()
|
||||
}
|
||||
data.provider.disconnect()
|
||||
data.yDoc.destroy()
|
||||
})
|
||||
providersMap.current.clear()
|
||||
}
|
||||
}, [])
|
||||
// // Added this effect to clean up when the component unmounts
|
||||
// useEffect(() => {
|
||||
// return () => {
|
||||
// // Clean up all providers when the component unmounts
|
||||
// providersMap.current.forEach((data) => {
|
||||
// if (data.binding) {
|
||||
// data.binding.destroy()
|
||||
// }
|
||||
// data.provider.disconnect()
|
||||
// data.yDoc.destroy()
|
||||
// })
|
||||
// providersMap.current.clear()
|
||||
// }
|
||||
// }, [])
|
||||
|
||||
// Connection/disconnection effect
|
||||
useEffect(() => {
|
||||
@ -1088,62 +1088,62 @@ export default function CodeEditor({
|
||||
</div>
|
||||
</>
|
||||
) : // Note clerk.loaded is required here due to a bug: https://github.com/clerk/javascript/issues/1643
|
||||
clerk.loaded ? (
|
||||
<>
|
||||
{provider && userInfo ? (
|
||||
<Cursors yProvider={provider} userInfo={userInfo} />
|
||||
) : null}
|
||||
<Editor
|
||||
height="100%"
|
||||
language={editorLanguage}
|
||||
beforeMount={handleEditorWillMount}
|
||||
onMount={handleEditorMount}
|
||||
onChange={(value) => {
|
||||
// If the new content is different from the cached content, update it
|
||||
if (value !== fileContents[activeFileId]) {
|
||||
setActiveFileContent(value ?? "") // Update the active file content
|
||||
// Mark the file as unsaved by setting 'saved' to false
|
||||
setTabs((prev) =>
|
||||
prev.map((tab) =>
|
||||
tab.id === activeFileId
|
||||
? { ...tab, saved: false }
|
||||
: tab
|
||||
clerk.loaded ? (
|
||||
<>
|
||||
{/* {provider && userInfo ? (
|
||||
<Cursors yProvider={provider} userInfo={userInfo} />
|
||||
) : null} */}
|
||||
<Editor
|
||||
height="100%"
|
||||
language={editorLanguage}
|
||||
beforeMount={handleEditorWillMount}
|
||||
onMount={handleEditorMount}
|
||||
onChange={(value) => {
|
||||
// If the new content is different from the cached content, update it
|
||||
if (value !== fileContents[activeFileId]) {
|
||||
setActiveFileContent(value ?? "") // Update the active file content
|
||||
// Mark the file as unsaved by setting 'saved' to false
|
||||
setTabs((prev) =>
|
||||
prev.map((tab) =>
|
||||
tab.id === activeFileId
|
||||
? { ...tab, saved: false }
|
||||
: tab
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// If the content matches the cached content, mark the file as saved
|
||||
setTabs((prev) =>
|
||||
prev.map((tab) =>
|
||||
tab.id === activeFileId
|
||||
? { ...tab, saved: true }
|
||||
: tab
|
||||
} else {
|
||||
// If the content matches the cached content, mark the file as saved
|
||||
setTabs((prev) =>
|
||||
prev.map((tab) =>
|
||||
tab.id === activeFileId
|
||||
? { ...tab, saved: true }
|
||||
: tab
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}}
|
||||
options={{
|
||||
tabSize: 2,
|
||||
minimap: {
|
||||
enabled: false,
|
||||
},
|
||||
padding: {
|
||||
bottom: 4,
|
||||
top: 4,
|
||||
},
|
||||
scrollBeyondLastLine: false,
|
||||
fixedOverflowWidgets: true,
|
||||
fontFamily: "var(--font-geist-mono)",
|
||||
}}
|
||||
theme={theme === "light" ? "vs" : "vs-dark"}
|
||||
value={activeFileContent}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div className="w-full h-full flex items-center justify-center text-xl font-medium text-muted-foreground/50 select-none">
|
||||
<Loader2 className="animate-spin w-6 h-6 mr-3" />
|
||||
Waiting for Clerk to load...
|
||||
</div>
|
||||
)}
|
||||
}
|
||||
}}
|
||||
options={{
|
||||
tabSize: 2,
|
||||
minimap: {
|
||||
enabled: false,
|
||||
},
|
||||
padding: {
|
||||
bottom: 4,
|
||||
top: 4,
|
||||
},
|
||||
scrollBeyondLastLine: false,
|
||||
fixedOverflowWidgets: true,
|
||||
fontFamily: "var(--font-geist-mono)",
|
||||
}}
|
||||
theme={theme === "light" ? "vs" : "vs-dark"}
|
||||
value={activeFileContent}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div className="w-full h-full flex items-center justify-center text-xl font-medium text-muted-foreground/50 select-none">
|
||||
<Loader2 className="animate-spin w-6 h-6 mr-3" />
|
||||
Waiting for Clerk to load...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
<ResizableHandle />
|
||||
|
@ -9,7 +9,7 @@ import { Pencil, Users } from "lucide-react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { useState } from "react"
|
||||
import { Avatars } from "../live/avatars"
|
||||
// import { Avatars } from "../live/avatars"
|
||||
import DeployButtonModal from "./deploy"
|
||||
import DownloadButton from "./downloadButton"
|
||||
import EditSandboxModal from "./edit"
|
||||
@ -70,17 +70,16 @@ export default function Navbar({
|
||||
sandboxData={sandboxData}
|
||||
/>
|
||||
<div className="flex items-center h-full space-x-4">
|
||||
<Avatars />
|
||||
{/* <Avatars /> */}
|
||||
|
||||
{isOwner ? (
|
||||
<>
|
||||
<DeployButtonModal data={sandboxData} userData={userData} />
|
||||
<Button variant="outline" onClick={() => setIsShareOpen(true)}>
|
||||
{/* <Button variant="outline" onClick={() => setIsShareOpen(true)}>
|
||||
<Users className="w-4 h-4 mr-2" />
|
||||
Share
|
||||
</Button>
|
||||
<DownloadButton name={sandboxData.name} />
|
||||
</>
|
||||
</Button> */}
|
||||
<DownloadButton name={sandboxData.name} /></>
|
||||
) : null}
|
||||
<ThemeSwitcher />
|
||||
<UserButton userData={userData} />
|
||||
|
@ -45,9 +45,14 @@ export default function Landing() {
|
||||
<h1 className="text-2xl font-medium text-center mt-16">
|
||||
A Collaborative + AI-Powered Code Environment
|
||||
</h1>
|
||||
<p className="text-muted-foreground mt-4 text-center ">
|
||||
{/* <p className="text-muted-foreground mt-4 text-center ">
|
||||
Sandbox is an open-source cloud-based code editing environment with
|
||||
custom AI code autocompletion and real-time collaboration.
|
||||
</p> */}
|
||||
<p className="text-muted-foreground mt-4 text-center ">
|
||||
A cloud-based code editor featuring real-time collaboration,
|
||||
intelligent code autocompletion, and an AI assistant to help you code
|
||||
faster and smarter.
|
||||
</p>
|
||||
<div className="mt-8 flex space-x-4">
|
||||
<Link href="/sign-up">
|
||||
|
Loading…
x
Reference in New Issue
Block a user