@@ -37,21 +37,13 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
3737 const connectionError = useBluetoothAudioStore ( ( s ) => s . connectionError ) ;
3838 const [ hasScanned , setHasScanned ] = useState ( false ) ;
3939 const [ connectingDeviceId , setConnectingDeviceId ] = useState < string | null > ( null ) ;
40-
41- // Start scanning when sheet opens
42- useEffect ( ( ) => {
43- if ( isOpen && ! hasScanned ) {
44- startScan ( ) ;
45- }
46- // eslint-disable-next-line react-hooks/exhaustive-deps
47- } , [ isOpen , hasScanned ] ) ;
40+ const preferredDeviceDisplayName = preferredDevice ?. id === 'system-audio' ? t ( 'bluetooth.system_audio' ) : preferredDevice ?. name || t ( 'bluetooth.unknown_device' ) ;
4841
4942 const startScan = React . useCallback ( async ( ) => {
5043 try {
5144 setHasScanned ( true ) ;
5245 await bluetoothAudioService . startScanning ( 10000 ) ; // 10 second scan
5346 } catch ( error ) {
54- setHasScanned ( false ) ; // Reset scan state on error
5547 logger . error ( {
5648 message : 'Failed to start Bluetooth scan' ,
5749 context : { error } ,
@@ -61,6 +53,13 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
6153 }
6254 } , [ t ] ) ;
6355
56+ // Start scanning when sheet opens
57+ useEffect ( ( ) => {
58+ if ( isOpen && ! hasScanned ) {
59+ startScan ( ) ;
60+ }
61+ } , [ isOpen , hasScanned , startScan ] ) ;
62+
6463 const handleDeviceSelect = React . useCallback (
6564 async ( device : BluetoothAudioDevice ) => {
6665 try {
@@ -222,7 +221,7 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
222221 } , [ isScanning , hasScanned , startScan , t ] ) ;
223222
224223 return (
225- < CustomBottomSheet isOpen = { isOpen } onClose = { onClose } >
224+ < CustomBottomSheet isOpen = { isOpen } onClose = { onClose } snapPoints = { [ 85 ] } minHeight = "min-h-0" >
226225 < VStack className = "flex-1 p-4" >
227226 < Heading className = "mb-4 text-lg" > { t ( 'bluetooth.select_device' ) } </ Heading >
228227
@@ -232,7 +231,7 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
232231 < HStack className = "items-center justify-between" >
233232 < VStack >
234233 < Text className = "text-sm font-medium text-neutral-900 dark:text-neutral-100" > { t ( 'bluetooth.current_selection' ) } </ Text >
235- < Text className = "text-sm text-neutral-600 dark:text-neutral-400" > { preferredDevice . name } </ Text >
234+ < Text className = "text-sm text-neutral-600 dark:text-neutral-400" > { preferredDeviceDisplayName } </ Text >
236235 </ VStack >
237236 < Button onPress = { handleClearSelection } size = { isLandscape ? 'sm' : 'xs' } variant = "outline" >
238237 < ButtonText className = { isLandscape ? '' : 'text-2xs' } > { t ( 'bluetooth.clear' ) } </ ButtonText >
@@ -255,7 +254,7 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
255254
256255 // Update preferred device manually here to ensure UI reflects it immediately
257256 // preventing race conditions with store updates
258- await setPreferredDevice ( { id : 'system-audio' , name : 'System Audio' } ) ;
257+ await setPreferredDevice ( { id : 'system-audio' , name : t ( 'bluetooth.system_audio' ) } ) ;
259258
260259 onClose ( ) ;
261260 } catch ( error ) {
@@ -277,8 +276,8 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
277276 < HStack className = "items-center" >
278277 < BluetoothIcon size = { 16 } className = "mr-2 text-primary-600" />
279278 < VStack >
280- < Text className = { `font-medium ${ preferredDevice ?. id === 'system-audio' ? 'text-primary-700 dark:text-primary-300' : 'text-neutral-900 dark:text-neutral-100' } ` } > { t ( 'bluetooth.systemAudio ' ) } </ Text >
281- < Text className = "text-xs text-neutral-500" > { t ( 'bluetooth.systemAudioDescription ' ) } </ Text >
279+ < Text className = { `font-medium ${ preferredDevice ?. id === 'system-audio' ? 'text-primary-700 dark:text-primary-300' : 'text-neutral-900 dark:text-neutral-100' } ` } > { t ( 'bluetooth.system_audio ' ) } </ Text >
280+ < Text className = "text-xs text-neutral-500" > { t ( 'bluetooth.system_audio_description ' ) } </ Text >
282281 </ VStack >
283282 </ HStack >
284283 { preferredDevice ?. id === 'system-audio' && (
@@ -316,11 +315,7 @@ export function BluetoothDeviceSelectionBottomSheet({ isOpen, onClose }: Bluetoo
316315 { bluetoothState !== State . PoweredOn && (
317316 < Box className = "mt-4 rounded-lg border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-700 dark:bg-yellow-900" >
318317 < Text className = "text-sm text-yellow-800 dark:text-yellow-200" >
319- { bluetoothState === State . PoweredOff
320- ? t ( 'bluetooth.bluetooth_disabled' )
321- : bluetoothState === State . Unauthorized
322- ? t ( 'bluetooth.bluetooth_unauthorized' )
323- : t ( 'bluetooth.bluetooth_not_ready' , { state : bluetoothState } ) }
318+ { bluetoothState === State . PoweredOff ? t ( 'bluetooth.poweredOff' ) : bluetoothState === State . Unauthorized ? t ( 'bluetooth.unauthorized' ) : t ( 'bluetooth.bluetooth_not_ready' , { state : bluetoothState } ) }
324319 </ Text >
325320 </ Box >
326321 ) }
0 commit comments