Skip to content

Commit

Permalink
fix #192 handle subfolders when create/delete file, add alerts to avo…
Browse files Browse the repository at this point in the history
…id silent fails
  • Loading branch information
kmcb777 committed Feb 19, 2018
1 parent 1c5f74c commit 7808be7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/pages/Project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,24 @@ class ProjectPage extends Component {
handleAddFile = fileName => {
fs.writeFile(fileName, defaultMJML, err => {
if (err) {
return
this.props.addAlert('Error creating file', 'error')
throw new Error(err)
}
this._filelist.refresh()
})
}

handleRemoveFile = async fileName => {
await trash(fileName)
try {
if (await trash(fileName) === undefined) {
throw new Error('No file was deleted')
}
this.props.addAlert('File successfully removed', 'success')
} catch (e) {
this.props.addAlert('Could not delete file', 'error')
throw new Error(e)
}

this._filelist.refresh()
this.setState({ activeFile: null })
}
Expand Down Expand Up @@ -168,7 +178,6 @@ class ProjectPage extends Component {

render() {
const { preview } = this.props

const { path, activeFile } = this.state

const rootPath = this.props.location.query.path
Expand Down Expand Up @@ -259,8 +268,8 @@ class ProjectPage extends Component {
</div>

<SendModal />
<AddFileModal rootPath={rootPath} onAdd={this.handleAddFile} />
<RemoveFileModal rootPath={rootPath} onRemove={this.handleRemoveFile} />
<AddFileModal rootPath={path} onAdd={this.handleAddFile} />
<RemoveFileModal rootPath={path} onRemove={this.handleRemoveFile} />
</div>
)
}
Expand Down

0 comments on commit 7808be7

Please sign in to comment.