delete files, only client side
This commit is contained in:
parent
acd5aa8c83
commit
5f694329db
3 changed files with 26 additions and 13 deletions
|
@ -153,9 +153,10 @@ export function updateFileName(id, name) {
|
|||
};
|
||||
}
|
||||
|
||||
export function deleteFile(id) {
|
||||
export function deleteFile(id, parentId) {
|
||||
return {
|
||||
type: ActionTypes.DELETE_FILE,
|
||||
id
|
||||
id,
|
||||
parentId
|
||||
};
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ export class FileNode extends React.Component {
|
|||
<a
|
||||
onClick={() => {
|
||||
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
|
||||
this.props.deleteFile(this.props.id);
|
||||
this.props.deleteFile(this.props.id, this.props.parentId);
|
||||
this.props.resetSelectedFile();
|
||||
}
|
||||
}}
|
||||
|
@ -135,6 +135,7 @@ export class FileNode extends React.Component {
|
|||
|
||||
FileNode.propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
parentId: PropTypes.string,
|
||||
children: PropTypes.array,
|
||||
name: PropTypes.string.isRequired,
|
||||
isSelected: PropTypes.bool,
|
||||
|
|
|
@ -92,15 +92,17 @@ const files = (state, action) => {
|
|||
case ActionTypes.RESET_PROJECT:
|
||||
return initialState();
|
||||
case ActionTypes.CREATE_FILE: // eslint-disable-line
|
||||
const newState = state.map((file) => {
|
||||
if (file.id === action.parentId) {
|
||||
const newFile = Object.assign({}, file);
|
||||
newFile.children = [...newFile.children, action.id];
|
||||
return newFile;
|
||||
}
|
||||
return file;
|
||||
});
|
||||
return [...newState, { name: action.name, id: action.id, _id: action._id, content: action.content, url: action.url }];
|
||||
{
|
||||
const newState = state.map((file) => {
|
||||
if (file.id === action.parentId) {
|
||||
const newFile = Object.assign({}, file);
|
||||
newFile.children = [...newFile.children, action.id];
|
||||
return newFile;
|
||||
}
|
||||
return file;
|
||||
});
|
||||
return [...newState, { name: action.name, id: action.id, _id: action._id, content: action.content, url: action.url }];
|
||||
}
|
||||
case ActionTypes.SHOW_FILE_OPTIONS:
|
||||
return state.map(file => {
|
||||
if (file.id !== action.id) {
|
||||
|
@ -126,7 +128,16 @@ const files = (state, action) => {
|
|||
return Object.assign({}, file, { name: action.name });
|
||||
});
|
||||
case ActionTypes.DELETE_FILE:
|
||||
return state.filter(file => file.id !== action.id);
|
||||
{
|
||||
const newState = state.map((file) => {
|
||||
if (file.id === action.parentId) {
|
||||
const newChildren = file.children.filter(child => child !== action.id);
|
||||
return { ...file, children: newChildren };
|
||||
}
|
||||
return file;
|
||||
});
|
||||
return newState.filter(file => file.id !== action.id);
|
||||
}
|
||||
case ActionTypes.SHOW_EDIT_FILE_NAME:
|
||||
return state.map(file => {
|
||||
if (file.id !== action.id) {
|
||||
|
|
Loading…
Reference in a new issue