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

Commit

Permalink
❤️ changes 😍
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodinh committed Mar 17, 2020
1 parent c4c2ee8 commit 4cd81db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
18 changes: 3 additions & 15 deletions components/FindButton.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react'
import { useStoreState, useStoreActions } from 'easy-peasy'
import {
lastBatteryBuffer,
lastTemperatureBuffer,
celciusToFahrenheit
} from '../lib/'
import { lastBatteryBuffer, lastTemperatureBuffer } from '../lib/'

let device = null
let myCharacteristicNotify = null
Expand All @@ -26,9 +22,7 @@ const FindButton = () => {
const resetDevice = useStoreActions(actions => actions.device.reset)

// Temperature Model
const addTemperature = useStoreActions(
actions => actions.temperature.addValue
)
const { prepareValue } = useStoreActions(actions => actions.temperature)
const resetTemperature = useStoreActions(actions => actions.temperature.reset)
// Battery Model
const addBatteryValue = useStoreActions(actions => actions.battery.addValue)
Expand All @@ -54,13 +48,7 @@ const FindButton = () => {
const hex2dec = parseInt(a[2], 16)
const celcius = hex2dec / 10

console.log(unit)
console.log(celcius)
console.log(celciusToFahrenheit(celcius))

unit === 'C'
? addTemperature(celcius)
: addTemperature(celciusToFahrenheit(celcius))
prepareValue(celcius)
}

if (hexString.substr(0, 4) === 'aa8e') {
Expand Down
3 changes: 1 addition & 2 deletions components/LifeinaBoxStats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { useStoreState } from 'easy-peasy'
import { celciusToFahrenheit } from '../lib/'

const LifeinaBoxStats = () => {
const temperatureValue = useStoreState(state => state.temperature.value)
Expand All @@ -23,7 +22,7 @@ const LifeinaBoxStats = () => {
</span>
) : temperatureValue && unit === 'F' ? (
<span className='inline-block bg-gray-200 rounded-full px-3 py-1 text-lg font-semibold text-gray-700 mr-2'>
{`${celciusToFahrenheit(temperatureValue)} °F`}
{`${temperatureValue} °F`}
</span>
) : null}
{batteryValue ? (
Expand Down
8 changes: 7 additions & 1 deletion model/temperature-model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { action, computed } from 'easy-peasy'
import { action, computed, thunk } from 'easy-peasy'
import { nth } from 'lodash'
import { celciusToFahrenheit } from '../lib/'

const temperatureModel = {
values: [],
Expand All @@ -24,6 +25,11 @@ const temperatureModel = {
{ x: -9, y: nth(state.values, -10) || 0 },
{ x: -10, y: nth(state.values, -11) || 0 }
]
}),
prepareValue: thunk((actions, payload, { getState, getStoreState }) => {
const unit = getStoreState().settings.unit
const value = unit === 'C' ? payload : celciusToFahrenheit(payload)
actions.addValue(value)
})
}

Expand Down

0 comments on commit 4cd81db

Please sign in to comment.