2024-05-31 23:53:30 -06:00
|
|
|
import React from "react";
|
2024-06-25 17:05:41 -06:00
|
|
|
import {Breadcrumbs, useTitle} from "./Common";
|
2024-11-02 15:14:02 -06:00
|
|
|
import {Button, Icon} from "./Theme";
|
2024-05-31 23:53:30 -06:00
|
|
|
import {useCalcQuery} from "../hooks/customHooks";
|
2024-06-20 09:51:29 -06:00
|
|
|
import {TemperatureCalculator} from "./calculators/TemperatureCalculator";
|
2024-06-25 17:05:41 -06:00
|
|
|
import {ElectricalCalculators} from "./calculators/ElectricalCalculators";
|
2024-06-20 09:51:29 -06:00
|
|
|
import {DipoleAntennaCalculator} from "./calculators/HamCalculators";
|
2025-12-07 11:54:20 -07:00
|
|
|
import {Link} from "react-router";
|
2025-01-18 10:08:11 -07:00
|
|
|
import {RatioCalculators} from "./calculators/RatioCalculator";
|
2025-02-07 11:44:17 -07:00
|
|
|
import {QRCodeCalculator} from "./calculators/QRCodeCalculator";
|
Add Drive Ratio calculator (pulleys, gears, sprockets)
A new "Drive Ratio" calculator under /more/calculators for belt, gear, and
chain-sprocket drives, supporting a compound train of 2–6 wheels on a single
shared belt/chain (constant size·rpm across the train).
- Pure, unit-tested math: size·rpm solver, ratio, torque, surface/belt speed,
belt length, sprocket pitch diameter, chain length, gear pitch diameter.
- Mode toggle (Pulley/Gear/Sprocket) with imperial/metric units; torque in
lb·ft or N·m.
- Add/remove wheels (2–6), each with a colorblind-friendly color shared between
its inputs and the schematic SVG diagram (Paul Tol bright palette).
- Dependency-free inline-SVG diagram: colored wheels threaded by one belt/chain,
or meshing gear teeth; auto-fitting viewBox.
- Per-mode details: belt/chain length and center distance (2-wheel only, with an
info popup), per-wheel pitch diameters, and constant train speed.
- Guards against impossible geometry (wheels overlapping) and ideal-torque note.
- Integer teeth enforced in gear/sprocket modes; pulley diameters stay continuous.
Also fix Theme.Header dropping the theme's text color when a caller passes a
`style` prop (now merges {...t.style, ...props.style}).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-28 15:01:34 -06:00
|
|
|
import {DriveCalculator} from "./calculators/DriveCalculator";
|
2024-05-31 23:53:30 -06:00
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
export const useCalculators = () => {
|
|
|
|
|
const [calc, setCalc] = useCalcQuery();
|
2024-05-31 23:53:30 -06:00
|
|
|
|
|
|
|
|
const calculators = [
|
2025-01-19 11:58:43 -07:00
|
|
|
{key: 'ratio', icon: 'th large', button: 'Ratio', contents: <RatioCalculators/>},
|
2024-06-25 17:05:41 -06:00
|
|
|
{key: 'electrical', icon: 'lightning', button: 'Electrical', contents: <ElectricalCalculators/>},
|
Add Drive Ratio calculator (pulleys, gears, sprockets)
A new "Drive Ratio" calculator under /more/calculators for belt, gear, and
chain-sprocket drives, supporting a compound train of 2–6 wheels on a single
shared belt/chain (constant size·rpm across the train).
- Pure, unit-tested math: size·rpm solver, ratio, torque, surface/belt speed,
belt length, sprocket pitch diameter, chain length, gear pitch diameter.
- Mode toggle (Pulley/Gear/Sprocket) with imperial/metric units; torque in
lb·ft or N·m.
- Add/remove wheels (2–6), each with a colorblind-friendly color shared between
its inputs and the schematic SVG diagram (Paul Tol bright palette).
- Dependency-free inline-SVG diagram: colored wheels threaded by one belt/chain,
or meshing gear teeth; auto-fitting viewBox.
- Per-mode details: belt/chain length and center distance (2-wheel only, with an
info popup), per-wheel pitch diameters, and constant train speed.
- Guards against impossible geometry (wheels overlapping) and ideal-torque note.
- Integer teeth enforced in gear/sprocket modes; pulley diameters stay continuous.
Also fix Theme.Header dropping the theme's text color when a caller passes a
`style` prop (now merges {...t.style, ...props.style}).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-28 15:01:34 -06:00
|
|
|
{key: 'drive', icon: 'cogs', button: 'Drive Ratio', contents: <DriveCalculator/>},
|
2024-06-20 09:51:29 -06:00
|
|
|
{key: 'antenna', icon: 'signal', button: 'Antenna', contents: <DipoleAntennaCalculator/>},
|
2024-06-25 17:05:41 -06:00
|
|
|
{key: 'temperature', icon: 'thermometer', button: 'Temperature', contents: <TemperatureCalculator/>},
|
2025-02-07 11:44:17 -07:00
|
|
|
{key: 'qrCode', icon: 'qrcode', button: 'QR Code', contents: <QRCodeCalculator/>},
|
2024-05-31 23:53:30 -06:00
|
|
|
];
|
|
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
const activeCalculator = calc ? calculators.find(i => i.key === calc) : null;
|
2024-05-31 23:53:30 -06:00
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
const calculatorLinks = calculators.map(i => {
|
2024-05-31 23:53:30 -06:00
|
|
|
const {button, icon, key} = i;
|
2024-06-25 17:05:41 -06:00
|
|
|
return <Link key={key} to={`/more/calculators?calc=${key}`}>
|
2025-01-19 11:58:43 -07:00
|
|
|
<Button key={key} style={{margin: '0.5em'}}>
|
2024-06-25 17:05:41 -06:00
|
|
|
{icon && <Icon name={icon}/>}
|
|
|
|
|
{button}
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
2024-05-31 23:53:30 -06:00
|
|
|
});
|
|
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
return {calc, calculators, activeCalculator, calculatorLinks}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function CalculatorsPage() {
|
|
|
|
|
const {activeCalculator, calculatorLinks} = useCalculators();
|
|
|
|
|
|
|
|
|
|
const {icon, button, title, contents} = activeCalculator || {};
|
|
|
|
|
const name = activeCalculator ? title || button + ' Calculator' : 'Calculators';
|
|
|
|
|
useTitle(name);
|
|
|
|
|
|
|
|
|
|
const body = activeCalculator ? <span>{contents}</span> : calculatorLinks;
|
2024-06-25 17:05:41 -06:00
|
|
|
|
|
|
|
|
// 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'}];
|
2024-05-31 23:53:30 -06:00
|
|
|
|
|
|
|
|
return <>
|
2024-06-25 17:05:41 -06:00
|
|
|
<Breadcrumbs crumbs={crumbs} size='huge'/>
|
|
|
|
|
|
|
|
|
|
<div style={{marginTop: '1em'}}>
|
|
|
|
|
{body}
|
|
|
|
|
</div>
|
2024-05-31 23:53:30 -06:00
|
|
|
</>
|
|
|
|
|
}
|