Skip to content

Commit

Permalink
fixed nod big
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Jun 24, 2020
1 parent 58267ef commit 74a29e3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
98 changes: 49 additions & 49 deletions src/SubblocksEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import move from 'lodash-move'
import { isEqual } from 'lodash'
import { defineMessages } from 'react-intl'
import { Button } from 'semantic-ui-react'
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import move from 'lodash-move';
import { isEqual } from 'lodash';
import { defineMessages } from 'react-intl';
import { Button } from 'semantic-ui-react';

import './volto-subblocks.css'
import './volto-subblocks.css';

const messages = defineMessages({
addBlock: {
id: 'Add block',
defaultMessage: 'Add block',
},
})
});

class SubblocksEdit extends Component {
/**
Expand All @@ -34,37 +34,37 @@ class SubblocksEdit extends Component {
onSelectBlock: PropTypes.func.isRequired,
openObjectBrowser: PropTypes.func.isRequired,
pathname: PropTypes.string.isRequired,
}
};

constructor(props) {
super(props)
let subblocks = []
super(props);
let subblocks = [];

if (!__SERVER__) {
if (props.data && props.data.subblocks) {
subblocks = props.data.subblocks
subblocks = props.data.subblocks;
}
}

this.state = { subblocks }
this.state = { subblocks };
}

state = {
subblocks: [],
subIndexSelected: 0,
}
};

/**
* Component will receive props
* @method componentDidMount
* @returns {undefined}
*/
componentDidMount() {
if (this.props.selected) {
this.node.focus()
if (this.props.selected && this.node) {
this.node.focus();
}
if (this.state.subblocks.length === 0) {
this.addSubblock()
this.addSubblock();
}
}

Expand All @@ -75,7 +75,7 @@ class SubblocksEdit extends Component {
*/
componentWillUnmount() {
if (this.props.selected && this.node) {
this.node.focus()
this.node.focus();
}
}

Expand All @@ -87,19 +87,19 @@ class SubblocksEdit extends Component {
*/
onChangeSubblocks = (subblockIndex, subblock) => {
if (!isEqual(subblock, this.state.subblocks[subblockIndex])) {
var subblocks = this.state.subblocks
var subblocks = this.state.subblocks;

subblocks[subblockIndex] = subblock
subblocks[subblockIndex] = subblock;

this.props.onChangeBlock(this.props.block, {
...this.props.data,
subblocks: subblocks,
lastChange: new Date().getTime(),
})
});

this.setState({ subblocks })
this.setState({ subblocks });
}
}
};

/**
* Move block handler
Expand All @@ -109,42 +109,42 @@ class SubblocksEdit extends Component {
* @returns {undefined}
*/
onMoveSubblock = (dragIndex, hoverIndex) => {
const subblocks = move(this.props.data.subblocks, dragIndex, hoverIndex)
const subblocks = move(this.props.data.subblocks, dragIndex, hoverIndex);

this.props.onChangeBlock(this.props.block, {
...this.props.data,
subblocks: subblocks,
})
});

this.setState({ subblocks })
}
this.setState({ subblocks });
};

addSubblock = () => {
var s = this.state.subblocks
var id = new Date().getTime().toString()
var newBlock = { id: id }
s.push({})
var s = this.state.subblocks;
var id = new Date().getTime().toString();
var newBlock = { id: id };
s.push({});
this.setState({
subblocks: s,
})
var index = this.state.subblocks.length - 1
this.onChangeSubblocks(index, newBlock)
this.onSubblockChangeFocus(index)
}
});
var index = this.state.subblocks.length - 1;
this.onChangeSubblocks(index, newBlock);
this.onSubblockChangeFocus(index);
};

onSubblockChangeFocus = (index) => {
this.setState({ subIndexSelected: index })
}
this.setState({ subIndexSelected: index });
};

deleteSubblock = (index) => {
var sbb = this.state.subblocks
var subblocks = [...sbb.slice(0, index), ...sbb.slice(index + 1)]
this.setState({ subblocks })
var sbb = this.state.subblocks;
var subblocks = [...sbb.slice(0, index), ...sbb.slice(index + 1)];
this.setState({ subblocks });
this.props.onChangeBlock(this.props.block, {
...this.props.data,
subblocks: subblocks,
})
}
});
};

renderAddBlockButton = (title) => {
return (
Expand All @@ -153,12 +153,12 @@ class SubblocksEdit extends Component {
{title ? title : this.props.intl.formatMessage(messages.addBlock)}
</Button>
)
)
}
);
};

isSubblockSelected = (subindex) => {
return this.props.selected && this.state.subIndexSelected === subindex
}
return this.props.selected && this.state.subIndexSelected === subindex;
};

subblockProps = {
block: this.props.block,
Expand All @@ -167,7 +167,7 @@ class SubblocksEdit extends Component {
onMoveSubblock: this.onMoveSubblock,
onDelete: this.deleteSubblock,
nblock: this.state.subblocks.length,
}
};
}

export default SubblocksEdit
export default SubblocksEdit;
12 changes: 6 additions & 6 deletions src/SubblocksWrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react'
import cx from 'classnames'
import React from 'react';
import cx from 'classnames';

const SubblocksWrapper = ({ className, children, node }) => {
return (
<div
className={cx('volto-subblocks-wrapper', className)}
ref={(_node) => {
node = _node
node = _node;
}}
>
{children}
</div>
)
}
);
};

export default SubblocksWrapper
export default SubblocksWrapper;

0 comments on commit 74a29e3

Please sign in to comment.