only request doodle printers when adding or managing printers

This commit is contained in:
Casper Lamboo 2018-04-23 12:27:16 +02:00
parent 0119c91001
commit f109147e62

View File

@ -25,7 +25,6 @@ import { Doodle3DManager } from 'doodle3d-api';
const DOODLE_3D_MANAGER = new Doodle3DManager(); const DOODLE_3D_MANAGER = new Doodle3DManager();
DOODLE_3D_MANAGER.checkNonServerBoxes = false; DOODLE_3D_MANAGER.checkNonServerBoxes = false;
DOODLE_3D_MANAGER.setAutoUpdate(true, 5000);
const CONNECT_URL = 'http://connect.doodle3d.com/'; const CONNECT_URL = 'http://connect.doodle3d.com/';
@ -127,8 +126,8 @@ class Settings extends React.Component {
} }
const eventListener = ({ boxes }) => this.setState({ wifiBoxes: boxes }); const eventListener = ({ boxes }) => this.setState({ wifiBoxes: boxes });
this.setState({ wifiBoxes: DOODLE_3D_MANAGER.boxes, eventListener });
DOODLE_3D_MANAGER.addEventListener('boxeschanged', eventListener); DOODLE_3D_MANAGER.addEventListener('boxeschanged', eventListener);
this.setState({ eventListener });
} }
componentWillUnmount() { componentWillUnmount() {
@ -361,7 +360,13 @@ class Settings extends React.Component {
closeAddPrinterDialog = (override) => this.setAddPrinterDialog(false, override); closeAddPrinterDialog = (override) => this.setAddPrinterDialog(false, override);
openAddPrinterDialog = (override) => this.setAddPrinterDialog(true, override); openAddPrinterDialog = (override) => this.setAddPrinterDialog(true, override);
setAddPrinterDialog = (open, override = {}) => this.setState({ setAddPrinterDialog = (open, override = {}) => {
if (open) {
DOODLE_3D_MANAGER.setAutoUpdate(true, 10000);
} else {
DOODLE_3D_MANAGER.setAutoUpdate(false);
}
this.setState({
addPrinter: { addPrinter: {
ip: '', ip: '',
name: '', name: '',
@ -371,12 +376,22 @@ class Settings extends React.Component {
...override ...override
} }
}); });
};
closeManagePrinterDialog = () => this.setManagePrinterDialog(false); closeManagePrinterDialog = () => this.setManagePrinterDialog(false);
openManagePrinterDialog = () => this.setManagePrinterDialog(true); openManagePrinterDialog = () => this.setManagePrinterDialog(true);
setManagePrinterDialog = (open) => { setManagePrinterDialog = (open) => {
const { localStorage: { active, printers } } = this.state; const { localStorage: { active, printers } } = this.state;
if (!active) return this.setState({ managePrinter: { open: false } }); if (!active) {
DOODLE_3D_MANAGER.setAutoUpdate(false);
return this.setState({ managePrinter: { open: false } });
}
if (open) {
DOODLE_3D_MANAGER.setAutoUpdate(true, 10000);
} else {
DOODLE_3D_MANAGER.setAutoUpdate(false);
}
this.setState({ this.setState({
managePrinter: { managePrinter: {
open, open,