mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 20:59:56 -05:00
Moving OTP and Vin decoder to calculators to save Navbar space. Reworking calculators to purpose groups, and adding colors.
This commit is contained in:
parent
c95afc7f62
commit
05bb65fc03
8 changed files with 373 additions and 308 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import React from "react";
|
||||
import {Breadcrumbs, useTitle} from "./Common";
|
||||
import {Button, Icon} from "./Theme";
|
||||
import {Button, Header, Icon} from "./Theme";
|
||||
import {useCalcQuery} from "../hooks/customHooks";
|
||||
import {TemperatureCalculator} from "./calculators/TemperatureCalculator";
|
||||
import {ElectricalCalculators} from "./calculators/ElectricalCalculators";
|
||||
|
|
@ -11,32 +11,63 @@ import {QRCodeCalculator} from "./calculators/QRCodeCalculator";
|
|||
import {DriveCalculator} from "./calculators/DriveCalculator";
|
||||
import {WaterCalculator} from "./calculators/WaterCalculator";
|
||||
import {FoodStorageCalculator} from "./calculators/FoodStorageCalculator";
|
||||
import {OneTimePadCalculator} from "./calculators/OneTimePadCalculator";
|
||||
import {VinDecoderCalculator} from "./calculators/VinDecoderCalculator";
|
||||
|
||||
// Calculators are shown in these titled groups, in this order. Each calculator carries a
|
||||
// `group` matching one of these names; any calculator whose group is missing/unknown falls
|
||||
// into a trailing "Other" section so a new calculator can never silently disappear.
|
||||
//
|
||||
// `color` is a Semantic UI named color (colorblind-friendly palette) used to tint the group's
|
||||
// buttons. Violet is intentionally avoided — it is the default navbar color and would blend in.
|
||||
export const CALCULATOR_GROUPS = [
|
||||
{name: 'Preparedness & Storage', color: 'red'},
|
||||
{name: 'Radio & Communications', color: 'blue'},
|
||||
{name: 'Engineering', color: 'yellow'},
|
||||
{name: 'Tools & Reference', color: 'grey'},
|
||||
];
|
||||
|
||||
export const useCalculators = () => {
|
||||
const [calc, setCalc] = useCalcQuery();
|
||||
|
||||
const calculators = [
|
||||
{key: 'ratio', icon: 'th large', button: 'Ratio', contents: <RatioCalculators/>},
|
||||
{key: 'electrical', icon: 'lightning', button: 'Electrical', contents: <ElectricalCalculators/>},
|
||||
{key: 'drive', icon: 'cogs', button: 'Drive Ratio', contents: <DriveCalculator/>},
|
||||
{key: 'water', icon: 'tint', button: 'Water Storage', contents: <WaterCalculator/>},
|
||||
{key: 'ration', icon: 'food', button: 'Food Storage', contents: <FoodStorageCalculator/>},
|
||||
{key: 'antenna', icon: 'signal', button: 'Antenna', contents: <DipoleAntennaCalculator/>},
|
||||
{key: 'temperature', icon: 'thermometer', button: 'Temperature', contents: <TemperatureCalculator/>},
|
||||
{key: 'qrCode', icon: 'qrcode', button: 'QR Code', contents: <QRCodeCalculator/>},
|
||||
{key: 'ratio', icon: 'th large', button: 'Ratio', group: 'Engineering', contents: <RatioCalculators/>},
|
||||
{key: 'electrical', icon: 'lightning', button: 'Electrical', group: 'Engineering', contents: <ElectricalCalculators/>},
|
||||
{key: 'drive', icon: 'cogs', button: 'Drive Ratio', group: 'Engineering', contents: <DriveCalculator/>},
|
||||
{key: 'water', icon: 'tint', button: 'Water Storage', group: 'Preparedness & Storage', contents: <WaterCalculator/>},
|
||||
{key: 'ration', icon: 'food', button: 'Food Storage', group: 'Preparedness & Storage', contents: <FoodStorageCalculator/>},
|
||||
{key: 'antenna', icon: 'signal', button: 'Antenna', group: 'Radio & Communications', contents: <DipoleAntennaCalculator/>},
|
||||
{key: 'temperature', icon: 'thermometer', button: 'Temperature', group: 'Tools & Reference', contents: <TemperatureCalculator/>},
|
||||
{key: 'qrCode', icon: 'qrcode', button: 'QR Code', group: 'Tools & Reference', contents: <QRCodeCalculator/>},
|
||||
{key: 'otp', icon: 'lock', button: 'One Time Pad', title: 'One Time Pad', group: 'Radio & Communications', contents: <OneTimePadCalculator/>},
|
||||
{key: 'vin', icon: 'car', button: 'VIN Decoder', title: 'VIN Decoder', group: 'Tools & Reference', contents: <VinDecoderCalculator/>},
|
||||
];
|
||||
|
||||
const activeCalculator = calc ? calculators.find(i => i.key === calc) : null;
|
||||
|
||||
const calculatorLinks = calculators.map(i => {
|
||||
const {button, icon, key} = i;
|
||||
return <Link key={key} to={`/more/calculators?calc=${key}`}>
|
||||
<Button key={key} style={{margin: '0.5em'}}>
|
||||
const calculatorButton = ({button, icon, key}, color) =>
|
||||
<Link key={key} to={`/more/calculators?calc=${key}`}>
|
||||
<Button color={color} style={{margin: '0.5em'}}>
|
||||
{icon && <Icon name={icon}/>}
|
||||
{button}
|
||||
</Button>
|
||||
</Link>
|
||||
});
|
||||
</Link>;
|
||||
|
||||
// Render each defined group as a titled section, then any leftovers under "Other".
|
||||
const groupNames = CALCULATOR_GROUPS.map(g => g.name);
|
||||
const grouped = CALCULATOR_GROUPS.map(g => [g.name, g.color, calculators.filter(c => c.group === g.name)]);
|
||||
const leftovers = calculators.filter(c => !groupNames.includes(c.group));
|
||||
if (leftovers.length > 0) {
|
||||
grouped.push(['Other', undefined, leftovers]);
|
||||
}
|
||||
|
||||
const calculatorLinks = grouped
|
||||
.filter(([, , items]) => items.length > 0)
|
||||
.map(([name, color, items]) =>
|
||||
<div key={name} style={{marginBottom: '1.5em'}}>
|
||||
<Header as='h3'>{name}</Header>
|
||||
{items.map(c => calculatorButton(c, color))}
|
||||
</div>);
|
||||
|
||||
return {calc, calculators, activeCalculator, calculatorLinks}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue