From 689c1b4cdf0dd7cbaf8216a88ecc68f0a5df6c42 Mon Sep 17 00:00:00 2001 From: Nicholas Warzin Date: Wed, 25 Nov 2020 09:10:22 -0500 Subject: [PATCH] Allow simple calculations of skein/cost. Style. --- package.json | 5 ++++- src/App.css | 38 +++++++--------------------------- src/App.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 63 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index b624a35..55a1c91 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "name": "yarn", + "homepage": "/yarn", "version": "0.1.0", "private": true, "dependencies": { - "@material-ui/core": "^4.11.0", + "@material-ui/core": "^4.11.1", + "@material-ui/icons": "^4.9.1", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", @@ -15,6 +17,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", + "deploy": "npm run build && scp -rp build/* nicholas@warzin.com:/var/www/random/yarn", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/src/App.css b/src/App.css index 74b5e05..9f74164 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,14 @@ .App { text-align: center; + max-width: 400px; + margin: 12px auto; + padding: 0 20px; } -.App-logo { - height: 40vmin; - pointer-events: none; +h1 { + font-size: 64px !important; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +h6 { + margin-bottom: 20px !important; } diff --git a/src/App.js b/src/App.js index c7cc176..c112ed1 100644 --- a/src/App.js +++ b/src/App.js @@ -2,46 +2,64 @@ import { useState, useEffect } from "react"; import logo from './logo.svg'; import './App.css'; -import {Typography, TextField, InputAdornment, Grid} from "@material-ui/core"; +import {Typography, TextField, InputAdornment, Grid, } from "@material-ui/core"; +import FavoriteIcon from "@material-ui/icons/Favorite"; const App = (props) => { const [values, setValues] = useState({ - total: 1914, + total: "", skeinLength: "", skeinPrice: "", + skeinCount: "", }); + // const [skeinCount, setSkeinCount] = useState(""); const [totalPrice, setTotalPrice] = useState(); + const [skeinsRequiredDisabled, setSkeinsRequiredDisabled] = useState(false); const _handleChange = (event) => { const { id, value } = event.target; - console.log("changing", id, value); + // console.log("changing", id, value); setValues({ ...values, - [id]: Number(value), + [id]: parseFloat(value || 0), }); - console.log(values); }; useEffect(() => { - const newTotal = Math.ceil((Number(values.total) / Number(values.skeinLength || 0))) - * Number(values.skeinPrice); + const newSkeinCount = Math.ceil((Number(values.total) / Number(values.skeinLength || 0)) || 0); + const newTotal = Number(newSkeinCount * Number(values.skeinPrice) || 0).toFixed(2); - setTotalPrice(newTotal); + // console.log(newSkeinCount, newTotal); - console.log("change"); + if (!values.total && !values.skeinLength) { + // console.log("setting a basic total"); + setSkeinsRequiredDisabled(false); + // setValues({ ...values, skeinCount: newSkeinCount }); + setTotalPrice((Number(values.skeinCount) || 0) * (Number(values.skeinPrice) || 0)); + } else { + // console.log("setting a complicated total"); + if (newSkeinCount !== values.skeinCount) setValues({ + ...values, + skeinCount: newSkeinCount, + }); + + setSkeinsRequiredDisabled(true); + setTotalPrice(newTotal); + } + + // console.log("change", values); }, [values]); - return ( -
+
- hey, we love yarn! + yarn calc Project details { value={values.total} onChange={_handleChange} type="number" + variant="outlined" + InputProps={{ + endAdornment: yards, + }} fullWidth /> @@ -60,6 +82,10 @@ const App = (props) => { value={values.skeinLength} onChange={_handleChange} type="number" + variant="outlined" + InputProps={{ + endAdornment: yards, + }} fullWidth /> @@ -70,6 +96,7 @@ const App = (props) => { value={values.skeinPrice} onChange={_handleChange} type="number" + variant="outlined" fullWidth InputProps={{ startAdornment: $, @@ -77,15 +104,26 @@ const App = (props) => { /> + + + Total project cost $, + style: { fontSize: "36px" }, }} />