mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-31 18:50:14 +02:00
Add file removal
This commit is contained in:
@@ -52,14 +52,16 @@ export default class ContentWrap2 extends Component {
|
||||
}
|
||||
}
|
||||
componentDidUpdate() {
|
||||
const { currentItem } = this.props;
|
||||
|
||||
// Select a new file if nothing is selected already or the selected file exists no more.
|
||||
if (
|
||||
this.props.currentItem &&
|
||||
this.props.currentItem.files &&
|
||||
!this.state.selectedFile
|
||||
currentItem &&
|
||||
currentItem.files &&
|
||||
(!this.state.selectedFile ||
|
||||
!currentItem.files.includes(this.state.selectedFile))
|
||||
) {
|
||||
this.setState({
|
||||
selectedFile: this.props.currentItem.files[0]
|
||||
});
|
||||
this.fileSelectHandler(this.props.currentItem.files[0]);
|
||||
}
|
||||
// HACK: becuase its a DOM manipulation
|
||||
// window.logCountEl.textContent = this.logCount;
|
||||
@@ -438,6 +440,7 @@ export default class ContentWrap2 extends Component {
|
||||
selectedFile={this.state.selectedFile}
|
||||
onFileSelect={this.fileSelectHandler.bind(this)}
|
||||
onAddFile={this.props.onAddFile}
|
||||
onRemoveFile={this.props.onRemoveFile}
|
||||
/>
|
||||
</div>
|
||||
<div class="code-side" id="js-code-side">
|
||||
|
@@ -64,8 +64,15 @@ export class SidePane extends Component {
|
||||
this.setState({ isEditing: false });
|
||||
}
|
||||
}
|
||||
removeFileClickHandler(file, e) {
|
||||
e.stopPropagation();
|
||||
const answer = confirm(`Are you sure you want to delete ${file.name}?`);
|
||||
if (answer) {
|
||||
this.props.onRemoveFile(file);
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const { files, onFileSelect, selectedFile } = this.props;
|
||||
const { files, onFileSelect, selectedFile, onRemoveFile } = this.props;
|
||||
|
||||
return (
|
||||
<div class="sidebar">
|
||||
@@ -105,8 +112,24 @@ export class SidePane extends Component {
|
||||
type="button"
|
||||
onClick={onFileSelect.bind(null, file)}
|
||||
>
|
||||
<FileIcon fileName={file.name} />
|
||||
{file.name}
|
||||
<div class="flex flex-v-center">
|
||||
<FileIcon fileName={file.name} />
|
||||
{file.name}
|
||||
</div>
|
||||
<div class="sidebar__file-options">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn--dark"
|
||||
onClick={this.removeFileClickHandler.bind(this, file)}
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
style="vertical-align:middle;width:14px;height:14px"
|
||||
>
|
||||
<path d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
|
@@ -1191,6 +1191,16 @@ export default class App extends Component {
|
||||
}
|
||||
});
|
||||
}
|
||||
removeFileHandler(fileToRemove) {
|
||||
this.setState({
|
||||
currentItem: {
|
||||
...this.state.currentItem,
|
||||
files: this.state.currentItem.files.filter(
|
||||
file => file !== fileToRemove
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
@@ -1222,6 +1232,7 @@ export default class App extends Component {
|
||||
onEditorFocus={this.editorFocusHandler.bind(this)}
|
||||
onSplitUpdate={this.splitUpdateHandler.bind(this)}
|
||||
onAddFile={this.addFileHandler.bind(this)}
|
||||
onRemoveFile={this.removeFileHandler.bind(this)}
|
||||
/>
|
||||
|
||||
<Footer
|
||||
|
Reference in New Issue
Block a user