From bc67cab75f9fa9f8e14fe236b4ea593c628c70de Mon Sep 17 00:00:00 2001 From: Casper Lamboo Date: Wed, 7 Mar 2018 11:14:02 +0100 Subject: [PATCH] Add selected printer query param @companje --- index.js | 4 ++-- src/interface/Settings.js | 46 ++++++++++++++++++++++++++++----------- src/interface/index.js | 4 +++- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 5e02721..7fd587a 100644 --- a/index.js +++ b/index.js @@ -32,10 +32,10 @@ jss.createStyleSheet({ } }).attach(); -const { file } = queryString.parse(location.search); +const { file, selectedPrinter } = queryString.parse(location.search); render(( - + ), document.getElementById('app')); diff --git a/src/interface/Settings.js b/src/interface/Settings.js index 7105f45..a5f2f7d 100644 --- a/src/interface/Settings.js +++ b/src/interface/Settings.js @@ -72,6 +72,7 @@ const updateLocalStorage = (localStorage) => { class Settings extends React.Component { static propTypes = { + selectedPrinter: PropTypes.string, classes: PropTypes.objectOf(PropTypes.string), onChange: PropTypes.func, disabled: PropTypes.bool.isRequired @@ -89,20 +90,39 @@ class Settings extends React.Component { advancedFields: PropTypes.array.isRequired }; - state = { - localStorage: getLocalStorage(), - wifiBoxes: [], - addPrinter: { - open: false, - name: '', - printer: '', - ip: '', - error: null - }, - managePrinter: { - open: false + constructor(props) { + super(props); + + const { selectedPrinter } = this.props; + + const localStorage = getLocalStorage(); + + if (selectedPrinter) { + const active = Object.entries(localStorage.printers) + .map(([key, value]) => ({ key, value })) + .find(({ key, value: { ip } }) => ip === selectedPrinter); + + if (active) { + localStorage.active = active.key; + updateLocalStorage(localStorage); + } } - }; + this.state = { + localStorage, + wifiBoxes: [], + addPrinter: { + open: false, + name: '', + printer: '', + ip: '', + error: null + }, + managePrinter: { + open: false + } + }; + } + componentDidMount() { const { onChange } = this.props; diff --git a/src/interface/index.js b/src/interface/index.js index 4a5f967..0903562 100644 --- a/src/interface/index.js +++ b/src/interface/index.js @@ -106,6 +106,7 @@ const styles = { class Interface extends React.Component { static propTypes = { fileUrl: PropTypes.string, + selectedPrinter: PropTypes.string, mesh: PropTypes.shape({ isMesh: PropTypes.oneOf([true]) }), classes: PropTypes.objectOf(PropTypes.string), pixelRatio: PropTypes.number.isRequired, @@ -332,7 +333,7 @@ class Interface extends React.Component { } render() { - const { classes, onCancel } = this.props; + const { classes, onCancel, selectedPrinter } = this.props; const { isSlicing, progress, showFullScreen, error, objectDimensions, settings } = this.state; const style = { ...(showFullScreen ? {} : { maxWidth: 'inherit', width: '100%', height: '100%' }) }; @@ -340,6 +341,7 @@ class Interface extends React.Component { const settingsPanel = (