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.
This commit is contained in:
Akhileshrangani4 2024-08-31 20:31:20 -04:00
parent 2da60ff4e4
commit f683ff6480
3 changed files with 17 additions and 7 deletions

View File

@ -143,6 +143,8 @@ io.on("connection", async (socket) => {
isOwner: boolean; isOwner: boolean;
}; };
console.log("user:",data)
if (data.isOwner) { if (data.isOwner) {
isOwnerConnected = true; isOwnerConnected = true;
connections[data.sandboxId] = (connections[data.sandboxId] ?? 0) + 1; connections[data.sandboxId] = (connections[data.sandboxId] ?? 0) + 1;
@ -183,6 +185,7 @@ io.on("connection", async (socket) => {
fixPermissions(); fixPermissions();
socket.emit("loaded", sandboxFiles.files); socket.emit("loaded", sandboxFiles.files);
console.log("files got", sandboxFiles.files)
socket.on("getFile", (fileId: string, callback) => { socket.on("getFile", (fileId: string, callback) => {
console.log(fileId); console.log(fileId);

View File

@ -50,9 +50,9 @@ export default function Dashboard({
const router = useRouter() const router = useRouter()
useEffect(() => { useEffect(() => {
if (!sandboxes) { // if (!sandboxes) {
router.refresh() router.refresh() // fix: update the dashboard to show the new project
} // }
}, [sandboxes]) }, [sandboxes])
return ( return (

View File

@ -45,9 +45,15 @@ export default function CodeEditor({
const { socket, setUserAndSandboxId } = useSocket(); const { socket, setUserAndSandboxId } = useSocket();
useEffect(() => { useEffect(() => {
// Check if socket is null, and initialize it by setting userId and sandboxId console.log('Effect triggered:', { socket, userData, sandboxData });
if (!socket && userData.id && sandboxData.id) { // Ensure userData.id and sandboxData.id are available before attempting to connect
setUserAndSandboxId(userData.id, sandboxData.id); 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]); }, [socket, userData.id, sandboxData.id, setUserAndSandboxId]);
@ -439,6 +445,7 @@ export default function CodeEditor({
const onLoadedEvent = (files: (TFolder | TFile)[]) => { const onLoadedEvent = (files: (TFolder | TFile)[]) => {
setFiles(files) setFiles(files)
console.log("loaded", files)
} }
const onError = (message: string) => { const onError = (message: string) => {
@ -478,7 +485,7 @@ export default function CodeEditor({
socket?.off("previewURL", loadPreviewURL) socket?.off("previewURL", loadPreviewURL)
} }
// }, []); // }, []);
}, [terminals]) }, [socket, terminals, setTerminals, setFiles, toast, setDisableAccess, isOwner, loadPreviewURL]);
// Helper functions for tabs: // Helper functions for tabs: