Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp calculator #37

Merged
merged 3 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 34 additions & 15 deletions calculator/src/components/Ingredient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,45 @@ export default class Ingredient extends Component {
return (percent * 100).toFixed(2) + "%";
}

formatTotalOfIngredient(percent, totalFlour) {
return (totalFlour * percent).toFixed(2);
formatTotalOfIngredient(total) {
return (total).toFixed(2);
}

render() {
return (
<div className={this.props.single?'ingredient':'multi'}>
<div className="ingredient-element">{this.props.name}</div>
<div className="ingredient-element number">
{this.formatPercentage(this.props.percentage)}
<div className={'ingredient-wrapper ' + (this.props.intro ? 'ingredient-wrapper--intro' : '')}>
<div className='ingredient-base'>
<div className="ingredient-element">{this.props.name}</div>
<div className="ingredient-element number">
{this.props.percentage ? this.formatPercentage(this.props.percentage) : ''}
</div>
<div className="ingredient-element number">
<p className="ingredient-amount">
{this.formatTotalOfIngredient(this.props.absolute * this.props.count)}
</p>
<p>&nbsp;g</p>
</div>
</div>
<div className="ingredient-element number">
<p className="ingredient-amount">
{this.formatTotalOfIngredient(
this.props.percentage,
this.props.totalFlour
)
}
</p>
<p>&nbsp;g</p>
<div className='ingredient-explanation'>
{this.props.description}
</div>
<div className='ingredient-children'>
{this.props.breakdown.map((ing, i) => {
return (
<div key={i} className='ingredient-base ingredient-base--breakdown'>
<div className="ingredient-element">{ing.name}</div>
<div className="ingredient-element number">
{this.formatPercentage(ing.percentage)}
</div>
<div className="ingredient-element number">
<p className="ingredient-amount">
{this.formatTotalOfIngredient(ing.absolute * this.props.count)}
</p>
<p>&nbsp;g</p>
</div>
</div>
);
})}
</div>
</div>
);
Expand Down
40 changes: 40 additions & 0 deletions calculator/src/components/IngredientList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { Component } from "react";
import Close from "../components/Close";
import Ingredient from "../components/Ingredient";

export default class IngredientList extends Component {
render() {
return (
<div className="result">
<main className="main">
<div className="view-header">
<div className="result-header">
<h2>
Required ingredients for: {this.props.pizzaCount}{" "}
{this.props.pizzaCount > 1 ? "pizzas" : "pizza"}
</h2>
<h3>
Desired final weight per pizza: {this.props.pizzaWeight} g
</h3>
</div>
<Close color="white" />
</div>
{this.props.ingredients.map((ing, i) => {
return (
<Ingredient
name={ing.name}
percentage={ing.percentage}
absolute={ing.absolute}
breakdown={ing.breakdown ? ing.breakdown : []}
description={ing.description}
count={this.props.pizzaCount}
key={i}
intro={ing.intro}
/>
);
})}
</main>
</div>
);
}
}
12 changes: 0 additions & 12 deletions calculator/src/components/Or.js

This file was deleted.

63 changes: 51 additions & 12 deletions calculator/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ a {
}

.main {
max-width: 80vw;
max-width: 90vw;
display: flex;
justify-content: center;
align-items: center;
Expand All @@ -51,32 +51,43 @@ a {
}
}

.submit {
.calculate-buttons {
margin-top: 10px;
margin-bottom: 10px;
background: #ee5230;
display: flex;
}

.calculate-buttons > * {
box-sizing: border-box;
border: none;
border-radius: 6px;
text-align: center;
padding: 8px;
width: 100%;

cursor: pointer;

font-weight: medium;
line-height: normal;
font-size: 18px;
text-align: center;
}

.calculate-buttons span {
display: block;
width: 150px;
}

.calculate-buttons > a {
width: 100%;
background: #ee5230;
box-sizing: border-box;
cursor: pointer;
color: #ffffff;
border-radius: 5px;
}

.text-muted {
margin-top: 10px;
}

.link {
.more-info {
margin-top: 40px;
text-align: center;
}

Expand Down Expand Up @@ -177,11 +188,31 @@ a {

/*-------- Ingredient --------*/

.ingredient {
.ingredient-wrapper {
display: flex;
border-bottom: solid 3px #fff;
width: 100%;
padding: 20px;
padding: 20px 0px;
flex-wrap: wrap;
}

.ingredient-wrapper--intro {
border-bottom: dashed 6px #fff;
}

.ingredient-base {
display: flex;
width: 100%;
}

.ingredient-base--breakdown {
font-size: 14px;
padding-top: 10px;
}

.ingredient-explanation {
font-size: 14px;
padding-top: 10px;
}

.multi {
Expand All @@ -198,7 +229,7 @@ a {
font-style: italic;
}

.ingredient:last-of-type {
.ingredient-wrapper:last-of-type {
border-bottom: none;
}

Expand All @@ -207,6 +238,11 @@ a {
flex-grow: 1;
justify-content: flex-start;
width: 33.33%;
white-space: nowrap;
}

.ingredient-children {
width: 100%;
}

.number {
Expand All @@ -217,6 +253,9 @@ a {
.ingredient-element {
font-size: 1.5rem;
}
.ingredient-base--breakdown .ingredient-element {
font-size: 1.25rem;
}
}

.ingredient-element > p {
Expand Down
45 changes: 25 additions & 20 deletions calculator/src/pages/Calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import { Link } from "react-router-dom";
import logo from "../images/logo.svg";
import calculator from "../images/calculator.svg";
import Input from "../components/Input";
import { defaultOptions } from "../utils";

class Calculator extends React.Component {
constructor(props) {
super(props);
this.state = {
pizzaWeight: "",
pizzaCount: ""
};
this.state = defaultOptions();
}

handlePizzaWeightChange = e => {
this.setState({ pizzaWeight: e.target.value });
this.setState({ weight: e.target.value });
};

handlePizzaCountChange = e => {
this.setState({ pizzaCount: e.target.value });
this.setState({ count: e.target.value });
};

calculate = e => {
e.preventDefault();
this.props.history.push(
`/result?weight=${this.state.pizzaWeight}&count=${this.state.pizzaCount}`
);
};
buildParameters() {
const opts = {
...defaultOptions(),
weight: this.state.weight,
count: this.state.count,
};
return `weight=${opts.weight}&count=${opts.count}&water=${opts.water}&salt=${opts.salt}&sourdoughPercent=${opts.sourdoughPercent}&sourdoughHydration=${opts.sourdoughHydration}&dryYeastPercent=${opts.dryYeastPercent}`
}

render() {
return (
Expand All @@ -41,32 +41,37 @@ class Calculator extends React.Component {
</h2>
</header>
<main className="main">
<form onSubmit={this.calculate}>
<form>
<Input
id="count"
onChange={this.handlePizzaCountChange}
label="Number of pizzas"
value="2"
value={this.state.count}
step="1"
/>

<Input
id="weight"
onChange={this.handlePizzaWeightChange}
label="Weight per pizza (grams)"
value="200"
value={this.state.weight}
>
<small className="text-muted">
Typically between 200 and 250 grams. For a home oven 200 grams
is recommended.
is recommended. Choose between a yeast based dough and a sourdough
based dough.
</small>
</Input>

<button type="submit" className="submit">
Calculate
</button>
<div className="calculate-buttons">
<Link to={`result?yeast=true&${this.buildParameters()}`}>Yeast</Link>
<span>
- or -
</span>
<Link to={`result?sourdough=true&${this.buildParameters()}`}>Sourdough</Link>
</div>
</form>
<div className="link">
<div className="more-info">
<Link to="/info">
More info{" "}
<span role="img" aria-label="">
Expand Down