diff --git a/app/public/index.html b/app/public/index.html index c985a9e..3ec9cb9 100644 --- a/app/public/index.html +++ b/app/public/index.html @@ -14,7 +14,7 @@ You need to enable JavaScript to run this app.

MyHours

-

Fill in your working hours:

+

When and where did you work?

diff --git a/app/src/App.js b/app/src/App.js index b200056..dfdb2f2 100644 --- a/app/src/App.js +++ b/app/src/App.js @@ -1,9 +1,19 @@ import React, { Component } from "react"; +import PropTypes from "prop-types"; import "./App.css"; import HourObject from "./HourObject"; import TotalHours from "./TotalHours"; import Input from "./Input"; +const calculateTotal = (start, end) => { + return end - start; +}; + +calculateTotal.propTypes = { + start: PropTypes.number.isRequired, + end: PropTypes.number.isRequired +}; + class App extends Component { constructor(props) { super(props); @@ -12,7 +22,7 @@ class App extends Component { this.state = { name: "Café Devine", location: "Budafabriek", - start: "7", + start: "9", end: "19" }; } @@ -21,29 +31,39 @@ class App extends Component { this.setState({ [name]: value }); }; - calculateTotal = (start, end) => { - return start + end; - } - render() { const { name, location, start, end } = this.state; - const total = this.calculateTotal(start, end); + const total = calculateTotal(parseFloat(start), parseFloat(end)); return (
this.handleInputChange("name", e)} /> this.handleInputChange("location", e)} /> + this.handleInputChange("start", e)} + /> + this.handleInputChange("end", e)} + />
- +
diff --git a/app/src/HourObject.jsx b/app/src/HourObject.jsx index 4190dfd..bac8c91 100644 --- a/app/src/HourObject.jsx +++ b/app/src/HourObject.jsx @@ -9,8 +9,8 @@ const HourObject = ({ name, location, date, startHour, endHour, total }) => { Name Location Date - Start - End + Start hour + End hour Total diff --git a/app/src/Input.jsx b/app/src/Input.jsx index c2c3b0a..dad5adf 100644 --- a/app/src/Input.jsx +++ b/app/src/Input.jsx @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' -const Input = ({ value, name, onChange }) => { +const Input = ({ value, name, type, onChange }) => { const changeInput = e => { const { value } = e.currentTarget; @@ -10,14 +10,14 @@ const Input = ({ value, name, onChange }) => { return ( ) } Input.propTypes = { - value: PropTypes.number.isRequired, + value: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired }