diff --git a/unit-conversion/public/index.html b/unit-conversion/public/index.html index a48795dddd09fee33fe8c06844a73eb22e9a1473..ac0ad19103d5fc4bc168585bb2714675ed5e0bf1 100644 --- a/unit-conversion/public/index.html +++ b/unit-conversion/public/index.html @@ -9,8 +9,8 @@ content="An app that takes units and converts them to other units" /> <meta name="theme-color" content="rgba(208 0 0 / 100%)" /> - <link rel="icon" href="%PUBLIC_URL%/logo.svg" /> - <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo.svg" /> + <link rel="icon" href="u.svg" /> + <link rel="apple-touch-icon" href="u.svg" /> <title>Unit Conversion</title> </head> <body> diff --git a/unit-conversion/public/logo.svg b/unit-conversion/public/logo.svg deleted file mode 100644 index 9118454587f555b17c42f441444c53fa943495aa..0000000000000000000000000000000000000000 --- a/unit-conversion/public/logo.svg +++ /dev/null @@ -1,5 +0,0 @@ -<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 152 152"> - <rect x="0" y="0" width="152" height="152" fill="rgba(0 0 0 / 100%)" /> - <path d="M147,1H90V42h10V75.673L53.532,2.393,52.648,1H2V42H12v66H2v41H62V108H52V74.336l46.467,73.271L99.351,149H150V108H140V42h10V1Z" stroke-width="3" stroke="rgba(255 255 255 / 100%)" fill="rgba(208 0 0 / 100%)"> - </path> -</svg> diff --git a/unit-conversion/public/manifest.json b/unit-conversion/public/manifest.json index aaece82c09c55550ec22723d9b1bad018bcd3f67..14082a3e8822e2615ac275f680eb7b1b83f118b3 100644 --- a/unit-conversion/public/manifest.json +++ b/unit-conversion/public/manifest.json @@ -4,7 +4,7 @@ "description": "An app that takes units and converts them to other units", "icons": [ { - "src": "logo.svg", + "src": "u.svg", "type": "image/svg+xml", "sizes": "192x192 512x512", "purpose": "any maskable" diff --git a/unit-conversion/public/u.svg b/unit-conversion/public/u.svg new file mode 100644 index 0000000000000000000000000000000000000000..deefd6479bf9d0e35e5a3413db8cc3617c3db811 --- /dev/null +++ b/unit-conversion/public/u.svg @@ -0,0 +1 @@ +<svg id="Capa_1" enable-background="new 0 0 512 512" height="512" viewBox="0 0 512 512" width="512" xmlns="http://www.w3.org/2000/svg"><g id="U"><path d="m337.255 281.038c.015 67.588-1.025 87.876-24.229 105.894-22.163 17.227-82.017 19.79-110.537-1.201-27.246-20.039-28.315-48.384-27.847-96.782l.103-288.949h-128.745v268.557c0 93.472 0 181.758 103.638 226.406 47.595 20.546 154.453 24.243 211.816 1.465 104.546-41.528 104.546-129.477 104.546-231.738v-264.69h-128.745z"/></g></svg> \ No newline at end of file diff --git a/unit-conversion/src/features/card/card.css b/unit-conversion/src/features/card/card.css index 27a238a8038454ad4b52f75566ab963058ce2214..84648ea218b718b1ce592f7d3f57b1566d0abcc7 100644 --- a/unit-conversion/src/features/card/card.css +++ b/unit-conversion/src/features/card/card.css @@ -13,6 +13,7 @@ 0 22.3px 17.9px rgba(0 0 0 / 7.2%), 0 41.8px 33.4px rgba(0 0 0 / 8.6%), 0 100px 80px rgba(0 0 0 / 12%); + padding-left: 40px; } .inputField { diff --git a/unit-conversion/src/features/card/card.js b/unit-conversion/src/features/card/card.js index 5368f55bb8e726a43883cf9566fc1bd01012535d..7c7e973a2f319b7ee6135bd8aa84652517d6e644 100644 --- a/unit-conversion/src/features/card/card.js +++ b/unit-conversion/src/features/card/card.js @@ -1,17 +1,17 @@ -import PropTypes from 'prop-types'; -import './card.css'; - -export function Card(props) { - Card.propTypes = { - title: PropTypes.string.isRequired, - }; - - return ( - <div className="card"> - <h1>{props.title}</h1> - <div> - {props.children} - </div> - </div> - ); -} +import PropTypes from 'prop-types'; +import './card.css'; + +export function Card(props) { + Card.propTypes = { + title: PropTypes.string.isRequired, + }; + + return ( + <div className="card"> + <h1>{props.title}</h1> + <div> + {props.children} + </div> + </div> + ); +} diff --git a/unit-conversion/src/features/ending-number-output/endingNumberOutput.js b/unit-conversion/src/features/ending-number-output/endingNumberOutput.js index 3d3af89eee4f1220d871213d1e9b1f206fb1c797..ad1038b26a49fe08c7ede60fcaf49201fd274fee 100644 --- a/unit-conversion/src/features/ending-number-output/endingNumberOutput.js +++ b/unit-conversion/src/features/ending-number-output/endingNumberOutput.js @@ -1,43 +1,43 @@ -/* eslint-disable no-magic-numbers */ -import { useSelector } from 'react-redux'; -import { selectCurrentOutputUnit, selectCurrentInputUnit} from '../unit-selector/unitSelectorSlice'; -import { selectNumberOfUnits } from '../number-input-field/numberInputFieldSlice'; - -export function EndingNumberOutput() { - const conversionTable = { - // To use these conversion multiply your specified unit with - // its number to get meters. - unitsToMeters: { - km: 1000, - m: 1.0, - cm: 1 / 100, - ft: 1 / 3.281, - in: 1 / 39.3701, - }, - // Multiply a number of meters by one of these conversions to - // get that number of units. - metersToUnits: { - km: 1 / 1000, - m: 1.0, - cm: 100, - ft: 3.281, - in: 39.3701, - }, - }; - - const currentInputUnit = useSelector(selectCurrentInputUnit); - const currentOutputUnit = useSelector(selectCurrentOutputUnit); - const numberOfUnits = parseFloat(useSelector(selectNumberOfUnits)); - const numberOfMeters = numberOfUnits * conversionTable.unitsToMeters[currentInputUnit]; - let convertedNumber = numberOfMeters * conversionTable.metersToUnits[currentOutputUnit]; - - if (isNaN(convertedNumber)) { - convertedNumber = 'Please enter number to convert to '; - } - - return ( - <div> - <h1>{convertedNumber} {currentOutputUnit}</h1> - </div> - ); -} +/* eslint-disable no-magic-numbers */ +import { useSelector } from 'react-redux'; +import { selectCurrentOutputUnit, selectCurrentInputUnit } from '../unit-selector/unitSelectorSlice'; +import { selectNumberOfUnits } from '../number-input-field/numberInputFieldSlice'; + +export function EndingNumberOutput() { + const conversionTable = { + // To use these conversion multiply your specified unit with + // its number to get meters. + unitsToMeters: { + km: 1000, + m: 1.0, + cm: 1 / 100, + ft: 1 / 3.281, + in: 1 / 39.3701, + }, + // Multiply a number of meters by one of these conversions to + // get that number of units. + metersToUnits: { + km: 1 / 1000, + m: 1.0, + cm: 100, + ft: 3.281, + in: 39.3701, + }, + }; + + const currentInputUnit = useSelector(selectCurrentInputUnit); + const currentOutputUnit = useSelector(selectCurrentOutputUnit); + const numberOfUnits = parseFloat(useSelector(selectNumberOfUnits)); + const numberOfMeters = numberOfUnits * conversionTable.unitsToMeters[currentInputUnit]; + let convertedNumber = numberOfMeters * conversionTable.metersToUnits[currentOutputUnit]; + + if (isNaN(convertedNumber)) { + convertedNumber = 'Please enter number to convert to '; + } + + return ( + <div> + <h1>{convertedNumber} {currentOutputUnit}</h1> + </div> + ); +} diff --git a/unit-conversion/src/features/number-input-field/numberInputField.js b/unit-conversion/src/features/number-input-field/numberInputField.js index 65c50c8b82675ccc41f0c2cf90c16c8cc7da96be..e6a5925c98ee0643f62a1146ea2fdaa21899bce9 100644 --- a/unit-conversion/src/features/number-input-field/numberInputField.js +++ b/unit-conversion/src/features/number-input-field/numberInputField.js @@ -1,20 +1,20 @@ -import { useSelector, useDispatch } from 'react-redux'; -import { selectCurrentInputUnit } from '../unit-selector/unitSelectorSlice'; -import { setNumberOfUnits } from './numberInputFieldSlice'; - -export function NumberInputField() { - const currentInputUnit = useSelector(selectCurrentInputUnit); - const placeHolderString = `Enter # of "${currentInputUnit}"`; - const dispatch = useDispatch(); - - function handleChange(e) { - const currentNumber = e.target.value; - dispatch(setNumberOfUnits(currentNumber)); - } - - return ( - <div> - <input className="inputField" type="text" placeholder={ placeHolderString } onChange={handleChange}/> - </div> - ); -} +import { useSelector, useDispatch } from 'react-redux'; +import { selectCurrentInputUnit } from '../unit-selector/unitSelectorSlice'; +import { setNumberOfUnits } from './numberInputFieldSlice'; + +export function NumberInputField() { + const currentInputUnit = useSelector(selectCurrentInputUnit); + const placeHolderString = `Enter # of "${currentInputUnit}"`; + const dispatch = useDispatch(); + + function handleChange(e) { + const currentNumber = e.target.value; + dispatch(setNumberOfUnits(currentNumber)); + } + + return ( + <div> + <input className="inputField" type="text" placeholder={ placeHolderString } onChange={handleChange}/> + </div> + ); +} diff --git a/unit-conversion/src/features/number-input-field/numberInputFieldSlice.js b/unit-conversion/src/features/number-input-field/numberInputFieldSlice.js index 2d301f620f302debb52d4cad03e92cf0dbae3936..a38790224e5a22c7c3591dabc694a8489946fe65 100644 --- a/unit-conversion/src/features/number-input-field/numberInputFieldSlice.js +++ b/unit-conversion/src/features/number-input-field/numberInputFieldSlice.js @@ -1,26 +1,26 @@ -import { createSlice } from '@reduxjs/toolkit'; - -const numberInputFieldSlice = createSlice({ - name: 'numberInputField', - initialState: { - numberToConvert: 0, - }, - reducers: { - setNumberOfUnits: (state, action) => { - const numToConvert = action.payload; - return { - ...state, - numberToConvert: numToConvert, - }; - }, - }, -}); -export default numberInputFieldSlice; - -export const { - setNumberOfUnits, -} = numberInputFieldSlice.actions; - -export function selectNumberOfUnits(state) { - return state.numberInputField.numberToConvert; -} +import { createSlice } from '@reduxjs/toolkit'; + +const numberInputFieldSlice = createSlice({ + name: 'numberInputField', + initialState: { + numberToConvert: 0, + }, + reducers: { + setNumberOfUnits: (state, action) => { + const numToConvert = action.payload; + return { + ...state, + numberToConvert: numToConvert, + }; + }, + }, +}); +export default numberInputFieldSlice; + +export const { + setNumberOfUnits, +} = numberInputFieldSlice.actions; + +export function selectNumberOfUnits(state) { + return state.numberInputField.numberToConvert; +} diff --git a/unit-conversion/src/features/unit-selector/unitSelector.js b/unit-conversion/src/features/unit-selector/unitSelector.js index 5cf9a67bcbde4cb4eb98c90868b145d11712ff64..7dbb9ed9926e68c5bf2e560e47bdbb7d9c7981b1 100644 --- a/unit-conversion/src/features/unit-selector/unitSelector.js +++ b/unit-conversion/src/features/unit-selector/unitSelector.js @@ -1,71 +1,71 @@ -import { store } from '../../app/store'; -import { useDispatch } from 'react-redux'; -import { - setCurrentInputUnit, - setCurrentOutputUnit, -} from './unitSelectorSlice'; -import PropTypes from 'prop-types'; - -export function UnitSelector(props) { - // type will either be 'Input' or 'Output' - UnitSelector.propTypes = { - type: PropTypes.string.isRequired, - }; - - const unitSelectorOptions = [ - { - label: 'Km', - value: 'km', - }, - { - label: 'M', - value: 'm', - }, - { - label: 'Cm', - value: 'cm', - }, - { - label: 'Ft', - value: 'ft', - }, - { - label: 'In', - value: 'in', - }, - ]; - - const disbatch = useDispatch(); - function handleChange(e) { - const unsubscribe = store.subscribe(() => - console.log('State after dispatch: ', store.getState()), - ); - const currentUnit = e.target.value; - console.log(currentUnit); - - if (props.type === 'Input'){ - disbatch(setCurrentInputUnit(currentUnit)); - } - if (props.type === 'Output'){ - disbatch(setCurrentOutputUnit(currentUnit)); - } - unsubscribe(); - } - - function handleSubmit(e) { - e.preventDefault(); - } - - return ( - <div> - <form onSubmit={handleSubmit}> - <div className="select-container"> - <select name="units" onChange={handleChange}> - {unitSelectorOptions.map((option) => - <option value={option.value}>{option.label}</option>)} - </select> - </div> - </form> - </div> - ); -} +import { store } from '../../app/store'; +import { useDispatch } from 'react-redux'; +import { + setCurrentInputUnit, + setCurrentOutputUnit, +} from './unitSelectorSlice'; +import PropTypes from 'prop-types'; + +export function UnitSelector(props) { + // type will either be 'Input' or 'Output' + UnitSelector.propTypes = { + type: PropTypes.string.isRequired, + }; + + const unitSelectorOptions = [ + { + label: 'Km', + value: 'km', + }, + { + label: 'M', + value: 'm', + }, + { + label: 'Cm', + value: 'cm', + }, + { + label: 'Ft', + value: 'ft', + }, + { + label: 'In', + value: 'in', + }, + ]; + + const disbatch = useDispatch(); + function handleChange(e) { + const unsubscribe = store.subscribe(() => + console.log('State after dispatch: ', store.getState()), + ); + const currentUnit = e.target.value; + console.log(currentUnit); + + if (props.type === 'Input'){ + disbatch(setCurrentInputUnit(currentUnit)); + } + if (props.type === 'Output'){ + disbatch(setCurrentOutputUnit(currentUnit)); + } + unsubscribe(); + } + + function handleSubmit(e) { + e.preventDefault(); + } + + return ( + <div> + <form onSubmit={handleSubmit}> + <div className="select-container"> + <select name="units" onChange={handleChange}> + {unitSelectorOptions.map((option) => + <option value={option.value}>{option.label}</option>)} + </select> + </div> + </form> + </div> + ); +} diff --git a/unit-conversion/src/features/unit-selector/unitSelectorSlice.js b/unit-conversion/src/features/unit-selector/unitSelectorSlice.js index 288651358d799ddaf8831ebbad1302320c73d885..f8e6d30dedf3eacac9c9707f7370b5ec137e2cd4 100644 --- a/unit-conversion/src/features/unit-selector/unitSelectorSlice.js +++ b/unit-conversion/src/features/unit-selector/unitSelectorSlice.js @@ -1,40 +1,40 @@ -import { createSlice } from '@reduxjs/toolkit'; - -const unitSelectorSlice = createSlice({ - name: 'unitSelector', - initialState: { - currentInputUnit: 'km', - currentOutputUnit: 'km', - }, - reducers: { - // The action payload should have the unit to switch to with the in or out - setCurrentInputUnit: (state, action) => { - const newUnit = action.payload; - return { - ...state, - currentInputUnit: newUnit, - }; - }, - setCurrentOutputUnit: (state, action) => { - const newUnit = action.payload; - return { - ...state, - currentOutputUnit: newUnit, - }; - }, - }, -}); -export default unitSelectorSlice; - -export const { - setCurrentInputUnit, - setCurrentOutputUnit, -} = unitSelectorSlice.actions; - -export function selectCurrentInputUnit(state) { - return state.unitSelector.currentInputUnit; -} - -export function selectCurrentOutputUnit(state) { - return state.unitSelector.currentOutputUnit; -} +import { createSlice } from '@reduxjs/toolkit'; + +const unitSelectorSlice = createSlice({ + name: 'unitSelector', + initialState: { + currentInputUnit: 'km', + currentOutputUnit: 'km', + }, + reducers: { + // The action payload should have the unit to switch to with the in or out + setCurrentInputUnit: (state, action) => { + const newUnit = action.payload; + return { + ...state, + currentInputUnit: newUnit, + }; + }, + setCurrentOutputUnit: (state, action) => { + const newUnit = action.payload; + return { + ...state, + currentOutputUnit: newUnit, + }; + }, + }, +}); +export default unitSelectorSlice; + +export const { + setCurrentInputUnit, + setCurrentOutputUnit, +} = unitSelectorSlice.actions; + +export function selectCurrentInputUnit(state) { + return state.unitSelector.currentInputUnit; +} + +export function selectCurrentOutputUnit(state) { + return state.unitSelector.currentOutputUnit; +}