toolbar/RunButton: enable only when active file

Before multi-file support, it was not possible to have no open file.
So we need to change the state logic to only enable the button when
there is an active file rather than when the editor "is ready".

Fixes: https://github.com/pybricks/support/issues/691
This commit is contained in:
David Lechner
2022-08-12 18:00:57 -05:00
parent f603f97c25
commit 92431298b2
3 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -3,7 +3,7 @@
import { cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../../test';
import { testRender, uuid } from '../../../../test';
import { downloadAndRun } from '../../../hub/actions';
import { HubRuntimeState } from '../../../hub/reducers';
import RunButton from './RunButton';
@@ -14,7 +14,7 @@ afterEach(() => {
it('should dispatch action when clicked', async () => {
const [user, button, dispatch] = testRender(<RunButton id="test-run-button" />, {
editor: { isReady: true },
editor: { activeFileUuid: uuid(0) },
hub: { runtime: HubRuntimeState.Idle },
});
+2 -2
View File
@@ -16,7 +16,7 @@ const RunButton: React.VoidFunctionComponent<RunButtonProps> = ({ id }) => {
const downloadProgress = useSelector((s) => s.hub.downloadProgress);
const mpyAbiVersion = useSelector((s) => s.hub.mpyAbiVersion);
const runtime = useSelector((s) => s.hub.runtime);
const isEditorReady = useSelector((s) => s.editor.isReady);
const activeFile = useSelector((s) => s.editor.activeFileUuid);
const keyboardShortcut = 'F5';
const i18n = useI18n();
@@ -35,7 +35,7 @@ const RunButton: React.VoidFunctionComponent<RunButtonProps> = ({ id }) => {
: i18n.translate('tooltip.action', { key: keyboardShortcut })
}
icon={icon}
enabled={isEditorReady && runtime === HubRuntimeState.Idle}
enabled={activeFile !== null && runtime === HubRuntimeState.Idle}
showProgress={runtime === HubRuntimeState.Loading}
progress={downloadProgress === null ? undefined : downloadProgress}
onAction={() => dispatch(downloadAndRun(mpyAbiVersion))}