Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the hub name as a default when installing/re-installing PyBricks Firmware #2297

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/ble/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2022 The Pybricks Authors
// Copyright (c) 2020-2024 The Pybricks Authors
//
// Manages state for the Bluetooth Low Energy connection.
// This assumes that there is only one global connection to a single device.
Expand Down Expand Up @@ -84,6 +84,14 @@ const deviceName: Reducer<string> = (state = '', action) => {
return state;
};

const deviceNameLastConnected: Reducer<string> = (state = '', action) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a state for this, just a hook that wraps useLocalStorage().

if (bleDidConnectPybricks.matches(action)) {
return action.name;
}

return state;
};

const deviceType: Reducer<string> = (state = '', action) => {
if (bleDidDisconnectPybricks.matches(action)) {
return '';
Expand Down Expand Up @@ -136,6 +144,7 @@ export default combineReducers({
connection,
deviceName,
deviceType,
deviceNameLastConnected,
deviceFirmwareVersion,
deviceLowBatteryWarning,
deviceBatteryCharging,
Expand Down
5 changes: 3 additions & 2 deletions src/firmware/installPybricksDialog/InstallPybricksDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2023 The Pybricks Authors
// Copyright (c) 2022-2024 The Pybricks Authors

import './installPybricksDialog.scss';
import {
Expand Down Expand Up @@ -450,6 +450,7 @@ const BootloaderModePanel: React.FunctionComponent<BootloaderModePanelProps> = (

export const InstallPybricksDialog: React.FunctionComponent = () => {
const { isOpen } = useSelector((s) => s.firmware.installPybricksDialog);
const deviceNameLastConnected = useSelector((s) => s.ble.deviceNameLastConnected);
const inProgress = useSelector(
(s) =>
s.firmware.isFirmwareFlashUsbDfuInProgress ||
Expand Down Expand Up @@ -527,7 +528,7 @@ export const InstallPybricksDialog: React.FunctionComponent = () => {
title={i18n.translate('optionsPanel.title')}
panel={
<ConfigureOptionsPanel
hubName={hubName}
hubName={hubName || deviceNameLastConnected}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it would work correctly. It would only display deviceNameLastConnected but not actually use this when flashing.

Instead, I would use deviceNameLastConnected as the placeholder and then modify the call to firmwareInstallPybricksDialogAccept() to add the appropriate logic.

metadata={
isCustomFirmwareRequested
? customFirmwareData?.metadata
Expand Down
Loading