Add/remove one file in Content Manager for Bookshelf

This commit is contained in:
Aurelsicoko 2018-03-02 16:31:32 +01:00
parent 5f0618f94c
commit 2bdf226490
3 changed files with 28 additions and 30 deletions

View File

@ -134,18 +134,6 @@ class ImgPreview extends React.Component {
this.props.onDrop(e);
}
handleMouseEnter = (e) => {
e.preventDefault();
e.stopPropagation();
this.setState({ isOver: true });
}
handleMouseLeave = (e) => {
e.preventDefault();
e.stopPropagation();
this.setState({ isOver: false });
}
// TODO change logic to depend on the type
isPictureType = (fileName) => /\.(jpe?g|png|gif)$/i.test(fileName);
@ -188,12 +176,10 @@ class ImgPreview extends React.Component {
)}
onDragOver={this.handleDragOver}
onDragEnter={this.handleDragEnter}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
style={containerStyle}
>
<div
className={cn(this.state.isDraging && styles.overlay || this.state.isOver && !this.state.isOverArrow && styles.overlay)}
className={cn(this.state.isDraging && styles.overlay)}
onDragLeave={this.handleDragLeave}
onDragOver={this.handleDragOver}
onDrop={this.handleDrop}
@ -203,13 +189,13 @@ class ImgPreview extends React.Component {
displayHint={isEmpty(files)}
onClick={onBrowseClick}
onDrop={this.handleDrop}
showWhiteHint={this.state.isDraging || this.state.isOver && !this.state.isOverArrow || isEmpty(files)}
showWhiteHint={this.state.isDraging || isEmpty(files)}
/>
{ !isEmpty(imgURL) && this.renderContent() }
<ImgPreviewArrow
enable={this.state.isOver && isArray(files) && size(files) > 1}
enable={isArray(files) && size(files) > 1}
onClick={this.handleClick}
onMouseEnter={(e) => this.setState({ isOverArrow: true })}
onMouseLeave={(e) => this.setState({ isOverArrow: false })}
@ -218,7 +204,7 @@ class ImgPreview extends React.Component {
/>
<ImgPreviewArrow
enable={this.state.isOver && isArray(files) && size(files) > 1}
enable={isArray(files) && size(files) > 1}
onClick={this.handleClick}
onMouseEnter={(e) => this.setState({ isOverArrow: true })}
onMouseLeave={(e) => this.setState({ isOverArrow: false })}

View File

@ -198,13 +198,19 @@ module.exports = {
case 'oneToManyMorph':
case 'manyToManyMorph':
const transformToArrayID = (array) => {
return _.isArray(array) ? array.map(value => {
if (_.isPlainObject(value)) {
return value._id || value.id;
}
if(_.isArray(array)) {
return array.map(value => {
if (_.isPlainObject(value)) {
return value._id || value.id;
}
return value;
}) : transformToArrayID(_.isEmpty(array) ? [] : [array]);
return value;
})
}
if (_.isPlainObject(array)) {
return _.isEmpty(array) ? [] : transformToArrayID([array]);
}
};
// Compare array of ID to find deleted files.

View File

@ -190,13 +190,19 @@ module.exports = {
case 'oneToManyMorph':
case 'manyToManyMorph':
const transformToArrayID = (array) => {
return _.isArray(array) ? array.map(value => {
if (_.isPlainObject(value)) {
return value._id || value.id;
}
if (_.isArray(array)) {
return array.map(value => {
if (_.isPlainObject(value)) {
return value._id || value.id;
}
return value;
}) : transformToArrayID(_.isEmpty(array) ? [] : [array]);
return value;
})
}
if (_.isPlainObject(array)) {
return _.isEmpty(array) ? [] : transformToArrayID([array]);
}
};
// Compare array of ID to find deleted files.