Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/src/config.js
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# assignment_exchange_rates
How much does a Big Mac cost in Italy?

Alex Thomas
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "assignment_exchange_rates",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.0.0-alpha.6",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-scripts": "1.0.14"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Currency Converter</title>
</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
15 changes: 15 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
8 changes: 8 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
85 changes: 85 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { Component } from "react";
import CurrencyConverterContainer from "./CurrencyConverterContainer";
import CurrencyRatesTableContainer from "./CurrencyRatesTableContainer";
import JumbotronFluid from "./elements/JumbotronFluid";
import config from '../config'
class App extends Component {
constructor() {
super(),
(this.state = {
isFetching: false,
baseCurrency: "USD",
rates: [],
date: new Date().toISOString().slice(0, 10)
});
}


getRates = () => {
fetch(
`http://api.fixer.io/${this.state.date}?base=${this.state.baseCurrency}?{config.key}`
)
.then(response => response.json())
.then(json => {
this.setState({
rates: json.rates,
isFetching: false
});
});
};
componentDidMount() {
// Before performing the fetch, set isFetching to true
this.setState({ isFetching: true }, this.getRates());
}
shouldComponentUpdate() {
return this.state.isFetching !== false;
}

switch_currency = e => {
e.preventDefault();
//console.log("select-target", e.target);
//console.log("select-target.value", e.target.value);
this.setState(
{
baseCurrency: e.target.value
},
this.setState({ isFetching: true }, this.getRates())
);
};

setDate = e => {
//console.log("date-target", e.target);
//console.log("date-target.value", e.target.value);
this.setState(
{
date: e.target.value,
isFetching: true
},
this.getRates()
);
};
render() {
const { baseCurrency, rates, date } = this.state;
const currenciesArray = Object.keys(rates);
//console.log("RATES Passed", rates);
console.log("RATES Passed", config.key);
return (
<div className="wrapper">
<JumbotronFluid heading="Currency Converter" />
<CurrencyRatesTableContainer
baseCurrency={baseCurrency}
onSubmit={this.populateCurrencyTable}
switch_currency={this.switch_currency}
setDate={this.setDate}
date={date}
rates={rates}
currenciesArray={currenciesArray}
/>
<hr />
<CurrencyConverterContainer />
</div>
);
}
}

export default App;
42 changes: 42 additions & 0 deletions src/components/BaseCurrencyForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import Select from "./elements/Select";
import Button from "./elements/Button";

const BaseCurrencyForm = props => {
const {
rates,
baseCurrency,
switch_currency,
setDate,
date,
currenciesArray
} = props;
return (
<form className="container" id="ChooseBaseCurrency">
<Select
className="form-control"
name="baseCurrency"
form="ChooseBaseCurrency"
handleSwitch={switch_currency}
data={currenciesArray}
baseValue={baseCurrency}
/>
<input
className="form-control"
type="date"
name="rateDate"
value={date}
onChange={setDate}
/>
<br />
</form>
);
};

BaseCurrencyForm.defaultProps = {
type: "button",
color: "default",
children: "Submit"
};

export default BaseCurrencyForm;
28 changes: 28 additions & 0 deletions src/components/ConverterBaseCurrencySelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";
import Select from "./elements/Select";
import PropTypes from "prop-types";

const ConverterBaseCurrencySelector = ({
selectCurrency,
converterBaseCurrency,
currenciesArray
}) => {
//currenciesArray.unshift(converterBaseCurrency);
return (
<Select
name="baseCurrency"
form="CurrencyConverterForm"
handleSwitch={selectCurrency}
baseValue={converterBaseCurrency}
data={currenciesArray}
/>
);
};

ConverterBaseCurrencySelector.propTypes = {
convertedCurrency: PropTypes.string.isRequired,
selectCurrency: PropTypes.func.isRequired,
currenciesArray: PropTypes.array.isRequired
};
export default ConverterBaseCurrencySelector;

28 changes: 28 additions & 0 deletions src/components/ConverterConvertedCurrencySelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";
import Select from "./elements/Select";
import PropTypes from "prop-types";

const ConverterConvertedCurrencySelector = ({
selectCurrency,
convertedCurrency,
currenciesArray
}) => {
//currenciesArray.unshift(convertedCurrency);
return (
<Select
name="baseCurrency"
form="CurrencyConverterForm"
handleSwitch={selectCurrency}
baseValue={convertedCurrency}
data={currenciesArray}
/>
);
};

ConverterConvertedCurrencySelector.propTypes = {
convertedCurrency: PropTypes.string.isRequired,
selectCurrency: PropTypes.func.isRequired,
currenciesArray: PropTypes.array.isRequired
};

export default ConverterConvertedCurrencySelector;
8 changes: 8 additions & 0 deletions src/components/CurrencyConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";
import Converter from "./elements/Converter";

const CurrencyConverter = () => {
return <div />;
};

export default CurrencyConverter;
Loading