mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 13:37:58 +01:00
open printer popup with ip if printer is unknown
This commit is contained in:
parent
bc67cab75f
commit
e1c4e2c1d4
@ -90,25 +90,8 @@ class Settings extends React.Component {
|
|||||||
advancedFields: PropTypes.array.isRequired
|
advancedFields: PropTypes.array.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props) {
|
state = {
|
||||||
super(props);
|
localStorage: getLocalStorage(),
|
||||||
|
|
||||||
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: [],
|
wifiBoxes: [],
|
||||||
addPrinter: {
|
addPrinter: {
|
||||||
open: false,
|
open: false,
|
||||||
@ -121,15 +104,27 @@ class Settings extends React.Component {
|
|||||||
open: false
|
open: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { onChange } = this.props;
|
const { onChange, selectedPrinter } = this.props;
|
||||||
const { localStorage } = this.state;
|
const { localStorage } = this.state;
|
||||||
if (localStorage.active) {
|
|
||||||
if (onChange) onChange(this.constructSettings(localStorage));
|
if (selectedPrinter && localStorage.active) {
|
||||||
|
const activePrinter = selectedPrinter && Object.entries(localStorage.printers)
|
||||||
|
.map(([key, value]) => ({ key, value }))
|
||||||
|
.find(({ key, value: { ip } }) => ip === selectedPrinter);
|
||||||
|
|
||||||
|
if (activePrinter) {
|
||||||
|
const state = this.changeSettings('activePrinter', activePrinter.key);
|
||||||
|
if (onChange) onChange(this.constructSettings(state.localStorage));
|
||||||
} else {
|
} else {
|
||||||
|
this.openAddPrinterDialog({ ip: selectedPrinter });
|
||||||
|
}
|
||||||
|
} else if (!selectedPrinter && localStorage.active) {
|
||||||
|
if (onChange) onChange(this.constructSettings(localStorage));
|
||||||
|
} else if (selectedPrinter && !localStorage.active) {
|
||||||
|
this.openAddPrinterDialog({ ip: selectedPrinter });
|
||||||
|
} else if (!selectedPrinter && !localStorage.active) {
|
||||||
this.openAddPrinterDialog();
|
this.openAddPrinterDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +233,8 @@ class Settings extends React.Component {
|
|||||||
if (onChange) onChange(this.constructSettings(state.localStorage));
|
if (onChange) onChange(this.constructSettings(state.localStorage));
|
||||||
updateLocalStorage(state.localStorage);
|
updateLocalStorage(state.localStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildContext() {
|
getChildContext() {
|
||||||
@ -357,9 +354,18 @@ class Settings extends React.Component {
|
|||||||
if (onChange) onChange(this.constructSettings(localStorage));
|
if (onChange) onChange(this.constructSettings(localStorage));
|
||||||
};
|
};
|
||||||
|
|
||||||
closeAddPrinterDialog = () => this.setAddPrinterDialog(false);
|
closeAddPrinterDialog = (override) => this.setAddPrinterDialog(false, override);
|
||||||
openAddPrinterDialog = () => this.setAddPrinterDialog(true);
|
openAddPrinterDialog = (override) => this.setAddPrinterDialog(true, override);
|
||||||
setAddPrinterDialog = (open) => this.setState({ addPrinter: { ip: '', name: '', printer: '', error: null, open } });
|
setAddPrinterDialog = (open, override = {}) => this.setState({
|
||||||
|
addPrinter: {
|
||||||
|
ip: '',
|
||||||
|
name: '',
|
||||||
|
printer: '',
|
||||||
|
error: null,
|
||||||
|
open,
|
||||||
|
...override
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
closeManagePrinterDialog = () => this.setManagePrinterDialog(false);
|
closeManagePrinterDialog = () => this.setManagePrinterDialog(false);
|
||||||
openManagePrinterDialog = () => this.setManagePrinterDialog(true);
|
openManagePrinterDialog = () => this.setManagePrinterDialog(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user