Add selected printer query param

@companje
This commit is contained in:
Casper Lamboo 2018-03-07 11:14:02 +01:00
parent 229929e4e8
commit bc67cab75f
3 changed files with 38 additions and 16 deletions

View File

@ -32,10 +32,10 @@ jss.createStyleSheet({
}
}).attach();
const { file } = queryString.parse(location.search);
const { file, selectedPrinter } = queryString.parse(location.search);
render((
<MuiThemeProvider muiTheme={muiTheme}>
<Interface fileUrl={file} name="doodle"/>
<Interface fileUrl={file} selectedPrinter={selectedPrinter} name="doodle"/>
</MuiThemeProvider>
), document.getElementById('app'));

View File

@ -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,8 +90,25 @@ class Settings extends React.Component {
advancedFields: PropTypes.array.isRequired
};
state = {
localStorage: getLocalStorage(),
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,
@ -103,6 +121,8 @@ class Settings extends React.Component {
open: false
}
};
}
componentDidMount() {
const { onChange } = this.props;

View File

@ -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 = (
<div className={classes.settingsBar} style={style}>
<Settings
selectedPrinter={selectedPrinter}
disabled={isSlicing}
onChange={this.onChangeSettings}
/>