Skip to content

Commit

Permalink
Fixed scan button, ran prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Feb 14, 2024
1 parent 9215f69 commit b4cafd4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"bluetooth": {
"scan-debug-title": "Bluetooth Scanner",
"scan-for-bluetooth": "Scan for Devices",
"is-scanning": "Scanning...",
"device-info": {
"id": "ID",
"name": "Name"
Expand Down
26 changes: 23 additions & 3 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet, Modal, ScrollView, SafeAreaView, View } from 'react-native';
import gatherBluetoothData from './blueoothScanner';
Expand All @@ -16,6 +16,7 @@ import { Appbar, useTheme, Button } from 'react-native-paper';
const BluetoothScanPage = ({ ...props }: any) => {
const { t } = useTranslation();
const [logs, setLogs] = useState<string[]>([]);
const [isScanning, setIsScanning] = useState(false);
const { colors } = useTheme();

// Function to run Bluetooth test and update logs
Expand All @@ -29,6 +30,20 @@ const BluetoothScanPage = ({ ...props }: any) => {
}
};

useEffect(() => {
let intervalId;
if (isScanning) {
intervalId = setInterval(runBluetoothTest, 5000);
} else {
clearInterval(intervalId);
}
return () => clearInterval(intervalId);
}, [isScanning]);

const handleToggle = () => {
setIsScanning(!isScanning);
};

const BlueScanContent = (
<div style={{ height: '100%' }}>
<Appbar.Header
Expand All @@ -43,8 +58,13 @@ const BluetoothScanPage = ({ ...props }: any) => {
<Appbar.Content title={t('bluetooth.scan-debug-title')} titleStyle={{ fontSize: 17 }} />
</Appbar.Header>
<View style={s.btnContainer}>
<Button mode="elevated" onPress={runBluetoothTest} textColor={colors.primary} style={s.btn}>
{t('bluetooth.scan-for-bluetooth')}
<Button
mode="elevated"
onPress={handleToggle}
textColor={isScanning ? colors.onPrimary : colors.primary}
style={s.btn}
buttonColor={isScanning ? colors.primary : colors.onPrimary}>
{isScanning ? t('bluetooth.is-scanning') : t('bluetooth.scan-for-bluetooth')}
</Button>
</View>

Expand Down
4 changes: 2 additions & 2 deletions www/js/control/BluetoothScanSettingRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const BluetoothScanSettingRow = ({}) => {
// Check and prompt for bluetooth scan permission
try {
let response = await window['cordova'].plugins.BEMDataCollection.bluetoothScanPermissions();
if (response == "OK") setBluePageVisible(true)
if (response == 'OK') setBluePageVisible(true);
} catch (e) {
displayError(e, "Insufficient Permissions");
displayError(e, 'Insufficient Permissions');
}
}

Expand Down

0 comments on commit b4cafd4

Please sign in to comment.