diff --git a/app/src/App.css b/app/src/App.css
index 3d6ee109..00b4b5ae 100644
--- a/app/src/App.css
+++ b/app/src/App.css
@@ -237,3 +237,11 @@ textarea.otp {
.search-clear {
margin: 10px;
}
+
+.icon.divider {
+ color: rgb(0, 0, 0, 0.4) !important;
+}
+
+.divider.inverted {
+ color: rgb(255, 255, 255, 0.6) !important;
+}
diff --git a/app/src/components/Calculators.js b/app/src/components/Calculators.js
index 47c1b11f..a506c48d 100644
--- a/app/src/components/Calculators.js
+++ b/app/src/components/Calculators.js
@@ -1,18 +1,19 @@
import React from "react";
-import {BackButton, useTitle} from "./Common";
-import {Button, Header, Icon} from "./Theme";
+import {Breadcrumbs, useTitle} from "./Common";
+import {Button, Icon, Segment} from "./Theme";
import {useCalcQuery} from "../hooks/customHooks";
import {TemperatureCalculator} from "./calculators/TemperatureCalculator";
-import {ElectricalCalculator} from "./calculators/ElectricalCalculators";
+import {ElectricalCalculators} from "./calculators/ElectricalCalculators";
import {DipoleAntennaCalculator} from "./calculators/HamCalculators";
+import {Link} from "react-router-dom";
export function CalculatorsPage() {
const {calc, setCalc} = useCalcQuery();
const calculators = [
- {key: 'temperature', icon: 'thermometer', button: 'Temperature', contents: },
- {key: 'electrical', icon: 'lightning', button: 'Electrical', contents: },
+ {key: 'electrical', icon: 'lightning', button: 'Electrical', contents: },
{key: 'antenna', icon: 'signal', button: 'Antenna', contents: },
+ {key: 'temperature', icon: 'thermometer', button: 'Temperature', contents: },
];
const activeCalculator = calc ?
@@ -21,26 +22,30 @@ export function CalculatorsPage() {
const {icon, button, title, contents} = activeCalculator || {};
const name = activeCalculator ? title || button + ' Calculator' : 'Calculators';
- const header = activeCalculator ? : ;
useTitle(name);
const calculatorButtons = calculators.map(i => {
const {button, icon, key} = i;
- return
+ return
+
+
});
- const body = activeCalculator ? <>
-
- {contents}
- >
- : calculatorButtons;
+ const body = activeCalculator ? {contents} : calculatorButtons;
+
+ // Make first breadcrumb a link back to Calculators only when a calculator is active.
+ const crumbs = activeCalculator
+ ? [{text: 'Calculators', link: '/more/calculators'}, {text: name, icon: icon}]
+ : [{text: 'Calculators'}];
- // TODO add Breadcrumb here.
return <>
- {header}
- {body}
+
+
+
+ {body}
+
>
}
diff --git a/app/src/components/Common.js b/app/src/components/Common.js
index 5b566849..fda3753b 100644
--- a/app/src/components/Common.js
+++ b/app/src/components/Common.js
@@ -1,5 +1,6 @@
import React, {useContext, useEffect, useState} from "react";
import {
+ BreadcrumbSection,
Button as SButton,
ButtonGroup,
Card,
@@ -29,6 +30,8 @@ import {
} from "../hooks/customHooks";
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
import {
+ Breadcrumb,
+ BreadcrumbDivider,
Button,
CardIcon,
darkTheme,
@@ -1601,8 +1604,9 @@ export function HandPointMessage({children, size = null}) {
}
export function WarningMessage({children, size = null}) {
- return
-
+ // Use color='yellow' because "warning" does not work.
+ return
+
{children}
@@ -1760,3 +1764,27 @@ export function IframeViewer({title, src, fallback, style, timeout = 5000}) {
export function roundDigits(value, decimals = 2) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
+
+
+export function Breadcrumbs({crumbs, size = undefined}) {
+ function getSection(crumb) {
+ const {text, link, icon} = crumb;
+ let contents = text;
+ if (link) {
+ contents =
+ {icon && }
+ {text}
+ ;
+ }
+ return {contents}
+ }
+
+ return
+ {crumbs.map((crumb, index) => (
+
+ {getSection(crumb)}
+ {index < crumbs.length - 1 && }
+
+ ))}
+
+}
diff --git a/app/src/components/Search.js b/app/src/components/Search.js
index 03fee1d6..b0e0dd35 100644
--- a/app/src/components/Search.js
+++ b/app/src/components/Search.js
@@ -41,7 +41,7 @@ const SUGGESTED_APPS = [
{
location: '/more/calculators?calc=electrical',
title: 'Electrical Calculator',
- description: 'Convert Volts, Ohms, Amps, Watts'
+ description: 'Convert Volts, Ohms, Amps, Watts, Power Loss.'
},
{
location: '/more/calculators?calc=antenna',
diff --git a/app/src/components/Theme.js b/app/src/components/Theme.js
index 0a9a345b..93784a38 100644
--- a/app/src/components/Theme.js
+++ b/app/src/components/Theme.js
@@ -2,6 +2,7 @@ import React, {useContext, useEffect, useState} from 'react';
import {ThemeContext} from "../contexts/contexts";
import {
Accordion as SAccordion,
+ Breadcrumb as SBreadcrumb,
Button as SButton,
Card as SCard,
Divider as SDivider,
@@ -345,3 +346,16 @@ export function Card({color, ...props}) {
}
return
}
+
+export function Breadcrumb({...props}) {
+ const {t} = useContext(ThemeContext);
+ return
+}
+
+export function BreadcrumbDivider({...props}) {
+ const {inverted} = useContext(ThemeContext);
+
+ // TODO this only handles icons for now.
+ let className = `divider icon ${inverted} ${props.icon || ''}`;
+ return
+}
diff --git a/app/src/components/calculators/ElectricalCalculators.js b/app/src/components/calculators/ElectricalCalculators.js
index 414b8963..c09cc3be 100644
--- a/app/src/components/calculators/ElectricalCalculators.js
+++ b/app/src/components/calculators/ElectricalCalculators.js
@@ -1,9 +1,23 @@
-import {roundDigits} from "../Common";
-import React from "react";
-import {Header} from "../Theme";
+import {HelpPopup, roundDigits, Toggle} from "../Common";
+import React, {useState} from "react";
+import {Form, Header, Segment, Table} from "../Theme";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
-import {GridColumn, GridRow} from "semantic-ui-react";
+import {
+ Container,
+ Dropdown,
+ GridColumn,
+ GridRow,
+ Icon,
+ Input,
+ TableBody,
+ TableCell,
+ TableHeader,
+ TableHeaderCell,
+ TableRow,
+} from "semantic-ui-react";
import {ColoredInput} from "../Apps";
+import Message from "semantic-ui-react/dist/commonjs/collections/Message";
+import {Media, ThemeContext} from "../../contexts/contexts";
const initialState = {
volts: '',
@@ -96,7 +110,7 @@ function ohmsLawReducer(state, action) {
return {volts, amps, ohms, watts, lastUpdated: newLastUpdated};
}
-export function ElectricalCalculator() {
+export function OhmsLawCalculator({setVolts}) {
// Provides a form which provides 4 inputs (volts, amps, ohms, watts), and calculates the missing values.
const [state, dispatch] = React.useReducer(ohmsLawReducer, initialState);
@@ -113,8 +127,15 @@ export function ElectricalCalculator() {
onSelect: e => e.target.select(), // Select the contents of the Input when a user selects it.
};
+ React.useEffect(() => {
+ console.log(state);
+ if (state.volts > 0) {
+ setVolts(state.volts);
+ }
+ }, [state]);
+
return
-
+
@@ -155,3 +176,218 @@ export function ElectricalCalculator() {
}
+
+// Dropdown options for wire types
+const resistancesPerKFeet = {
+ solid: {
+ '0000 AWG': 0.049,
+ '00 AWG': 0.0779,
+ '0 AWG': 0.0982,
+ '2 AWG': 0.1563,
+ '4 AWG': 0.2485,
+ '6 AWG': 0.3134,
+ '8 AWG': 0.628,
+ '10 AWG': 0.9987,
+ '12 AWG': 1.588,
+ '14 AWG': 2.525,
+ '16 AWG': 4.015,
+ '20 AWG': 10.15,
+ '24 AWG': 25.67,
+ },
+ stranded: {
+ '0000 AWG': 0.0608,
+ '00 AWG': 0.0967,
+ '0 AWG': 0.022,
+ '2 AWG': 0.019,
+ '4 AWG': 0.038,
+ '6 AWG': 0.491,
+ '8 AWG': 0.778,
+ '10 AWG': 1.24,
+ '12 AWG': 1.98,
+ '14 AWG': 3.14,
+ '16 AWG': 4.99,
+ '18 AWG': 7.95,
+ },
+};
+const resistancesPerKm = {
+ solid: {
+ ['120 mm²']: 0.153,
+ ['70 mm²']: 0.272,
+ ['50 mm²']: 0.391,
+ ['25 mm²']: 0.734,
+ ['16 mm²']: 1.16,
+ ['10 mm²']: 1.84,
+ ['6 mm²']: 3.11,
+ ['4 mm²']: 4.70,
+ ['2.5 mm²']: 7.56,
+ ['1.5 mm²']: 12.3,
+ ['1 mm²']: 18.5,
+ ['0.75 mm²']: 25.0,
+ ['0.5 mm²']: 37.0
+ },
+ stranded: {
+ ['120 mm²']: 0.150,
+ ['70 mm²']: 0.268,
+ ['50 mm²']: 0.387,
+ ['25 mm²']: 0.727,
+ ['16 mm²']: 1.15,
+ ['10 mm²']: 1.83,
+ ['6 mm²']: 3.08,
+ ['4 mm²']: 4.61,
+ ['2.5 mm²']: 7.41,
+ ['1.5 mm²']: 12.1,
+ ['1 mm²']: 18.1,
+ ['0.75 mm²']: 24.5,
+ ['0.5 mm²']: 36.0
+ }
+};
+
+
+// Dropdown options for wire types
+const wireTypeOptions = [
+ {key: 'solid', text: 'Solid Copper', value: 'solid'},
+ {key: 'stranded', text: 'Stranded Copper', value: 'stranded'},
+];
+
+// Helper function to calculate power loss
+export const calcPowerLossPercent = (isSAE, volts, amps, resistancePerKiloLength, length) => {
+ if (volts <= 0) {
+ return 0; // Avoid division by zero and meaningless calculations when there's no voltage.
+ }
+
+ const resistancePerLength = resistancePerKiloLength / 1000;
+ // Double the length for return trip.
+ const resistance = 2 * length * resistancePerLength;
+ // console.log(`resistancePerFoot=${resistancePerFoot} resistance=${resistance}`)
+ const voltageDrop = amps * resistance;
+
+ return (voltageDrop / volts) * 100; // Return as a percentage
+};
+
+const PowerLossCalculator = ({defaultVolts = 120}) => {
+ const [volts, setVolts] = useState(defaultVolts);
+ const [wireType, setWireType] = useState('solid');
+ const [isSAE, setIsSAE] = useState(true);
+ const [length, setLength] = useState(100);
+ const [ampsRange] = useState([1, 5, 10, 20, 40, 100]);
+
+ const {inverted} = React.useContext(ThemeContext);
+ const warningBackgroundColor = inverted === 'inverted' ? '#332020' : '#ffbebe';
+
+ React.useEffect(() => {
+ // Copy voltage from Ohm's Law calculator.
+ if (defaultVolts > 0) {
+ setVolts(defaultVolts);
+ }
+ }, [defaultVolts]);
+
+ const resistances = isSAE ? resistancesPerKFeet[wireType]
+ : resistancesPerKm[wireType];
+
+ const voltsInput = setVolts(parseInt(value))}
+ />;
+
+ const saeToggle = setIsSAE(!isSAE)}
+ />;
+
+ const lengthInput =
+
+
+ setLength(parseInt(value))}
+ />
+
+
+
+
+
+ ;
+
+ const wireTypeDropdown = setWireType(value)}
+ />;
+ return
+};
+
+export const ElectricalCalculators = () => {
+ const [volts, setVolts] = React.useState();
+ return
+
+
+
+}
diff --git a/app/src/components/calculators/ElectricalCalculators.test.js b/app/src/components/calculators/ElectricalCalculators.test.js
new file mode 100644
index 00000000..c76865a2
--- /dev/null
+++ b/app/src/components/calculators/ElectricalCalculators.test.js
@@ -0,0 +1,9 @@
+import {calcPowerLossPercent} from "./ElectricalCalculators";
+
+describe('calcPowerLossPercent Function Tests', () => {
+ test('should correctly calculate power loss percentage', () => {
+ // Parameters: isSAE, volts, amps, resistancePerKm, length
+ const percent = calcPowerLossPercent(true, 120, 8.33, 2.58, 200);
+ expect(percent).toBeCloseTo(7.16, 2); // Use expected correct value and precision
+ });
+});