chore: removing unnecessary code
This commit is contained in:
parent
7149925539
commit
800cb8b437
@ -1,37 +1,48 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { SetStateAction, useCallback, useEffect, useRef, useState } from "react"
|
import { SetStateAction, useCallback, useEffect, useRef, useState } from "react"
|
||||||
import monaco from "monaco-editor"
|
|
||||||
import Editor, { BeforeMount, OnMount } from "@monaco-editor/react"
|
import { Sandbox, User, TFile, TFolder, TTab } from "@/lib/types"
|
||||||
import { toast } from "sonner"
|
|
||||||
|
// Authentication
|
||||||
import { useClerk } from "@clerk/nextjs"
|
import { useClerk } from "@clerk/nextjs"
|
||||||
|
|
||||||
|
// Liveblocks
|
||||||
import * as Y from "yjs"
|
import * as Y from "yjs"
|
||||||
import LiveblocksProvider from "@liveblocks/yjs"
|
import LiveblocksProvider from "@liveblocks/yjs"
|
||||||
import { MonacoBinding } from "y-monaco"
|
import { MonacoBinding } from "y-monaco"
|
||||||
import { Awareness } from "y-protocols/awareness"
|
import { Awareness } from "y-protocols/awareness"
|
||||||
import { TypedLiveblocksProvider, useRoom, useSelf } from "@/liveblocks.config"
|
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 {
|
import {
|
||||||
ResizableHandle,
|
ResizableHandle,
|
||||||
ResizablePanel,
|
ResizablePanel,
|
||||||
ResizablePanelGroup,
|
ResizablePanelGroup,
|
||||||
} from "@/components/ui/resizable"
|
} 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 Tab from "../ui/tab"
|
||||||
import Sidebar from "./sidebar"
|
import Sidebar from "./sidebar"
|
||||||
import GenerateInput from "./generate"
|
import GenerateInput from "./generate"
|
||||||
import { Sandbox, User, TFile, TFolder, TTab } from "@/lib/types"
|
|
||||||
import { addNew, processFileType, validateName, debounce } from "@/lib/utils"
|
import { addNew, processFileType, validateName, debounce } from "@/lib/utils"
|
||||||
import { Cursors } from "./live/cursors"
|
import { Cursors } from "./live/cursors"
|
||||||
import { Terminal } from "@xterm/xterm"
|
|
||||||
import DisableAccessModal from "./live/disableModal"
|
import DisableAccessModal from "./live/disableModal"
|
||||||
import Loading from "./loading"
|
import Loading from "./loading"
|
||||||
import PreviewWindow from "./preview"
|
import PreviewWindow from "./preview"
|
||||||
import Terminals from "./terminals"
|
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({
|
export default function CodeEditor({
|
||||||
userData,
|
userData,
|
||||||
@ -41,22 +52,17 @@ export default function CodeEditor({
|
|||||||
sandboxData: Sandbox
|
sandboxData: Sandbox
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
//SocketContext functions and effects
|
// Socket to the backend server
|
||||||
const { socket, setUserAndSandboxId } = useSocket();
|
const { socket, setUserAndSandboxId } = useSocket();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Ensure userData.id and sandboxData.id are available before attempting to connect
|
// Pass the user and sandbox ID to the socket, causing the socket to be created and 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
|
|
||||||
setUserAndSandboxId(userData.id, sandboxData.id);
|
setUserAndSandboxId(userData.id, sandboxData.id);
|
||||||
}
|
}, []);
|
||||||
}
|
|
||||||
}, [socket, userData.id, sandboxData.id, setUserAndSandboxId]);
|
|
||||||
|
|
||||||
//Preview Button state
|
// Preview panel state
|
||||||
const [isPreviewCollapsed, setIsPreviewCollapsed] = useState(true)
|
const [isPreviewCollapsed, setIsPreviewCollapsed] = useState(true)
|
||||||
|
|
||||||
|
// When the owner closes the project, isDisabled gets set for the other users.
|
||||||
const [disableAccess, setDisableAccess] = useState({
|
const [disableAccess, setDisableAccess] = useState({
|
||||||
isDisabled: false,
|
isDisabled: false,
|
||||||
message: "",
|
message: "",
|
||||||
|
@ -27,7 +27,7 @@ export default function Navbar({
|
|||||||
const [isShareOpen, setIsShareOpen] = useState(false);
|
const [isShareOpen, setIsShareOpen] = useState(false);
|
||||||
const [isRunning, setIsRunning] = useState(false);
|
const [isRunning, setIsRunning] = useState(false);
|
||||||
|
|
||||||
const isOwner = sandboxData.userId === userData.id;;
|
const isOwner = sandboxData.userId === userData.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user