Skip to content

Commit

Permalink
Finish reusable bad
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmcdermott committed Mar 2, 2017
1 parent 150830a commit af3b1f8
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
src/1-readable/bad/*.js
110 changes: 107 additions & 3 deletions src/2-reusable/bad/index.js
@@ -1,13 +1,117 @@
import React, { Component } from 'react';

class ReusableBad extends Component {
class Inventory extends Component {
constructor() {
super();
this.state = {
localCurrency: 'usd',
inventory: [
{
product: 'Flashlight',
img: '/flashlight.jpg',
desc: 'A really great flashlight',
price: 100,
currency: 'usd',
},
{
product: 'Tin can',
img: '/tin_can.jpg',
desc: 'Pretty much what you would expect from a tin can',
price: 32,
currency: 'usd',
},
{
product: 'Cardboard Box',
img: '/cardboard_box.png',
desc: 'It holds things',
price: 5,
currency: 'usd',
},
],
};
}

convertCurrency(amount, fromCurrency, toCurrency) {
let currencyConversions = {
usd: {
rupee: 66.78,
yuan: 6.87,
usd: 1,
},
};

let currencySymbols = {
usd: '$',
rupee: '₹',
yuan: '元',
};

return currencySymbols[toCurrency] + amount * currencyConversions[fromCurrency][toCurrency];
}

onSelectCurrency(e) {
this.setState({
localCurrency: e.target.value,
});
}

render() {
return (
<div>
Reusable Bad
<label htmlFor="currencySelector">Currency:</label>
<select
className="u-full-width"
id="currencySelector"
onChange={this.onSelectCurrency.bind(this)}
value={this.state.localCurrency}
>
<option value="usd">USD</option>
<option value="rupee">Rupee</option>
<option value="yuan">Yuan</option>
</select>
<table style={{ width: '100%' }}>
<tbody>
<tr>
<th>
Product
</th>

<th>
Image
</th>

<th>
Description
</th>

<th>
Price
</th>
</tr>
{this.state.inventory.map((item, idx) => (
<tr key={idx}>
<td>
{item.product}
</td>

<td>
<img src={item.img} alt="" />
</td>

<td>
{item.desc}
</td>

<td>
{this.convertCurrency(item.price, item.currency, this.state.localCurrency)}
</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
}

export default ReusableBad;
export default Inventory;
2 changes: 1 addition & 1 deletion src/App.js
Expand Up @@ -34,7 +34,7 @@ class App extends Component {
constructor() {
super();
this.state = {
section: 'readable',
section: 'reusable',
quality: 'bad',
};
}
Expand Down

0 comments on commit af3b1f8

Please sign in to comment.