mirror of
https://github.com/chinchang/web-maker.git
synced 2025-05-06 18:45:31 +02:00
Add file removal
This commit is contained in:
parent
4b800da883
commit
9866b2dbd9
@ -52,14 +52,16 @@ export default class ContentWrap2 extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
|
const { currentItem } = this.props;
|
||||||
|
|
||||||
|
// Select a new file if nothing is selected already or the selected file exists no more.
|
||||||
if (
|
if (
|
||||||
this.props.currentItem &&
|
currentItem &&
|
||||||
this.props.currentItem.files &&
|
currentItem.files &&
|
||||||
!this.state.selectedFile
|
(!this.state.selectedFile ||
|
||||||
|
!currentItem.files.includes(this.state.selectedFile))
|
||||||
) {
|
) {
|
||||||
this.setState({
|
this.fileSelectHandler(this.props.currentItem.files[0]);
|
||||||
selectedFile: this.props.currentItem.files[0]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// HACK: becuase its a DOM manipulation
|
// HACK: becuase its a DOM manipulation
|
||||||
// window.logCountEl.textContent = this.logCount;
|
// window.logCountEl.textContent = this.logCount;
|
||||||
@ -438,6 +440,7 @@ export default class ContentWrap2 extends Component {
|
|||||||
selectedFile={this.state.selectedFile}
|
selectedFile={this.state.selectedFile}
|
||||||
onFileSelect={this.fileSelectHandler.bind(this)}
|
onFileSelect={this.fileSelectHandler.bind(this)}
|
||||||
onAddFile={this.props.onAddFile}
|
onAddFile={this.props.onAddFile}
|
||||||
|
onRemoveFile={this.props.onRemoveFile}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="code-side" id="js-code-side">
|
<div class="code-side" id="js-code-side">
|
||||||
|
@ -64,8 +64,15 @@ export class SidePane extends Component {
|
|||||||
this.setState({ isEditing: false });
|
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() {
|
render() {
|
||||||
const { files, onFileSelect, selectedFile } = this.props;
|
const { files, onFileSelect, selectedFile, onRemoveFile } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="sidebar">
|
<div class="sidebar">
|
||||||
@ -105,8 +112,24 @@ export class SidePane extends Component {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={onFileSelect.bind(null, file)}
|
onClick={onFileSelect.bind(null, file)}
|
||||||
>
|
>
|
||||||
<FileIcon fileName={file.name} />
|
<div class="flex flex-v-center">
|
||||||
{file.name}
|
<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>
|
</button>
|
||||||
</div>
|
</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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -1222,6 +1232,7 @@ export default class App extends Component {
|
|||||||
onEditorFocus={this.editorFocusHandler.bind(this)}
|
onEditorFocus={this.editorFocusHandler.bind(this)}
|
||||||
onSplitUpdate={this.splitUpdateHandler.bind(this)}
|
onSplitUpdate={this.splitUpdateHandler.bind(this)}
|
||||||
onAddFile={this.addFileHandler.bind(this)}
|
onAddFile={this.addFileHandler.bind(this)}
|
||||||
|
onRemoveFile={this.removeFileHandler.bind(this)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Footer
|
<Footer
|
||||||
|
@ -1615,17 +1615,19 @@ body:not(.is-app) .show-when-app {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sidebar__file {
|
.sidebar__file {
|
||||||
color: #f3f3f3;
|
color: #bbb;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
padding: 2px 4px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
.sidebar__file.selected {
|
.sidebar__file.selected {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: mediumblue;
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar__file-icon {
|
.sidebar__file-icon {
|
||||||
@ -1633,7 +1635,13 @@ body:not(.is-app) .show-when-app {
|
|||||||
height: 16px;
|
height: 16px;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
.sidebar__file-options {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
.sidebar__file:hover .sidebar__file-options,
|
||||||
|
.sidebar__file:focus .sidebar__file-options {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
@media screen and (max-width: 600px) {
|
@media screen and (max-width: 600px) {
|
||||||
body {
|
body {
|
||||||
font-size: 70%;
|
font-size: 70%;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user