Skip to content

Commit

Permalink
Reverted button to "Scan Once"
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Feb 21, 2024
1 parent 4788641 commit 0a71d52
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet, Modal, ScrollView, SafeAreaView, View } from 'react-native';
import gatherBluetoothData from './blueoothScanner';
Expand All @@ -23,28 +23,16 @@ const BluetoothScanPage = ({ ...props }: any) => {
// Function to run Bluetooth test and update logs
const runBluetoothTest = async () => {
try {
setIsScanning(true);
const newLogs = await gatherBluetoothData(t);
setLogs(newLogs);
} catch (error) {
logWarn(error);
// TODO: Handle error further
} finally {
setIsScanning(false);
}
};

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

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

const BluetoothCardList = ({ devices }) => (
<div>
{devices.map((device) => {
Expand Down Expand Up @@ -72,12 +60,7 @@ 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={handleToggle}
textColor={isScanning ? colors.onPrimary : colors.primary}
style={s.btn}
buttonColor={isScanning ? colors.primary : colors.onPrimary}>
<Button mode="elevated" onPress={runBluetoothTest} textColor={colors.primary} style={s.btn}>
{isScanning ? t('bluetooth.is-scanning') : t('bluetooth.scan-for-bluetooth')}
</Button>
</View>
Expand Down

0 comments on commit 0a71d52

Please sign in to comment.