David Lechner
2021-02-01 10:26:05 -06:00
parent aa4e06bef4
commit b30c31f8b7
13 changed files with 58 additions and 89 deletions
+4 -5
View File
@@ -7,7 +7,6 @@ import { AnchorButton, Button, Classes, Dialog } from '@blueprintjs/core';
import { WithI18nProps, withI18n } from '@shopify/react-i18n';
import React from 'react';
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { closeAboutDialog, openLicenseDialog } from '../actions/app';
import { RootState } from '../reducers';
import {
@@ -73,10 +72,10 @@ const mapStateToProps = (state: RootState): StateProps => ({
showAboutDialog: state.app.showAboutDialog,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onClose: (): Action => dispatch(closeAboutDialog()),
onLicenseButtonClick: (): Action => dispatch(openLicenseDialog()),
});
const mapDispatchToProps: DispatchProps = {
onClose: closeAboutDialog,
onLicenseButtonClick: openLicenseDialog,
};
export default connect(
mapStateToProps,
+3 -4
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { toggleBluetooth } from '../actions/ble';
import { RootState } from '../reducers';
import { BleConnectionState } from '../reducers/ble';
@@ -34,8 +33,8 @@ const mapStateToProps = (state: RootState): StateProps => {
}
};
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): Action => dispatch(toggleBluetooth()),
});
const mapDispatchToProps: DispatchProps = {
onAction: toggleBluetooth,
};
export default connect(mapStateToProps, mapDispatchToProps)(ActionButton);
+6 -7
View File
@@ -14,7 +14,6 @@ import React from 'react';
import AceEditor from 'react-ace';
import { IAceEditor } from 'react-ace/lib/types';
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { setEditSession, storageChanged } from '../actions/editor';
import { compile } from '../actions/mpy';
import { toggleBoolean } from '../actions/settings';
@@ -221,14 +220,14 @@ const mapStateToProps = (state: RootState): StateProps => ({
showDocs: state.settings.showDocs,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onSessionChanged: (s): Action => dispatch(setEditSession(s)),
onProgramStorageChanged: (v): Action => dispatch(storageChanged(v)),
const mapDispatchToProps: DispatchProps = {
onSessionChanged: setEditSession,
onProgramStorageChanged: storageChanged,
// REVISIT: the options here might need to be changed - hopefully there is
// one setting that works for all hub types for cases where we aren't connected.
onCheck: (script) => dispatch(compile(script)),
onToggleDocs: () => dispatch(toggleBoolean(SettingId.ShowDocs)),
});
onCheck: compile,
onToggleDocs: () => toggleBoolean(SettingId.ShowDocs),
};
export default connect(
mapStateToProps,
+6 -14
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import { connect } from 'react-redux';
import { Dispatch } from '../actions';
import { flashFirmware } from '../actions/flash-firmware';
import * as notification from '../actions/notification';
import { RootState } from '../reducers';
@@ -25,19 +24,12 @@ const mapStateToProps = (state: RootState): StateProps => ({
progress: state.firmware.progress === null ? undefined : state.firmware.progress,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onFile: (data): void => {
dispatch(flashFirmware(data));
},
onReject: (file): void => {
dispatch(
notification.add('error', `'${file.name}' is not a valid firmware file.`),
);
},
onClick: (): void => {
dispatch(flashFirmware());
},
});
const mapDispatchToProps: DispatchProps = {
onFile: flashFirmware,
onReject: (file) =>
notification.add('error', `'${file.name}' is not a valid firmware file.`),
onClick: () => flashFirmware(),
};
const mergeProps = (
stateProps: StateProps,
+4 -5
View File
@@ -15,7 +15,6 @@ import {
import { WithI18nProps, withI18n } from '@shopify/react-i18n';
import React from 'react';
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { closeLicenseDialog } from '../actions/app';
import { select } from '../actions/license';
import { RootState } from '../reducers';
@@ -152,10 +151,10 @@ const mapStateToProps = (state: RootState): StateProps => ({
licenseInfo: state.license.selected,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onClose: (): Action => dispatch(closeLicenseDialog()),
onSelectPackage: (info): Action => dispatch(select(info)),
});
const mapDispatchToProps: DispatchProps = {
onClose: closeLicenseDialog,
onSelectPackage: select,
};
export default connect(
mapStateToProps,
+5 -11
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { Dispatch } from '../actions';
import * as editor from '../actions/editor';
import * as notification from '../actions/notification';
import { RootState } from '../reducers';
@@ -18,16 +17,11 @@ const mapStateToProps = (state: RootState): StateProps => ({
enabled: state.editor.current !== null,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onFile: (data): void => {
dispatch(editor.open(data));
},
onReject: (file): void => {
dispatch(
notification.add('error', `'${file.name}' is not a valid python file.`),
);
},
});
const mapDispatchToProps: DispatchProps = {
onFile: editor.open,
onReject: (file) =>
notification.add('error', `'${file.name}' is not a valid python file.`),
};
const mergeProps = (
stateProps: StateProps,
+3 -4
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { repl } from '../actions/hub';
import { RootState } from '../reducers';
import { HubRuntimeState } from '../reducers/hub';
@@ -21,9 +20,9 @@ const mapStateToProps = (state: RootState): StateProps => ({
state.hub.runtime === HubRuntimeState.Error,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): Action => dispatch(repl()),
});
const mapDispatchToProps: DispatchProps = {
onAction: repl,
};
const mergeProps = (
stateProps: StateProps,
+3 -4
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { downloadAndRun } from '../actions/hub';
import { RootState } from '../reducers';
import { HubRuntimeState } from '../reducers/hub';
@@ -20,9 +19,9 @@ const mapStateToProps = (state: RootState): StateProps => ({
state.editor.current !== null && state.hub.runtime === HubRuntimeState.Idle,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): Action => dispatch(downloadAndRun()),
});
const mapDispatchToProps: DispatchProps = {
onAction: downloadAndRun,
};
const mergeProps = (
stateProps: StateProps,
+3 -6
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { Dispatch } from '../actions';
import * as editor from '../actions/editor';
import { RootState } from '../reducers';
import ActionButton, { ActionButtonProps } from './ActionButton';
@@ -18,11 +17,9 @@ const mapStateToProps = (state: RootState): StateProps => ({
enabled: state.editor.current !== null,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): void => {
dispatch(editor.saveAs());
},
});
const mapDispatchToProps: DispatchProps = {
onAction: editor.saveAs,
};
const mergeProps = (
stateProps: StateProps,
+3 -4
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2021 The Pybricks Authors
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { openSettings as openSettings } from '../actions/app';
import ActionButton, { ActionButtonProps } from './ActionButton';
import { TooltipId } from './button-i18n';
@@ -12,9 +11,9 @@ type StateProps = undefined;
type DispatchProps = Pick<ActionButtonProps, 'onAction'>;
type OwnProps = Pick<ActionButtonProps, 'id'>;
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): Action => dispatch(openSettings()),
});
const mapDispatchToProps: DispatchProps = {
onAction: openSettings,
};
const mergeProps = (
_stateProps: StateProps,
+12 -15
View File
@@ -18,7 +18,6 @@ import {
import { WithI18nProps, withI18n } from '@shopify/react-i18n';
import React from 'react';
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import {
checkForUpdate,
closeSettings,
@@ -330,20 +329,18 @@ const mapStateToProps = (state: RootState): StateProps => ({
readyForOfflineUse: state.app.readyForOfflineUse,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onClose: (): Action => dispatch(closeSettings()),
onShowDocsChanged: (checked): Action =>
dispatch(setBoolean(SettingId.ShowDocs, checked)),
onDarkModeChanged: (checked): Action =>
dispatch(setBoolean(SettingId.DarkMode, checked)),
onFlashCurrentProgramChanged: (checked): Action =>
dispatch(setBoolean(SettingId.FlashCurrentProgram, checked)),
onAbout: (): Action => dispatch(openAboutDialog()),
onToggleDocs: (): Action => dispatch(toggleBoolean(SettingId.ShowDocs)),
onCheckForUpdate: (registration) => dispatch(checkForUpdate(registration)),
onReload: (registration) => dispatch(reload(registration)),
onInstallPrompt: (event) => dispatch(installPrompt(event)),
});
const mapDispatchToProps: DispatchProps = {
onClose: closeSettings,
onShowDocsChanged: (checked) => setBoolean(SettingId.ShowDocs, checked),
onDarkModeChanged: (checked) => setBoolean(SettingId.DarkMode, checked),
onFlashCurrentProgramChanged: (checked) =>
setBoolean(SettingId.FlashCurrentProgram, checked),
onAbout: openAboutDialog,
onToggleDocs: () => toggleBoolean(SettingId.ShowDocs),
onCheckForUpdate: checkForUpdate,
onReload: reload,
onInstallPrompt: installPrompt,
};
export default connect(
mapStateToProps,
+3 -4
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { stop } from '../actions/hub';
import { RootState } from '../reducers';
import { HubRuntimeState } from '../reducers/hub';
@@ -19,9 +18,9 @@ const mapStateToProps = (state: RootState): StateProps => ({
enabled: state.hub.runtime === HubRuntimeState.Running,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): Action => dispatch(stop()),
});
const mapDispatchToProps: DispatchProps = {
onAction: stop,
};
const mergeProps = (
stateProps: StateProps,
+3 -6
View File
@@ -14,7 +14,6 @@ import { connect } from 'react-redux';
import { Observable, Unsubscribe } from 'redux';
import { Terminal as XTerm } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { Dispatch } from '../actions';
import { receiveData } from '../actions/terminal';
import { RootState } from '../reducers';
import { isMacOS } from '../utils/os';
@@ -175,11 +174,9 @@ const mapStateToProps = (state: RootState): StateProps => ({
darkMode: state.settings.darkMode,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onData: (d): void => {
dispatch(receiveData(d));
},
});
const mapDispatchToProps: DispatchProps = {
onData: receiveData,
};
export default connect(
mapStateToProps,