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
This commit is contained in:
2026-02-06 16:47:47 -05:00
parent 702281c6cf
commit f7cec0af43

View File

@@ -78,11 +78,26 @@ function App() {
}
}
const handleNewFile = () => {
setCurrentFile(null)
setContent('# New File\n\nStart writing here...')
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 () => {
if (!currentFile) {