Skip to content

Commit b3bbc31

Browse files
authored
Merge pull request #25 from magjac/configurable-holdoff
Configurable holdoff
2 parents 004261d + 2cbc213 commit b3bbc31

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/SettingsDialog.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import FormGroup from '@material-ui/core/FormGroup';
1111
import FormControlLabel from '@material-ui/core/FormControlLabel';
1212
import Switch from '@material-ui/core/Switch';
1313
import Input from '@material-ui/core/Input';
14+
import InputAdornment from '@material-ui/core/InputAdornment';
1415
import InputLabel from '@material-ui/core/InputLabel';
1516
import MenuItem from '@material-ui/core/MenuItem';
1617
import FormHelperText from '@material-ui/core/FormHelperText';
@@ -33,10 +34,16 @@ const styles = theme => ({
3334
margin: theme.spacing.unit,
3435
minWidth: 120,
3536
},
37+
formControlLabel: {
38+
margin: theme.spacing.unit * -0.5,
39+
},
3640
title: {
3741
display: 'flex',
3842
justifyContent: 'space-between',
3943
},
44+
holdOffInput: {
45+
width: '7em',
46+
}
4047
});
4148

4249
class SettingsDialog extends React.Component {
@@ -53,6 +60,10 @@ class SettingsDialog extends React.Component {
5360
this.props.onFitGraphSwitchChange(event.target.checked);
5461
};
5562

63+
handleHoldOffChange = (event) => {
64+
this.props.onHoldOffChange(event.target.value);
65+
};
66+
5667
render() {
5768
const { classes } = this.props;
5869
return (
@@ -102,6 +113,7 @@ class SettingsDialog extends React.Component {
102113
</DialogContentText>
103114
<FormGroup row>
104115
<FormControlLabel
116+
className={classes.formControlLabel}
105117
control={
106118
<Switch
107119
checked={this.props.fitGraph}
@@ -112,6 +124,30 @@ class SettingsDialog extends React.Component {
112124
/>
113125
</FormGroup>
114126
</DialogContent>
127+
<DialogTitle id="form-dialog-title">Other</DialogTitle>
128+
<DialogContent>
129+
<FormControl
130+
className={classes.formControl}
131+
aria-describedby="holdoff-helper-text"
132+
>
133+
<InputLabel shrink={true}>Editor hold-off time</InputLabel>
134+
<Input
135+
className={classes.holdOffInput}
136+
id="holdoff"
137+
type="number"
138+
value={this.props.holdOff}
139+
onChange={this.handleHoldOffChange}
140+
endAdornment={<InputAdornment position="end"> seconds</InputAdornment>}
141+
inputProps={{
142+
'aria-label': 'Holdoff',
143+
min: 0.0,
144+
max: 9.9,
145+
step: 0.1,
146+
}}
147+
/>
148+
<FormHelperText id="holdoff-helper-text">Time of editor inactivity after which graph rendering starts</FormHelperText>
149+
</FormControl>
150+
</DialogContent>
115151
</Dialog>
116152
</div>
117153
);

src/TextEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TextEditor extends React.Component {
1717
if (this.pendingChanges === 0) {
1818
this.props.onTextChange(value);
1919
}
20-
}, this.props.holdOff);
20+
}, this.props.holdOff * 1000);
2121
};
2222

2323
render() {

src/pages/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Index extends React.Component {
5858
defaultNodeAttributes: JSON.parse(localStorage.getItem('defaultNodeAttributes')) || {},
5959
defaultEdgeAttributes: JSON.parse(localStorage.getItem('defaultEdgeAttributes')) || {},
6060
error: null,
61+
holdOff: localStorage.getItem('holdOff') || 0.2,
6162
};
6263
}
6364

@@ -171,6 +172,12 @@ class Index extends React.Component {
171172
});
172173
}
173174

175+
handleHoldOffChange = (holdOff) => {
176+
this.setPersistentState({
177+
holdOff: holdOff,
178+
});
179+
}
180+
174181
handleNodeShapeClick = (shape) => {
175182
let x0 = null;
176183
let y0 = null;
@@ -355,6 +362,8 @@ class Index extends React.Component {
355362
fitGraph={this.state.fitGraph}
356363
onEngineSelectChange={this.handleEngineSelectChange}
357364
onFitGraphSwitchChange={this.handleFitGraphSwitchChange}
365+
holdOff={this.state.holdOff}
366+
onHoldOffChange={this.handleHoldOffChange}
358367
onSettingsClose={this.handleSettingsClose}
359368
/>
360369
<Grid container
@@ -392,7 +401,7 @@ class Index extends React.Component {
392401
dotSrc={this.state.dotSrc}
393402
onTextChange={this.handleTextChange}
394403
error={this.state.error}
395-
holdOff={200}
404+
holdOff={this.state.holdOff}
396405
/>
397406
)}
398407
</div>

0 commit comments

Comments
 (0)