From f683ff6480d7302ae8617fad9bafc3d961cde254 Mon Sep 17 00:00:00 2001 From: Akhileshrangani4 Date: Sat, 31 Aug 2024 20:31:20 -0400 Subject: [PATCH] fix: files not loading when creating a new project This push contains console logs at various places where the server is emitting the event and the client is receiving the event. Please remove those before merging with production. --- backend/server/src/index.ts | 3 +++ frontend/components/dashboard/index.tsx | 6 +++--- frontend/components/editor/index.tsx | 15 +++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/backend/server/src/index.ts b/backend/server/src/index.ts index 6ca6853..973153e 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -143,6 +143,8 @@ io.on("connection", async (socket) => { isOwner: boolean; }; + console.log("user:",data) + if (data.isOwner) { isOwnerConnected = true; connections[data.sandboxId] = (connections[data.sandboxId] ?? 0) + 1; @@ -183,6 +185,7 @@ io.on("connection", async (socket) => { fixPermissions(); socket.emit("loaded", sandboxFiles.files); + console.log("files got", sandboxFiles.files) socket.on("getFile", (fileId: string, callback) => { console.log(fileId); diff --git a/frontend/components/dashboard/index.tsx b/frontend/components/dashboard/index.tsx index 4724041..a339d86 100644 --- a/frontend/components/dashboard/index.tsx +++ b/frontend/components/dashboard/index.tsx @@ -50,9 +50,9 @@ export default function Dashboard({ const router = useRouter() useEffect(() => { - if (!sandboxes) { - router.refresh() - } + // if (!sandboxes) { + router.refresh() // fix: update the dashboard to show the new project + // } }, [sandboxes]) return ( diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 5d4340d..d14b5fd 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -45,9 +45,15 @@ export default function CodeEditor({ const { socket, setUserAndSandboxId } = useSocket(); useEffect(() => { - // Check if socket is null, and initialize it by setting userId and sandboxId - if (!socket && userData.id && sandboxData.id) { - setUserAndSandboxId(userData.id, sandboxData.id); + console.log('Effect triggered:', { socket, userData, sandboxData }); + // 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 + console.log('Initializing socket...'); + setUserAndSandboxId(userData.id, sandboxData.id); + } } }, [socket, userData.id, sandboxData.id, setUserAndSandboxId]); @@ -439,6 +445,7 @@ export default function CodeEditor({ const onLoadedEvent = (files: (TFolder | TFile)[]) => { setFiles(files) + console.log("loaded", files) } const onError = (message: string) => { @@ -478,7 +485,7 @@ export default function CodeEditor({ socket?.off("previewURL", loadPreviewURL) } // }, []); - }, [terminals]) + }, [socket, terminals, setTerminals, setFiles, toast, setDisableAccess, isOwner, loadPreviewURL]); // Helper functions for tabs: