This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from exanup/dev
Dev
- Loading branch information
Showing
15 changed files
with
374 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": ["standard", "plugin:react/recommended"], | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"react/prop-types": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, { Component } from 'react' | ||
import Calculator from './Calculator' | ||
|
||
export default class App extends Component { | ||
render () { | ||
return <Calculator /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React, { Component } from 'react' | ||
|
||
export default class BoilingVerdict extends Component { | ||
render () { | ||
const temperature = this.props.temperature | ||
const verdict = temperature >= 100 ? `boil` : `not boil` | ||
const msg = `The water would ${verdict}.` | ||
|
||
return <div>{msg}</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { Component, Fragment } from 'react' | ||
import BoilingVerdict from './BoilingVerdict' | ||
import TemperatureUnit from './TemperatureUnit' | ||
|
||
import { convertUnit, toCelsius, toFahrenheit } from '../utils/unitConversion' | ||
|
||
const scales = { CELSIUS: 0, FAHRENHEIT: 1 } | ||
|
||
export default class Calculator extends Component { | ||
constructor () { | ||
super() | ||
this.state = { temperature: '', scale: scales.CELSIUS } | ||
|
||
this.handleTemperatureUpdate = this.handleTemperatureUpdate.bind(this) | ||
} | ||
|
||
handleTemperatureUpdate (temperature, scale) { | ||
this.setState({ temperature, scale }) | ||
} | ||
|
||
render () { | ||
const temperature = this.state.temperature | ||
const scale = this.state.scale | ||
|
||
const celsius = | ||
scale === scales.CELSIUS | ||
? temperature | ||
: convertUnit(temperature, toCelsius) | ||
|
||
const fahrenheit = | ||
scale === scales.FAHRENHEIT | ||
? temperature | ||
: convertUnit(temperature, toFahrenheit) | ||
|
||
return ( | ||
<Fragment> | ||
<TemperatureUnit | ||
temperature={celsius} | ||
scale={scales.CELSIUS} | ||
onUpdateTemperature={this.handleTemperatureUpdate} | ||
/> | ||
<TemperatureUnit | ||
temperature={fahrenheit} | ||
scale={scales.FAHRENHEIT} | ||
onUpdateTemperature={this.handleTemperatureUpdate} | ||
/> | ||
<BoilingVerdict temperature={temperature} /> | ||
</Fragment> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { Component } from 'react' | ||
|
||
export default class TemperatureUnit extends Component { | ||
constructor (props) { | ||
super(props) | ||
this.handleChange = this.handleChange.bind(this) | ||
} | ||
handleChange (e) { | ||
const temperature = isNaN(parseFloat(e.target.value)) | ||
? 0 | ||
: parseFloat(e.target.value) | ||
|
||
const scale = this.props.scale | ||
this.props.onUpdateTemperature(temperature, scale) | ||
} | ||
|
||
render () { | ||
const temperature = this.props.temperature | ||
return ( | ||
<input type="text" value={temperature} onChange={this.handleChange} /> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import App from './App'; | ||
import registerServiceWorker from './registerServiceWorker'; | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import './index.css' | ||
import App from './components/App' | ||
import registerServiceWorker from './registerServiceWorker' | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
registerServiceWorker(); | ||
ReactDOM.render(<App />, document.getElementById('root')) | ||
registerServiceWorker() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export let convertUnit = (value, callback) => callback(value) | ||
export let toCelsius = (f) => (f - 32) / 1.8 | ||
export let toFahrenheit = (c) => c * 1.8 + 32 |
Oops, something went wrong.