Skip to content

Commit 0a10373

Browse files
committed
frontend: style bluetooth peripherals list
- disable all options when a device is either connected or connecting - show spinner indicator when connecting - show spinner at the bottom when the app is scanning for devices
1 parent d1aee18 commit 0a10373

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

frontends/web/src/components/bluetooth/bluetooth.tsx

+24-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616

1717
import { useTranslation } from 'react-i18next';
1818
import { useSync } from '@/hooks/api';
19-
import { connect, getState, syncState } from '@/api/bluetooth';
19+
import { connect, getState, syncState, TPeripheral } from '@/api/bluetooth';
2020
import { runningInIOS } from '@/utils/env';
2121
import { Status } from '@/components/status/status';
2222
import { ActionableItem } from '@/components/actionable-item/actionable-item';
2323
import { Badge } from '@/components/badge/badge';
24+
import { HorizontallyCenteredSpinner, SpinnerRingAnimated } from '@/components/spinner/SpinnerAnimation';
2425
import styles from './bluetooth.module.css';
2526

27+
const isConnectedOrConnecting = (peripheral: TPeripheral) => {
28+
return peripheral.connectionState === 'connecting' || peripheral.connectionState === 'connected';
29+
};
30+
2631
const _Bluetooth = () => {
2732
const { t } = useTranslation();
2833
const state = useSync(getState, syncState);
@@ -36,35 +41,46 @@ const _Bluetooth = () => {
3641
</Status>
3742
);
3843
}
44+
const hasConnection = state.peripherals.some(isConnectedOrConnecting);
3945
return (
4046
<>
4147
<div className={styles.label}>
4248
{t('bluetooth.select')}
4349
</div>
4450
<div className={styles.container}>
45-
{ state.scanning ? 'scanning' : null }
4651
{state.peripherals.map(peripheral => {
52+
const onClick = !hasConnection ? () => connect(peripheral.identifier) : undefined;
53+
const connectingIcon = peripheral.connectionState === 'connecting' ? (
54+
<SpinnerRingAnimated />
55+
) : undefined;
4756
return (
4857
<ActionableItem
4958
key={peripheral.identifier}
50-
onClick={() => connect(peripheral.identifier)}>
59+
icon={connectingIcon}
60+
onClick={onClick}>
5161
<span>
5262
{ peripheral.name !== '' ? peripheral.name : peripheral.identifier }
5363
{' '}
64+
{ peripheral.connectionState === 'connected' ? (
65+
<Badge type="success">
66+
{t('bluetooth.connected')}
67+
</Badge>
68+
) : null }
5469
{ peripheral.connectionState === 'error' ? (
5570
<Badge type="danger">
56-
{t('bluetooth.connectionFailed')}
71+
<span style={{ whiteSpace: 'wrap' }}>
72+
{peripheral.connectionError}
73+
</span>
5774
</Badge>
5875
) : null }
59-
{ peripheral.connectionState === 'error' ? (
60-
<p>{ peripheral.connectionError }</p>
61-
) : peripheral.connectionState }
6276
</span>
63-
6477
</ActionableItem>
6578
);
6679
})}
6780
</div>
81+
{state.scanning && (
82+
<HorizontallyCenteredSpinner />
83+
)}
6884
</>
6985
);
7086
};

frontends/web/src/locales/en/app.json

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
"button": "Blink"
368368
},
369369
"bluetooth": {
370+
"connected": "connected",
370371
"connectionFailed": "failed",
371372
"enable": "Please turn on Bluetooth",
372373
"select": "Select your BitBox"

0 commit comments

Comments
 (0)