start file saving logic

This commit is contained in:
Ishaan Dey
2024-04-27 16:41:25 -04:00
parent d941e2c056
commit d6769f3407
3 changed files with 40 additions and 1 deletions

View File

@ -49,9 +49,34 @@ export default function CodeEditor({
`http://localhost:4000?userId=${userId}&sandboxId=${sandboxId}`
)
useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "s" && (e.metaKey || e.ctrlKey)) {
e.preventDefault()
const activeTab = tabs.find((t) => t.id === activeId)
console.log("saving " + activeTab?.name)
setTabs((prev) =>
prev.map((tab) =>
tab.id === activeId ? { ...tab, saved: true } : tab
)
)
socket.emit("saveFile", activeId, editorRef.current?.getValue())
}
}
document.addEventListener("keydown", down)
return () => {
document.removeEventListener("keydown", down)
}
}, [tabs, activeId])
// WS event handlers ------------
// connection/disconnection effect
useEffect(() => {
console.log("connecting")
socket.connect()
return () => {
@ -80,6 +105,8 @@ export default function CodeEditor({
}
}, [])
// ------------
const clerk = useClerk()
const selectFile = (tab: TTab) => {