mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
ble/alerts: move bluetooth not available from notifications
This commit is contained in:
@@ -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'),
|
||||
};
|
||||
};
|
||||
@@ -13,4 +13,6 @@ export enum I18nId {
|
||||
NoWebBluetoothMessage = 'noWebBluetooth.message',
|
||||
NoWebBluetoothSuggestion = 'noWebBluetooth.suggestion',
|
||||
NoWebBluetoothLinux = 'noWebBluetooth.linux',
|
||||
BluetoothNotAvailableMessage = 'bluetoothNotAvailable.message',
|
||||
BluetoothNotAvailableSuggestion = 'bluetoothNotAvailable.suggestion',
|
||||
}
|
||||
|
||||
@@ -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,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."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user