From f7cec0af4385b75ce6f32a879e1b517e78b0a7de Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Fri, 6 Feb 2026 16:47:47 -0500 Subject: [PATCH] feat: create file on backend when clicking New File - Prompt for filename before creating new file - POST to /api/files to create the file on backend - Set created file as currentFile and enter editing mode - Add error handling for failed API calls --- frontend/src/App.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 15975aa..c275a4b 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -78,10 +78,25 @@ function App() { } } - const handleNewFile = () => { - setCurrentFile(null) - setContent('# New File\n\nStart writing here...') - setIsEditing(true) + const handleNewFile = async () => { + const filename = prompt('Enter filename:', 'untitled.md') + if (!filename) return + + try { + const response = await fetch('/api/files', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({filename, content: '# New File\n\nStart writing here...', title: filename.replace('.md', '')}) + }) + if (response.ok) { + const newFile = await response.json() + setCurrentFile(newFile) + setContent(newFile.content) + setIsEditing(true) + } + } catch (error) { + console.error('Failed to create new file:', error) + } } const handleSave = async () => {