Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
df9ec776b8 | ||
|
ca7d918535 | ||
|
800cb8b437 |
@ -6,6 +6,7 @@ import { notFound, redirect } from "next/navigation"
|
||||
import Loading from "@/components/editor/loading"
|
||||
import dynamic from "next/dynamic"
|
||||
import fs from "fs"
|
||||
import { TerminalProvider } from "@/context/TerminalContext"
|
||||
|
||||
export const revalidate = 0
|
||||
|
||||
@ -87,8 +88,10 @@ 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}>
|
||||
<TerminalProvider>
|
||||
<Navbar userData={userData} sandboxData={sandboxData} shared={shared} />
|
||||
<div className="w-screen flex grow">
|
||||
<CodeEditor
|
||||
@ -96,7 +99,9 @@ export default async function CodePage({ params }: { params: { id: string } }) {
|
||||
sandboxData={sandboxData}
|
||||
/>
|
||||
</div>
|
||||
</TerminalProvider>
|
||||
</Room>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import { ThemeProvider } from "@/components/layout/themeProvider"
|
||||
import { ClerkProvider } from "@clerk/nextjs"
|
||||
import { Toaster } from "@/components/ui/sonner"
|
||||
import { Analytics } from "@vercel/analytics/react"
|
||||
import { TerminalProvider } from '@/context/TerminalContext';
|
||||
import { PreviewProvider } from "@/context/PreviewContext";
|
||||
import { SocketProvider } from '@/context/SocketContext'
|
||||
|
||||
@ -32,9 +31,7 @@ export default function RootLayout({
|
||||
>
|
||||
<SocketProvider>
|
||||
<PreviewProvider>
|
||||
<TerminalProvider>
|
||||
{children}
|
||||
</TerminalProvider>
|
||||
</PreviewProvider>
|
||||
</SocketProvider>
|
||||
<Analytics />
|
||||
|
@ -51,7 +51,7 @@ export default function Dashboard({
|
||||
|
||||
useEffect(() => { // update the dashboard to show a new project
|
||||
router.refresh()
|
||||
}, [sandboxes])
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -1,37 +1,48 @@
|
||||
"use client"
|
||||
|
||||
import { SetStateAction, useCallback, useEffect, useRef, useState } from "react"
|
||||
import monaco from "monaco-editor"
|
||||
import Editor, { BeforeMount, OnMount } from "@monaco-editor/react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Sandbox, User, TFile, TFolder, TTab } from "@/lib/types"
|
||||
|
||||
// Authentication
|
||||
import { useClerk } from "@clerk/nextjs"
|
||||
|
||||
// Liveblocks
|
||||
import * as Y from "yjs"
|
||||
import LiveblocksProvider from "@liveblocks/yjs"
|
||||
import { MonacoBinding } from "y-monaco"
|
||||
import { Awareness } from "y-protocols/awareness"
|
||||
import { TypedLiveblocksProvider, useRoom, useSelf } from "@/liveblocks.config"
|
||||
|
||||
// Icons
|
||||
import { FileJson, Loader2, TerminalSquare } from "lucide-react"
|
||||
|
||||
// Contexts
|
||||
import { PreviewProvider, usePreview } from '@/context/PreviewContext';
|
||||
import { useSocket } from "@/context/SocketContext"
|
||||
|
||||
// External Components
|
||||
import monaco from "monaco-editor"
|
||||
import { Terminal } from "@xterm/xterm"
|
||||
import Editor, { BeforeMount, OnMount } from "@monaco-editor/react"
|
||||
import { toast } from "sonner"
|
||||
import {
|
||||
ResizableHandle,
|
||||
ResizablePanel,
|
||||
ResizablePanelGroup,
|
||||
} from "@/components/ui/resizable"
|
||||
import { FileJson, Loader2, TerminalSquare } from "lucide-react"
|
||||
import { ImperativePanelHandle } from "react-resizable-panels"
|
||||
|
||||
// Editor Components
|
||||
import Tab from "../ui/tab"
|
||||
import Sidebar from "./sidebar"
|
||||
import GenerateInput from "./generate"
|
||||
import { Sandbox, User, TFile, TFolder, TTab } from "@/lib/types"
|
||||
import { addNew, processFileType, validateName, debounce } from "@/lib/utils"
|
||||
import { Cursors } from "./live/cursors"
|
||||
import { Terminal } from "@xterm/xterm"
|
||||
import DisableAccessModal from "./live/disableModal"
|
||||
import Loading from "./loading"
|
||||
import PreviewWindow from "./preview"
|
||||
import Terminals from "./terminals"
|
||||
import { ImperativePanelHandle } from "react-resizable-panels"
|
||||
import { PreviewProvider, usePreview } from '@/context/PreviewContext';
|
||||
import { useSocket } from "@/context/SocketContext"
|
||||
|
||||
export default function CodeEditor({
|
||||
userData,
|
||||
@ -41,22 +52,17 @@ export default function CodeEditor({
|
||||
sandboxData: Sandbox
|
||||
}) {
|
||||
|
||||
//SocketContext functions and effects
|
||||
// Socket to the backend server
|
||||
const { socket, setUserAndSandboxId } = useSocket();
|
||||
|
||||
useEffect(() => {
|
||||
// Ensure userData.id and sandboxData.id are available before attempting to connect
|
||||
if (userData.id && sandboxData.id) {
|
||||
// Check if the socket is not initialized or not connected
|
||||
if (!socket || (socket && !socket.connected)) {
|
||||
// Initialize socket connection
|
||||
// Pass the user and sandbox ID to the socket, causing the socket to be created and to connect.
|
||||
setUserAndSandboxId(userData.id, sandboxData.id);
|
||||
}
|
||||
}
|
||||
}, [socket, userData.id, sandboxData.id, setUserAndSandboxId]);
|
||||
}, []);
|
||||
|
||||
//Preview Button state
|
||||
// Preview panel state
|
||||
const [isPreviewCollapsed, setIsPreviewCollapsed] = useState(true)
|
||||
|
||||
// When the owner closes the project, isDisabled gets set for the other users.
|
||||
const [disableAccess, setDisableAccess] = useState({
|
||||
isDisabled: false,
|
||||
message: "",
|
||||
|
@ -27,7 +27,7 @@ export default function Navbar({
|
||||
const [isShareOpen, setIsShareOpen] = useState(false);
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
|
||||
const isOwner = sandboxData.userId === userData.id;;
|
||||
const isOwner = sandboxData.userId === userData.id;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
Loading…
x
Reference in New Issue
Block a user