Compare commits
9 Commits
fix-file-l
...
fix/socket
Author | SHA1 | Date | |
---|---|---|---|
9fd1f81654 | |||
665e36603f | |||
0679f99bb7 | |||
2065814aaa | |||
1502047bf2 | |||
bbd47db467 | |||
a15c1f15f5 | |||
f1a65106b0 | |||
5726cecb22 |
@ -143,8 +143,6 @@ 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;
|
||||||
@ -185,7 +183,6 @@ 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);
|
||||||
|
@ -49,10 +49,8 @@ export default function Dashboard({
|
|||||||
const q = searchParams.get("q")
|
const q = searchParams.get("q")
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { // update the dashboard to show a new project
|
||||||
// if (!sandboxes) {
|
router.refresh()
|
||||||
router.refresh() // fix: update the dashboard to show the new project
|
|
||||||
// }
|
|
||||||
}, [sandboxes])
|
}, [sandboxes])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -45,13 +45,11 @@ export default function CodeEditor({
|
|||||||
const { socket, setUserAndSandboxId } = useSocket();
|
const { socket, setUserAndSandboxId } = useSocket();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('Effect triggered:', { socket, userData, sandboxData });
|
|
||||||
// Ensure userData.id and sandboxData.id are available before attempting to connect
|
// Ensure userData.id and sandboxData.id are available before attempting to connect
|
||||||
if (userData.id && sandboxData.id) {
|
if (userData.id && sandboxData.id) {
|
||||||
// Check if the socket is not initialized or not connected
|
// Check if the socket is not initialized or not connected
|
||||||
if (!socket || (socket && !socket.connected)) {
|
if (!socket || (socket && !socket.connected)) {
|
||||||
// Initialize socket connection
|
// Initialize socket connection
|
||||||
console.log('Initializing socket...');
|
|
||||||
setUserAndSandboxId(userData.id, sandboxData.id);
|
setUserAndSandboxId(userData.id, sandboxData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -433,7 +431,7 @@ export default function CodeEditor({
|
|||||||
return () => {
|
return () => {
|
||||||
socket?.disconnect()
|
socket?.disconnect()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [socket])
|
||||||
|
|
||||||
// Socket event listener effect
|
// Socket event listener effect
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -445,7 +443,6 @@ 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) => {
|
||||||
@ -484,7 +481,6 @@ export default function CodeEditor({
|
|||||||
socket?.off("disableAccess", onDisableAccess)
|
socket?.off("disableAccess", onDisableAccess)
|
||||||
socket?.off("previewURL", loadPreviewURL)
|
socket?.off("previewURL", loadPreviewURL)
|
||||||
}
|
}
|
||||||
// }, []);
|
|
||||||
}, [socket, terminals, setTerminals, setFiles, toast, setDisableAccess, isOwner, loadPreviewURL]);
|
}, [socket, terminals, setTerminals, setFiles, toast, setDisableAccess, isOwner, loadPreviewURL]);
|
||||||
|
|
||||||
// Helper functions for tabs:
|
// Helper functions for tabs:
|
||||||
@ -495,14 +491,13 @@ export default function CodeEditor({
|
|||||||
const fileCache = useRef(new Map());
|
const fileCache = useRef(new Map());
|
||||||
|
|
||||||
// Debounced function to get file content
|
// Debounced function to get file content
|
||||||
const debouncedGetFile = useCallback(
|
const debouncedGetFile =
|
||||||
debounce((tabId, callback) => {
|
(tabId: any, callback: any) => {
|
||||||
socket?.emit('getFile', tabId, callback);
|
socket?.emit('getFile', tabId, callback);
|
||||||
}, 300), // 300ms debounce delay, adjust as needed
|
} // 300ms debounce delay, adjust as needed
|
||||||
[]
|
|
||||||
);
|
const selectFile = (tab: TTab) => {
|
||||||
|
|
||||||
const selectFile = useCallback((tab: TTab) => {
|
|
||||||
if (tab.id === activeFileId) return;
|
if (tab.id === activeFileId) return;
|
||||||
|
|
||||||
setGenerate((prev) => ({ ...prev, show: false }));
|
setGenerate((prev) => ({ ...prev, show: false }));
|
||||||
@ -527,7 +522,7 @@ export default function CodeEditor({
|
|||||||
|
|
||||||
setEditorLanguage(processFileType(tab.name));
|
setEditorLanguage(processFileType(tab.name));
|
||||||
setActiveFileId(tab.id);
|
setActiveFileId(tab.id);
|
||||||
}, [activeFileId, tabs, debouncedGetFile]);
|
};
|
||||||
|
|
||||||
// Close tab and remove from tabs
|
// Close tab and remove from tabs
|
||||||
const closeTab = (id: string) => {
|
const closeTab = (id: string) => {
|
||||||
|
Reference in New Issue
Block a user