Pause updates only for the current element

This commit is contained in:
Ingvar Stepanyan
2021-07-13 18:46:04 +00:00
parent f8188667df
commit e5b22b02bb

23
ui.html
View File

@@ -73,9 +73,14 @@
); );
} }
let { value, readonly } = config; let { value, readonly } = config;
let valueProp = type === 'toggle' ? 'checked' : 'value';
// We don't want to override current input's value while user is editing it.
if (document.activeElement?.id === id) {
value = document.activeElement?.[valueProp];
}
let attrs = { let attrs = {
id, id,
value, [valueProp]: value,
readonly, readonly,
disabled: inProgress disabled: inProgress
}; };
@@ -90,11 +95,9 @@
inputElem = readonly ? value : h('input', attrs); inputElem = readonly ? value : h('input', attrs);
break; break;
case 'toggle': { case 'toggle': {
let { value, ...otherAttrs } = attrs;
inputElem = h('input', { inputElem = h('input', {
type: 'checkbox', type: 'checkbox',
checked: value, ...attrs
...otherAttrs
}); });
break; break;
} }
@@ -124,24 +127,18 @@
} }
class Settings extends Component { class Settings extends Component {
state = { pauseUpdates: false, inProgress: false, config: 'Connecting...' }; state = { inProgress: false, config: 'Connecting...' };
constructor() { constructor() {
super(); super();
(async () => { (async () => {
while (true) { while (true) {
if (!this.state.pauseUpdates) { await this.refreshConfig();
await this.refreshConfig();
}
await new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
} }
})(); })();
} }
pauseUpdates = () => this.setState({ pauseUpdates: true });
resumeUpdates = () => this.setState({ pauseUpdates: false });
handleChange = async e => { handleChange = async e => {
let name = e.target.id; let name = e.target.id;
if (!name.startsWith('config-')) { if (!name.startsWith('config-')) {
@@ -207,7 +204,7 @@
await queue; await queue;
// I have no idea why, but if we connect too soon, it just hangs... // I have no idea why, but if we connect too soon, it just hangs...
await new Promise(resolve => setTimeout(resolve, 200)); await new Promise(resolve => setTimeout(resolve, 500));
let canvas = document.getElementById('canvas'); let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('bitmaprenderer'); let ctx = canvas.getContext('bitmaprenderer');