mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
Package firmware in app
- includes firmware .zip for movehub and cplushub - firmware flash button no longer opens file dialog - now connects first, then choses firmware based on connected device - drag and drop of custom firmware still works
This commit is contained in:
committed by
David Lechner
parent
5160d29c7e
commit
33861d970b
@@ -10,7 +10,7 @@ import { BootloaderConnectionState } from '../reducers/bootloader';
|
||||
import OpenFileButton, { OpenFileButtonProps } from './OpenFileButton';
|
||||
|
||||
type StateProps = Pick<OpenFileButtonProps, 'enabled'>;
|
||||
type DispatchProps = Pick<OpenFileButtonProps, 'onFile' | 'onReject'>;
|
||||
type DispatchProps = Pick<OpenFileButtonProps, 'onFile' | 'onReject' | 'onClick'>;
|
||||
type OwnProps = Pick<OpenFileButtonProps, 'id'>;
|
||||
|
||||
const mapStateToProps = (state: RootState): StateProps => ({
|
||||
@@ -26,6 +26,9 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
||||
notification.add('error', `'${file.name}' is not a valid firmware file.`),
|
||||
);
|
||||
},
|
||||
onClick: (): void => {
|
||||
dispatch(flashFirmware());
|
||||
},
|
||||
});
|
||||
|
||||
const mergeProps = (
|
||||
|
||||
@@ -23,6 +23,8 @@ export interface OpenFileButtonProps {
|
||||
readonly onFile: (data: ArrayBuffer) => void;
|
||||
/** Callback that is called when a file has been rejected (e.g. bad file extension). */
|
||||
readonly onReject: (file: File) => void;
|
||||
/** If defined, will call custom function instead of opening file browser. */
|
||||
readonly onClick?: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +72,8 @@ class OpenFileButton extends React.Component<OpenFileButtonProps> {
|
||||
onDropRejected={this.onDropRejected}
|
||||
accept={this.props.fileExtension}
|
||||
multiple={false}
|
||||
noClick={this.props.onClick !== undefined}
|
||||
noKeyboard={this.props.onClick !== undefined}
|
||||
>
|
||||
{({ getRootProps, getInputProps }): JSX.Element => (
|
||||
<OverlayTrigger
|
||||
@@ -89,6 +93,12 @@ class OpenFileButton extends React.Component<OpenFileButtonProps> {
|
||||
? { pointerEvents: 'none' }
|
||||
: undefined
|
||||
}
|
||||
// onClick={this.props.onClick}
|
||||
// breaks Dropzone when this.props.onClick is undefined
|
||||
// so we have to do it the long way
|
||||
{...(this.props.onClick
|
||||
? { onClick: this.props.onClick }
|
||||
: {})}
|
||||
>
|
||||
<input {...getInputProps()} />
|
||||
<Image
|
||||
|
||||
Reference in New Issue
Block a user