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:
@@ -78,10 +78,25 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleNewFile = () => {
|
const handleNewFile = async () => {
|
||||||
setCurrentFile(null)
|
const filename = prompt('Enter filename:', 'untitled.md')
|
||||||
setContent('# New File\n\nStart writing here...')
|
if (!filename) return
|
||||||
setIsEditing(true)
|
|
||||||
|
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 () => {
|
const handleSave = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user