ohif-viewer/src/connectedComponents/ConnectedLayoutButton.js

42 lines
962 B
JavaScript
Raw Normal View History

2019-01-06 21:59:25 +01:00
import { connect } from 'react-redux';
import { LayoutButton } from 'react-viewerbase';
2019-05-29 14:39:54 +02:00
import OHIF from 'ohif-core';
2019-01-06 21:59:25 +01:00
const { setLayout } = OHIF.redux.actions;
const mapStateToProps = state => {
2019-05-29 14:39:54 +02:00
return {
currentLayout: state.viewports.layout,
};
2019-01-06 21:59:25 +01:00
};
const mapDispatchToProps = dispatch => {
2019-05-29 14:39:54 +02:00
return {
// TODO: Change if layout switched becomes more complex
onChange: selectedCell => {
let viewports = [];
const rows = selectedCell.row + 1;
const columns = selectedCell.col + 1;
const numViewports = rows * columns;
for (let i = 0; i < numViewports; i++) {
viewports.push({
height: `${100 / rows}%`,
width: `${100 / columns}%`,
});
}
const layout = {
viewports,
};
2019-01-06 21:59:25 +01:00
2019-05-29 14:39:54 +02:00
dispatch(setLayout(layout));
},
};
2019-01-06 21:59:25 +01:00
};
const ConnectedLayoutButton = connect(
2019-05-29 14:39:54 +02:00
mapStateToProps,
mapDispatchToProps
2019-01-06 21:59:25 +01:00
)(LayoutButton);
export default ConnectedLayoutButton;