Skip to content

Commit eb95127

Browse files
Merge pull request #51 from CivicTechAtlanta/steve-fixes-3
fixes 3
2 parents 63ecfcf + 3676c1f commit eb95127

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

src/app/calculator-flow/components/ChlorineWeightFlow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function ChlorineWeightFormula({ onCalculate, sharedState }: { on
3838
});
3939

4040
// Calculate with chlorine percentage given as a whole number (e.g., 70 => 0.70)
41-
const chlorinePct = (Number(formData.chlorinePercentage) || 0) / 100;
41+
const chlorinePct = (Number(formData.chlorinePercentage) || 0);
4242

4343
const chlorineWeight = ( Number(formData.waterIngress) * (Number(formData.rechargeTimeDays) * 86400) * Number(formData.desiredConcentration) ) / (10 * chlorinePct)
4444

src/app/calculator-flow/components/MotherSolutionConcentrationFlow.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import Form from "../../mother-solution-concentration/components/Form";
99
import "../../mother-solution-concentration/styles/Main.css";
1010

1111
import modalData from "../../modals/mother-solution-concentration-modal-data";
12-
import { formatSig2 } from "@/app/utils/format";
13-
1412

1513
import { CalculatorFlowSharedStateData } from "./Interfaces";
1614

15+
const formatTwoDecimalPlaces = (num: number): string => {
16+
return num.toFixed(2);
17+
};
18+
1719
export default function MotherSolutionConcentrationFormula({ onCalculate, sharedState }: { onCalculate: (data: number) => void, sharedState: CalculatorFlowSharedStateData }) {
1820

1921
const { t } = useTranslation();
@@ -41,7 +43,7 @@ export default function MotherSolutionConcentrationFormula({ onCalculate, shared
4143
<h2>{`${t('The concentration of the mother solution is')}:`}</h2>
4244

4345
<p className="answer">
44-
{`${formatSig2(concentratedMotherSolution)} ${t('milligrams')}/${t('liters')}`}
46+
{`${formatTwoDecimalPlaces(concentratedMotherSolution)} ${t('milligrams')}/${t('liters')}`}
4547
</p>
4648
</div>
4749
<Modal

src/app/chlorine-weight/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function ChlorineWeightFormula() {
2626
rechargeTimeDays: '',
2727
});
2828

29-
const chlorinePct = (Number(formData.chlorinePercentage) || 0) / 100;
29+
const chlorinePct = (Number(formData.chlorinePercentage) || 0);
3030
const chlorineWeight = ( Number(formData.waterIngress) * (Number(formData.rechargeTimeDays) * 86400) * Number(formData.desiredConcentration) ) / (10 * chlorinePct)
3131

3232
const handleClick = () => {

src/app/mother-solution-concentration/components/Form.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type FormProps = {
1212
msVolume?: number | null;
1313
chlorineWeight?: number | null;
1414
msConcentration?: number | null;
15-
desiredConcentration?: number | null;
15+
chlorinePercentage?: number | null;
1616
};
1717
};
1818

@@ -23,11 +23,11 @@ export default function Form({ onCalculate, sharedState }: FormProps) {
2323
const [formData, setFormData] = useState<{
2424
motherSolutionVolume: number;
2525
weightOfChlorine: number;
26-
desiredReservoirConcentration: number;
26+
chlorinePercentage: number;
2727
}>({
2828
motherSolutionVolume: sharedState.msVolume || 0,
2929
weightOfChlorine: sharedState.chlorineWeight || 0,
30-
desiredReservoirConcentration: sharedState.desiredConcentration || 0,
30+
chlorinePercentage: sharedState.chlorinePercentage || 0,
3131
});
3232

3333
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -43,7 +43,7 @@ export default function Form({ onCalculate, sharedState }: FormProps) {
4343
setFormData({
4444
motherSolutionVolume: 0,
4545
weightOfChlorine: 0,
46-
desiredReservoirConcentration: 0,
46+
chlorinePercentage: 0,
4747
});
4848
}
4949

@@ -52,24 +52,26 @@ export default function Form({ onCalculate, sharedState }: FormProps) {
5252
const {
5353
motherSolutionVolume,
5454
weightOfChlorine,
55-
desiredReservoirConcentration,
55+
chlorinePercentage,
5656
} = formData;
5757

5858
let newConcentratedMotherSolution;
5959
if (motherSolutionVolume != 0) {
6060
newConcentratedMotherSolution =
61-
(weightOfChlorine * 10 * desiredReservoirConcentration) /
61+
(weightOfChlorine * 1000 * (chlorinePercentage / 100)) /
6262
motherSolutionVolume;
6363
} else {
6464
newConcentratedMotherSolution = 0;
6565
}
6666

67+
console.log(newConcentratedMotherSolution)
68+
6769
onCalculate(newConcentratedMotherSolution);
6870
};
6971

7072
const motherSolutionVolumeLabel = `${t('Mother Solution Volume')} (${t('liters')})`;
7173
const weightOfChlorineLabel = `${t('Weight of Chlorine')} (${t('grams')})`;
72-
const desiredReservoirConcentrationLabel = `${t('Desired Reservoir Concentration')} (${t('milligrams')}/${t('liters')})`;
74+
const chlorinePercentageLabel = `${t('Chlorine Percentage')} (%)`;
7375

7476
return (
7577
<form className="form" onSubmit={handleSubmit}>
@@ -88,11 +90,11 @@ export default function Form({ onCalculate, sharedState }: FormProps) {
8890
defaultValue={formData.weightOfChlorine.toString()}
8991
/>
9092
<Input
91-
label={desiredReservoirConcentrationLabel}
92-
name="desiredReservoirConcentration"
93+
label={chlorinePercentageLabel}
94+
name="chlorinePercentage"
9395
min="0"
9496
handleChange={handleChange}
95-
defaultValue={formData.desiredReservoirConcentration.toString()}
97+
defaultValue={formData.chlorinePercentage.toString()}
9698
/>
9799
<button type="reset" className="button" onClick={clear}>
98100
{t('Clear')}

src/app/mother-solution-concentration/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import LanguageSelector from "../components/LanguageSelector/LanguageSelector";
1010
import Modal from '../components/Modal/Modal';
1111

1212
import modalData from '../modals/mother-solution-concentration-modal-data';
13-
import { formatSig2 } from "../utils/format";
14-
1513

1614
import "./styles/Main.css";
1715

16+
const formatTwoDecimalPlaces = (num: number): string => {
17+
return num.toFixed(2);
18+
};
19+
1820
export default function MotherSolutionConcentrationFormula() {
1921
const { t } = useTranslation();
2022

@@ -33,13 +35,13 @@ export default function MotherSolutionConcentrationFormula() {
3335
<h1 className="pageHeader">{t('Mother Solution Concentration Formula')}
3436
<svg onClick={() => setShowModal('info')} fill="#288DCE" viewBox="0 0 50 50"><path d="M 25 2 C 12.309295 2 2 12.309295 2 25 C 2 37.690705 12.309295 48 25 48 C 37.690705 48 48 37.690705 48 25 C 48 12.309295 37.690705 2 25 2 z M 25 4 C 36.609824 4 46 13.390176 46 25 C 46 36.609824 36.609824 46 25 46 C 13.390176 46 4 36.609824 4 25 C 4 13.390176 13.390176 4 25 4 z M 25 11 A 3 3 0 0 0 22 14 A 3 3 0 0 0 25 17 A 3 3 0 0 0 28 14 A 3 3 0 0 0 25 11 z M 21 21 L 21 23 L 22 23 L 23 23 L 23 36 L 22 36 L 21 36 L 21 38 L 22 38 L 23 38 L 27 38 L 28 38 L 29 38 L 29 36 L 28 36 L 27 36 L 27 21 L 26 21 L 22 21 L 21 21 z" /></svg>
3537
</h1>
36-
<Form onCalculate={handleCalculate} sharedState={{}}></Form>
38+
<Form onCalculate={handleCalculate} sharedState={{}}/>
3739

3840
<div className="result-wrapper">
3941
<h2>{`${t('The concentration of the mother solution is')}:`}</h2>
4042

4143
<p className="answer">
42-
{`${formatSig2(concentratedMotherSolution)} ${t('mg')}/${t('L')}`}
44+
{`${formatTwoDecimalPlaces(concentratedMotherSolution)} ${t('mg')}/${t('L')}`}
4345
</p>
4446
</div>
4547

0 commit comments

Comments
 (0)