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

Commit

Permalink
❤️ these confounded tests drive me nuts 😍
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodinh committed Mar 17, 2020
1 parent 5309b3c commit 5399ef1
Show file tree
Hide file tree
Showing 8 changed files with 948 additions and 744 deletions.
8 changes: 7 additions & 1 deletion components/LifeinaBoxStats.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import { useStoreState } from 'easy-peasy'
import { celciusToFahrenheit } from '../lib/'

const LifeinaBoxStats = () => {
const temperatureValue = useStoreState(state => state.temperature.value)
const batteryValue = useStoreState(state => state.battery.value)
const batteryStatus = useStoreState(state => state.battery.status)
const { unit } = useStoreState(state => state.settings)

return (
<div className='max-w-sm rounded overflow-hidden m-auto bg-orange-100'>
Expand All @@ -15,10 +17,14 @@ const LifeinaBoxStats = () => {
</div>
</div>
<div className='px-6 py-4 '>
{temperatureValue ? (
{temperatureValue && unit === 'C' ? (
<span className='inline-block bg-gray-200 rounded-full px-3 py-1 text-lg font-semibold text-gray-700 mr-2'>
{`${temperatureValue} °C`}
</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`}
</span>
) : null}
{batteryValue ? (
<span className='inline-block bg-gray-200 rounded-full px-3 py-1 text-lg font-semibold text-gray-700 mr-2'>
Expand Down
38 changes: 38 additions & 0 deletions components/SelectLanguage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { useStoreState, useStoreActions } from 'easy-peasy'

const SelectLanguage = () => {
const { languages } = useStoreState(state => state.settings)
const { updateLanguage } = useStoreActions(actions => actions.settings)

const handleChange = event => {
if (!languages.includes(event.target.value)) {
return 0
}

updateLanguage(event.target.value)
}

return (
<div className='inline-block relative w-64'>
<select
onChange={handleChange}
className='block appearance-none w-full bg-white border border-gray-400 hover:border-gray-500 px-4 py-2 pr-8 rounded shadow leading-tight focus:outline-none focus:shadow-outline'
>
<option value='en_GB'>English</option>
<option value='fr_FR'>Français</option>
</select>
<div className='pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700'>
<svg
className='fill-current h-4 w-4'
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 20 20'
>
<path d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z' />
</svg>
</div>
</div>
)
}

export { SelectLanguage }
38 changes: 38 additions & 0 deletions components/SelectUnit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { useStoreState, useStoreActions } from 'easy-peasy'

const SelectUnit = () => {
const { units } = useStoreState(state => state.settings)
const { updateUnit } = useStoreActions(actions => actions.settings)

const handleChange = event => {
if (!units.includes(event.target.value)) {
return 0
}

updateUnit(event.target.value)
}

return (
<div className='inline-block relative w-64'>
<select
onChange={handleChange}
className='block appearance-none w-full bg-white border border-gray-400 hover:border-gray-500 px-4 py-2 pr-8 rounded shadow leading-tight focus:outline-none focus:shadow-outline'
>
<option value='C'>Celsius °C</option>
<option value='F'>Fahrenheit °F</option>
</select>
<div className='pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700'>
<svg
className='fill-current h-4 w-4'
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 20 20'
>
<path d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z' />
</svg>
</div>
</div>
)
}

export { SelectUnit }
2 changes: 2 additions & 0 deletions components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './BatteryChart'
export * from './LifeinaBoxStats'
export * from './TemperatureChart'
export * from './Nav'
export * from './SelectUnit'
export * from './SelectLanguage'
12 changes: 10 additions & 2 deletions model/settings-model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { action } from 'easy-peasy'

const settingsModel = {
language: 'en_GB',
pollInterval: 1000, // ms
unit: 'C' // accepted values: 'C' or 'F'
language: 'en_GB',
languages: ['en_GB', 'fr_FR'],
updateLanguage: action((state, payload) => {
state.language = payload
}),
unit: 'C',
units: ['C', 'F'],
updateUnit: action((state, payload) => {
state.unit = payload
})
}

export default settingsModel
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"lodash": "^4.17.15",
"micro": "^9.3.5-canary.3",
"micro-cors": "^0.1.1",
"next": "latest",
"next": "^9.3.0",
"next-redux-wrapper": "^4.0.1",
"prop-types": "^15.7.2",
"react": "latest",
"react-dom": "latest",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"styled-components": "^5.0.1",
"victory": "^34.1.1",
"yup": "^0.28.1"
Expand Down
5 changes: 3 additions & 2 deletions pages/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import '../styles/index.css'
import { Nav } from '../components/'
import { Nav, SelectUnit, SelectLanguage } from '../components/'

export default () => (
<>
Expand All @@ -9,7 +9,8 @@ export default () => (
className='flex flex-wrap -mx-2 shadow rounded'
style={{ backgroundColor: '#fefaf0' }}
>
<div>This feature is scheduled to tomorow :-)</div>
<SelectUnit />
<SelectLanguage />
</div>
</>
)
Loading

0 comments on commit 5399ef1

Please sign in to comment.