ble/alerts: move bluetooth not available from notifications

This commit is contained in:
David Lechner
2022-07-15 13:19:31 -05:00
parent f86a9ad051
commit ef0cd6507d
11 changed files with 43 additions and 13 deletions
+26
View File
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
import { Intent } from '@blueprintjs/core';
import React from 'react';
import { CreateToast } from '../../i18nToaster';
import { I18nId, useI18n } from './i18n';
const BluetoothNotAvailable: React.VoidFunctionComponent = () => {
const i18n = useI18n();
return (
<>
<p>{i18n.translate(I18nId.BluetoothNotAvailableMessage)}</p>
<p>{i18n.translate(I18nId.BluetoothNotAvailableSuggestion)}</p>
</>
);
};
export const bluetoothNotAvailable: CreateToast = (onAction) => {
return {
message: <BluetoothNotAvailable />,
icon: 'error',
intent: Intent.DANGER,
onDismiss: () => onAction('dismiss'),
};
};
+2
View File
@@ -13,4 +13,6 @@ export enum I18nId {
NoWebBluetoothMessage = 'noWebBluetooth.message',
NoWebBluetoothSuggestion = 'noWebBluetooth.suggestion',
NoWebBluetoothLinux = 'noWebBluetooth.linux',
BluetoothNotAvailableMessage = 'bluetoothNotAvailable.message',
BluetoothNotAvailableSuggestion = 'bluetoothNotAvailable.suggestion',
}
+2 -1
View File
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
import { bluetoothNotAvailable } from './BluetoothNotAvailable';
import { noWebBluetooth } from './NoWebBluetooth';
// gathers all of the alert creation functions for passing up to the top level
export default { noWebBluetooth };
export default { bluetoothNotAvailable, noWebBluetooth };
+4
View File
@@ -4,5 +4,9 @@
"suggestion": "Use a supported browser such as Google Chrome or Microsoft Edge.",
"linux": "Web Bluetooth is experimental on Linux and must be manually enabled. Copy the link below and paste it in the address bar.",
"action": "More Info"
},
"bluetoothNotAvailable": {
"message": "No Bluetooth adapter could be found.",
"suggestion": "Please connect or enable a Bluetooth Low Energy adapter and restart the browser."
}
}
+3
View File
@@ -264,6 +264,9 @@ describe('connect action is dispatched', () => {
await runConnectUntil(saga, ConnectRunPoint.Connect);
await expect(saga.take()).resolves.toEqual(
alertsShowAlert('ble', 'bluetoothNotAvailable'),
);
await expect(saga.take()).resolves.toEqual(
bleDidFailToConnectPybricks({
reason: BleDeviceFailToConnectReasonType.NoBluetooth,
+1
View File
@@ -109,6 +109,7 @@ function* handleBleConnectPybricks(): Generator {
const available = yield* call(() => navigator.bluetooth.getAvailability());
if (!available) {
yield* put(alertsShowAlert('ble', 'bluetoothNotAvailable'));
yield* put(bleDidFailToConnectPybricks({ reason: Reason.NoBluetooth }));
return;
}