Skip to content

Commit e3b33a5

Browse files
author
Aaron Imming
committed
Ensure correct button status
1 parent db5793f commit e3b33a5

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

src/botPage/view/View.js

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,17 @@ export default class View {
511511
});
512512

513513
const startBot = limitations => {
514-
const $runButtons = $('#runButton, #summaryRunButton');
515-
const $stopButtons = $('#stopButton, #summaryStopButton');
516-
$stopButtons.show();
517-
$runButtons.hide();
518-
$runButtons.prop('disabled', true);
514+
const el_run_buttons = document.querySelectorAll('#runButton, #summaryRunButton');
515+
const el_stop_buttons = document.querySelectorAll('#stopButton, #summaryStopButton');
516+
517+
el_run_buttons.forEach(el_run_button => {
518+
el_run_button.style.display = 'none';
519+
el_run_button.setAttributeNode(document.createAttribute('disabled'));
520+
});
521+
el_stop_buttons.forEach(el_stop_button => {
522+
el_stop_button.style.display = 'initial';
523+
});
524+
519525
globalObserver.emit('summary.disable_clear');
520526
showSummary();
521527
this.blockly.run(limitations);
@@ -627,31 +633,47 @@ export default class View {
627633
this.blockly.stop();
628634
}
629635
addEventHandlers() {
636+
const getRunButtonElements = () => document.querySelectorAll('#runButton, #summaryRunButton');
637+
const getStopButtonElements = () => document.querySelectorAll('#stopButton, #summaryStopButton');
638+
630639
window.addEventListener('storage', e => {
631640
window.onbeforeunload = null;
632641
if (e.key === 'activeToken' && !e.newValue) window.location.reload();
633642
if (e.key === 'realityCheckTime') hideRealityCheck();
634643
});
635644

636645
globalObserver.register('Error', error => {
637-
$('#runButton, #summaryRunButton').prop('disabled', false);
646+
getRunButtonElements().forEach(el_run_button => el_run_button.removeAttribute('disabled'));
647+
638648
if (error.error && error.error.error.code === 'InvalidToken') {
639649
removeAllTokens();
640650
updateTokenList();
641651
this.stop();
642652
}
643653
});
644654

655+
globalObserver.register('bot.running', () => {
656+
getRunButtonElements().forEach(el_run_button => {
657+
el_run_button.style.display = 'none';
658+
el_run_button.setAttributeNode(document.createAttribute('disabled'));
659+
});
660+
getStopButtonElements().forEach(el_stop_button => {
661+
el_stop_button.style.display = 'inline-block';
662+
el_stop_button.removeAttribute('disabled');
663+
});
664+
});
665+
645666
globalObserver.register('bot.stop', () => {
646-
const $runButtons = $('#runButton, #summaryRunButton');
647-
const $stopButtons = $('#stopButton, #summaryStopButton');
648-
if ($runButtons.is(':visible') || $stopButtons.is(':visible')) {
649-
$runButtons.show();
650-
$stopButtons.hide();
651-
652-
$stopButtons.prop('disabled', false);
653-
$runButtons.prop('disabled', false);
654-
}
667+
// Enable run button, this event is emitted after the interpreter
668+
// killed the API connection.
669+
getStopButtonElements().forEach(el_stop_button => {
670+
el_stop_button.style.display = 'none';
671+
el_stop_button.removeAttribute('disabled');
672+
});
673+
getRunButtonElements().forEach(el_run_button => {
674+
el_run_button.style.display = null;
675+
el_run_button.removeAttribute('disabled');
676+
});
655677
});
656678

657679
globalObserver.register('bot.info', info => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy