Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
❤️ bug fix 😍
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodinh committed Mar 5, 2020
1 parent 8183f0f commit 5309b3c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions components/FindButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { useStoreState, useStoreActions } from 'easy-peasy'
import { lastBatteryBuffer, lastTemperatureBuffer } from '../lib/'

let device = null
let myCharacteristicNotify = null
let interval = null

Expand Down Expand Up @@ -86,7 +87,7 @@ const FindButton = () => {
e.preventDefault()

try {
const device = await navigator.bluetooth.requestDevice({
device = await navigator.bluetooth.requestDevice({
filters: [{ name: lifeinaboxName }],
optionalServices: [lifeinaboxService]
})
Expand Down Expand Up @@ -118,11 +119,9 @@ const FindButton = () => {
}
}

const onClickDisconnectButton = e => {
e.preventDefault()

const onClickDisconnectButton = () => {
// remove listeners
if (myCharacteristicNotify && interval) {
if (myCharacteristicNotify && interval && device) {
myCharacteristicNotify.removeEventListener(
'characteristicvaluechanged',
handleNotifications,
Expand All @@ -134,14 +133,15 @@ const FindButton = () => {
myCharacteristicNotify = null
interval = null

// and reset redux
try {
resetDevice()
resetBattery()
resetTemperature()
} catch (error) {
console.log(error)
// disconnecting from Bluetooth Device
if (device.gatt.connected) {
device.gatt.disconnect()
}

// and reset redux
resetDevice()
resetBattery()
resetTemperature()
}
}

Expand Down

1 comment on commit 5309b3c

@vercel
Copy link

@vercel vercel bot commented on 5309b3c Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.