mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 22:19:36 +02:00
refactor: init
This commit is contained in:
141
.idea/workspace.xml
generated
141
.idea/workspace.xml
generated
@@ -5,32 +5,25 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="chore: compress video icon">
|
||||
<change afterPath="$PROJECT_DIR$/@types/theme.d.ts" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/public/assets/background-dark.png" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/sphereArea.ts" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/sphereVolume.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/App.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/App.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/Hero.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Hero.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/Navbar/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Navbar/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/ToolHeader.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolHeader.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/ToolLayout.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolLayout.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/allTools/ToolCard.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/allTools/ToolCard.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/examples/ExampleCard.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/examples/ExampleCard.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/input/BaseFileInput.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/input/BaseFileInput.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/input/ToolFileInput.tsx" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/input/ToolTextInput.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/input/ToolTextInput.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/options/ColorSelector.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/options/ColorSelector.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/options/TextFieldWithDesc.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/options/TextFieldWithDesc.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/options/ToolOptions.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/options/ToolOptions.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/result/ToolFileResult.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/result/ToolFileResult.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/result/ToolTextResult.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/result/ToolTextResult.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/config/muiConfig.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/config/muiConfig.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/home/Categories.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/home/Categories.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/home/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/home/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools-by-category/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools-by-category/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/split-pdf/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/split-pdf/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/video/compress/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/video/compress/service.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/video/gif/change-speed/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/video/gif/change-speed/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/tsconfig.json" beforeDir="false" afterPath="$PROJECT_DIR$/tsconfig.json" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/home/daniel/Projects/omni-tools/src/pages/tools/index.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/home/daniel/Projects/omni-tools/src/pages/tools/number/calculators/index.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/home/daniel/Projects/omni-tools/src/pages/tools/number/index.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/ToolContent.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolContent.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/ToolInputAndResult.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolInputAndResult.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/components/input/NumericInputWithUnit.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/input/NumericInputWithUnit.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/datatables/data/index.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/datatables/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datatables/index.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/datatables/types.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datatables/types.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/area_volume.ts" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/index.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/ohms_law.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/ohms_law.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/types.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/types.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/wire_voltage_drop.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/data/wire_voltage_drop.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/number/generic-calc/service.ts" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -47,7 +40,7 @@
|
||||
<option name="PUSH_AUTO_UPDATE" value="true" />
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="main" />
|
||||
<entry key="$PROJECT_DIR$" value="chesterkxng" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
@@ -66,87 +59,87 @@
|
||||
"state": "OPEN"
|
||||
}
|
||||
}</component>
|
||||
<component name="GitHubPullRequestState"><![CDATA[{
|
||||
"prStates": [
|
||||
<component name="GitHubPullRequestState">{
|
||||
"prStates": [
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts51PkS9",
|
||||
"number": 22
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts51PkS9",
|
||||
"number": 22
|
||||
},
|
||||
"lastSeen": 1741207144695
|
||||
"lastSeen": 1741207144695
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NiNYl",
|
||||
"number": 32
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NiNYl",
|
||||
"number": 32
|
||||
},
|
||||
"lastSeen": 1741209723869
|
||||
"lastSeen": 1741209723869
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Nheyd",
|
||||
"number": 31
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Nheyd",
|
||||
"number": 31
|
||||
},
|
||||
"lastSeen": 1741213371410
|
||||
"lastSeen": 1741213371410
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NmRBs",
|
||||
"number": 33
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6NmRBs",
|
||||
"number": 33
|
||||
},
|
||||
"lastSeen": 1741282429036
|
||||
"lastSeen": 1741282429036
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts5zyFTs",
|
||||
"number": 15
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts5zyFTs",
|
||||
"number": 15
|
||||
},
|
||||
"lastSeen": 1741535540953
|
||||
"lastSeen": 1741535540953
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QQB3c",
|
||||
"number": 59
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QQB3c",
|
||||
"number": 59
|
||||
},
|
||||
"lastSeen": 1743018960900
|
||||
"lastSeen": 1743018960900
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QMPEg",
|
||||
"number": 58
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QMPEg",
|
||||
"number": 58
|
||||
},
|
||||
"lastSeen": 1743019452983
|
||||
"lastSeen": 1743019452983
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QZvRI",
|
||||
"number": 61
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QZvRI",
|
||||
"number": 61
|
||||
},
|
||||
"lastSeen": 1743103196866
|
||||
"lastSeen": 1743103196866
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QqPrQ",
|
||||
"number": 73
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QqPrQ",
|
||||
"number": 73
|
||||
},
|
||||
"lastSeen": 1743265865001
|
||||
"lastSeen": 1743265865001
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Qp5nI",
|
||||
"number": 72
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6Qp5nI",
|
||||
"number": 72
|
||||
},
|
||||
"lastSeen": 1743338472110
|
||||
"lastSeen": 1743338472110
|
||||
},
|
||||
{
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QsjlS",
|
||||
"number": 76
|
||||
"id": {
|
||||
"id": "PR_kwDOMJIfts6QsjlS",
|
||||
"number": 76
|
||||
},
|
||||
"lastSeen": 1743352150953
|
||||
"lastSeen": 1743352150953
|
||||
}
|
||||
]
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="GithubPullRequestsUISettings">{
|
||||
"selectedUrlAndAccountId": {
|
||||
"url": "https://github.com/iib0011/omni-tools.git",
|
||||
@@ -199,7 +192,7 @@
|
||||
"Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run",
|
||||
"Vitest.replaceText function.executor": "Run",
|
||||
"Vitest.timeBetweenDates.executor": "Run",
|
||||
"git-widget-placeholder": "dark-mode",
|
||||
"git-widget-placeholder": "#89 on generic-calc",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/@types",
|
||||
|
@@ -1 +0,0 @@
|
||||
export const toolsTools = [];
|
@@ -1 +0,0 @@
|
||||
export const calculatorsTools = [];
|
@@ -1 +0,0 @@
|
||||
export const numberTools = [];
|
@@ -40,7 +40,7 @@ const FormikListenerComponent = <T,>({
|
||||
|
||||
interface ToolContentProps<T, I> extends ToolComponentProps {
|
||||
inputComponent?: ReactNode;
|
||||
resultComponent: ReactNode;
|
||||
resultComponent?: ReactNode;
|
||||
renderCustomInput?: (
|
||||
values: T,
|
||||
setFieldValue: (fieldName: string, value: any) => void
|
||||
|
@@ -6,18 +6,20 @@ export default function ToolInputAndResult({
|
||||
result
|
||||
}: {
|
||||
input?: ReactNode;
|
||||
result: ReactNode;
|
||||
result?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Grid id="tool" container spacing={2}>
|
||||
{input && (
|
||||
<Grid item xs={12} md={6}>
|
||||
{input}
|
||||
if (input || result) {
|
||||
return (
|
||||
<Grid id="tool" container spacing={2}>
|
||||
{input && (
|
||||
<Grid item xs={12} md={6}>
|
||||
{input}
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12} md={input ? 6 : 12}>
|
||||
{result}
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12} md={input ? 6 : 12}>
|
||||
{result}
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ export default function NumericInputWithUnit(props: {
|
||||
value: { value: number; unit: string };
|
||||
disabled?: boolean;
|
||||
disableChangingUnit?: boolean;
|
||||
onOwnChange: (value: { value: number; unit: string }) => void;
|
||||
onOwnChange?: (value: { value: number; unit: string }) => void;
|
||||
defaultPrefix?: string;
|
||||
}) {
|
||||
const [inputValue, setInputValue] = useState(props.value.value);
|
||||
|
@@ -1,10 +0,0 @@
|
||||
import type { DataTable } from '../types';
|
||||
import wiregauge from './wire_gauge';
|
||||
import material_electrical_properties from './material_electrical_properties';
|
||||
|
||||
const allDataTables: { [key: string]: DataTable } = {
|
||||
'wire-gauge': wiregauge,
|
||||
'material-electrical-properties': material_electrical_properties
|
||||
};
|
||||
|
||||
export default allDataTables;
|
@@ -1,18 +1,8 @@
|
||||
import type { DataTable } from './types.ts';
|
||||
|
||||
export async function getDataTable(name: string): Promise<DataTable> {
|
||||
const allDataTables = (await import('./data/index')).default;
|
||||
return allDataTables[name];
|
||||
}
|
||||
|
||||
/* Used in case later we want any kind of computed extra data */
|
||||
export function dataTableLookup(table: DataTable, key: string): any {
|
||||
return table.data[key];
|
||||
}
|
||||
|
||||
export async function listDataTables(): Promise<{ [name: string]: DataTable }> {
|
||||
const allDataTables = (await import('./data/index')).default;
|
||||
return allDataTables;
|
||||
}
|
||||
|
||||
export { DataTable };
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Represents a set of rows indexed by a key.
|
||||
Used for calculator presets
|
||||
|
||||
@@ -7,7 +7,7 @@ export interface DataTable {
|
||||
title: string;
|
||||
/* A JSON schema properties */
|
||||
columns: {
|
||||
[key: string]: any;
|
||||
[key: string]: { title: string; type: string; unit: string };
|
||||
};
|
||||
data: {
|
||||
[key: string]: {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import ohmslaw from './ohms_law';
|
||||
import voltagedropinwire from './wire_voltage_drop';
|
||||
import { areaSphere, volumeSphere } from './area_volume';
|
||||
import ohmslaw from './ohmsLaw';
|
||||
import voltageDropInWire from './voltageDropInWire';
|
||||
import sphereArea from './sphereArea';
|
||||
import sphereVolume from './sphereVolume';
|
||||
|
||||
export default [ohmslaw, voltagedropinwire, areaSphere, volumeSphere];
|
||||
export default [ohmslaw, voltageDropInWire, sphereArea, sphereVolume];
|
||||
|
@@ -5,7 +5,7 @@ const ohmsLawCalc: GenericCalcType = {
|
||||
name: 'ohms-law',
|
||||
description: 'Calculates voltage, current and resistance',
|
||||
formula: 'V = I * R',
|
||||
selections: [],
|
||||
presets: [],
|
||||
variables: [
|
||||
{
|
||||
name: 'V',
|
25
src/pages/tools/number/generic-calc/data/sphereArea.ts
Normal file
25
src/pages/tools/number/generic-calc/data/sphereArea.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { GenericCalcType } from './types';
|
||||
|
||||
const areaSphere: GenericCalcType = {
|
||||
title: 'Area of a Sphere',
|
||||
name: 'area-sphere',
|
||||
description: 'Area of a Sphere',
|
||||
formula: 'A = 4 * pi * r**2',
|
||||
presets: [],
|
||||
variables: [
|
||||
{
|
||||
name: 'A',
|
||||
title: 'Area',
|
||||
unit: 'mm2'
|
||||
},
|
||||
{
|
||||
name: 'r',
|
||||
title: 'Radius',
|
||||
formula: 'r = sqrt(A/pi) / 2',
|
||||
unit: 'mm',
|
||||
default: 1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default areaSphere;
|
@@ -1,33 +1,11 @@
|
||||
import type { GenericCalcType } from './types';
|
||||
|
||||
export const areaSphere: GenericCalcType = {
|
||||
title: 'Area of a Sphere',
|
||||
name: 'area-sphere',
|
||||
description: 'Area of a Sphere',
|
||||
formula: 'A = 4 * pi * r**2',
|
||||
selections: [],
|
||||
variables: [
|
||||
{
|
||||
name: 'A',
|
||||
title: 'Area',
|
||||
unit: 'mm2'
|
||||
},
|
||||
{
|
||||
name: 'r',
|
||||
title: 'Radius',
|
||||
formula: 'r = sqrt(A/pi) / 2',
|
||||
unit: 'mm',
|
||||
default: 1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const volumeSphere: GenericCalcType = {
|
||||
const volumeSphere: GenericCalcType = {
|
||||
title: 'Volume of a Sphere',
|
||||
name: 'volume-sphere',
|
||||
description: 'Volume of a Sphere',
|
||||
formula: 'v = (4/3) * pi * r**3',
|
||||
selections: [],
|
||||
presets: [],
|
||||
variables: [
|
||||
{
|
||||
name: 'v',
|
||||
@@ -49,3 +27,5 @@ export const volumeSphere: GenericCalcType = {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default volumeSphere;
|
@@ -1,9 +1,12 @@
|
||||
import { DataTable } from '../../../../../datatables';
|
||||
|
||||
export interface AlternativeVarInfo {
|
||||
title: string;
|
||||
unit: string;
|
||||
defaultPrefix?: string;
|
||||
formula: string;
|
||||
}
|
||||
|
||||
export interface GenericCalcType {
|
||||
title: string;
|
||||
name: string;
|
||||
@@ -17,9 +20,9 @@ export interface GenericCalcType {
|
||||
// Si prefix default
|
||||
defaultPrefix?: string;
|
||||
}[];
|
||||
selections?: {
|
||||
presets?: {
|
||||
title: string;
|
||||
source: string;
|
||||
source: DataTable;
|
||||
default: string;
|
||||
bind: {
|
||||
[key: string]: string;
|
||||
|
@@ -1,14 +1,17 @@
|
||||
import type { GenericCalcType } from './types';
|
||||
const voltagedropinwire: GenericCalcType = {
|
||||
import material_electrical_properties from '../../../../../datatables/data/material_electrical_properties';
|
||||
import wire_gauge from '../../../../../datatables/data/wire_gauge';
|
||||
|
||||
const voltageDropInWire: GenericCalcType = {
|
||||
title: 'Round trip voltage drop in cable',
|
||||
name: 'cable-voltage-drop',
|
||||
formula: 'x = (((p * L) / (A/10**6) ) *2) * I',
|
||||
description:
|
||||
'Calculates round trip voltage and power loss in a 2 conductor cable',
|
||||
selections: [
|
||||
presets: [
|
||||
{
|
||||
title: 'Material',
|
||||
source: 'material-electrical-properties',
|
||||
source: material_electrical_properties,
|
||||
default: 'Copper',
|
||||
bind: {
|
||||
p: 'resistivity_20c'
|
||||
@@ -17,7 +20,7 @@ const voltagedropinwire: GenericCalcType = {
|
||||
|
||||
{
|
||||
title: 'Wire Gauge',
|
||||
source: 'wire-gauge',
|
||||
source: wire_gauge,
|
||||
default: '24 AWG',
|
||||
bind: {
|
||||
A: 'area'
|
||||
@@ -72,4 +75,4 @@ const voltagedropinwire: GenericCalcType = {
|
||||
]
|
||||
};
|
||||
|
||||
export default voltagedropinwire;
|
||||
export default voltageDropInWire;
|
@@ -1,31 +1,29 @@
|
||||
import {
|
||||
Box,
|
||||
Autocomplete,
|
||||
TextField,
|
||||
Box,
|
||||
Radio,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableRow
|
||||
TableRow,
|
||||
TextField
|
||||
} from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useContext, useState } from 'react';
|
||||
import ToolContent from '@components/ToolContent';
|
||||
import { ToolComponentProps } from '@tools/defineTool';
|
||||
import ToolTextResult from '@components/result/ToolTextResult';
|
||||
import NumericInputWithUnit from '@components/input/NumericInputWithUnit';
|
||||
import { UpdateField } from '@components/options/ToolOptions';
|
||||
import { InitialValuesType } from './types';
|
||||
import type { AlternativeVarInfo, GenericCalcType } from './data/types';
|
||||
import type { DataTable } from 'datatables';
|
||||
import { getDataTable, dataTableLookup } from 'datatables';
|
||||
import { dataTableLookup } from 'datatables';
|
||||
|
||||
import nerdamer from 'nerdamer-prime';
|
||||
import 'nerdamer-prime/Algebra';
|
||||
import 'nerdamer-prime/Solve';
|
||||
import 'nerdamer-prime/Calculus';
|
||||
import Qty from 'js-quantities';
|
||||
import { error } from 'console';
|
||||
import { CustomSnackBarContext } from 'contexts/CustomSnackBarContext';
|
||||
|
||||
function numericSolveEquationFor(
|
||||
equation: string,
|
||||
@@ -59,15 +57,8 @@ export default async function makeTool(
|
||||
presets: {}
|
||||
};
|
||||
|
||||
const dataTables: { [key: string]: DataTable } = {};
|
||||
|
||||
for (const selection of calcData.selections || []) {
|
||||
dataTables[selection.source] = await getDataTable(selection.source);
|
||||
}
|
||||
|
||||
return function GenericCalc({ title }: ToolComponentProps) {
|
||||
const [result, setResult] = useState<string>('');
|
||||
|
||||
const { showSnackBar } = useContext(CustomSnackBarContext);
|
||||
const [alternatesByVariable, setAlternatesByVariable] = useState<{
|
||||
[key: string]: {
|
||||
value: {
|
||||
@@ -126,7 +117,7 @@ export default async function makeTool(
|
||||
}
|
||||
}
|
||||
|
||||
const selectionData = calcData.selections?.find(
|
||||
const selectionData = calcData.presets?.find(
|
||||
(sel) => sel.title === selection
|
||||
);
|
||||
|
||||
@@ -142,12 +133,11 @@ export default async function makeTool(
|
||||
updateVarField(
|
||||
key,
|
||||
|
||||
dataTableLookup(dataTables[selectionData.source], preset)[
|
||||
dataTableLookup(selectionData.source, preset)[
|
||||
selectionData.bind[key]
|
||||
],
|
||||
|
||||
dataTables[selectionData.source].columns[selectionData.bind[key]]
|
||||
?.unit || '',
|
||||
selectionData.source.columns[selectionData.bind[key]]?.unit || '',
|
||||
currentValues,
|
||||
updateFieldFunc
|
||||
);
|
||||
@@ -178,19 +168,16 @@ export default async function makeTool(
|
||||
}
|
||||
});
|
||||
|
||||
calcData.selections?.forEach((selection) => {
|
||||
calcData.presets?.forEach((selection) => {
|
||||
initialValues.presets[selection.title] = selection.default;
|
||||
if (selection.default == '<custom>') return;
|
||||
for (const key in selection.bind) {
|
||||
initialValues.vars[key] = {
|
||||
value: dataTableLookup(
|
||||
dataTables[selection.source],
|
||||
selection.default
|
||||
)[selection.bind[key]],
|
||||
value: dataTableLookup(selection.source, selection.default)[
|
||||
selection.bind[key]
|
||||
],
|
||||
|
||||
unit:
|
||||
dataTables[selection.source].columns[selection.bind[key]]?.unit ||
|
||||
''
|
||||
unit: selection.source.columns[selection.bind[key]]?.unit || ''
|
||||
};
|
||||
valsBoundToPreset[key] = selection.title;
|
||||
}
|
||||
@@ -264,53 +251,55 @@ export default async function makeTool(
|
||||
calcData.formula
|
||||
}}
|
||||
getGroups={({ values, updateField }) => [
|
||||
{
|
||||
title: 'Presets',
|
||||
component: (
|
||||
<Box>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Option</TableCell>
|
||||
<TableCell>Value</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{calcData.selections?.map((preset) => (
|
||||
<TableRow key={preset.title}>
|
||||
<TableCell>{preset.title}</TableCell>
|
||||
<TableCell>
|
||||
<Autocomplete
|
||||
disablePortal
|
||||
id="combo-box-demo"
|
||||
value={values.presets[preset.title]}
|
||||
options={[
|
||||
'<custom>',
|
||||
...Object.keys(
|
||||
dataTables[preset.source].data
|
||||
).sort()
|
||||
]}
|
||||
sx={{ width: 300 }}
|
||||
onChange={(event, newValue) => {
|
||||
handleSelectedPresetChange(
|
||||
preset.title,
|
||||
newValue || '',
|
||||
values,
|
||||
updateField
|
||||
);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="Preset" />
|
||||
)}
|
||||
></Autocomplete>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Box>
|
||||
)
|
||||
},
|
||||
...(calcData.presets?.length
|
||||
? [
|
||||
{
|
||||
title: 'Presets',
|
||||
component: (
|
||||
<Box>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Option</TableCell>
|
||||
<TableCell>Value</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{calcData.presets?.map((preset) => (
|
||||
<TableRow key={preset.title}>
|
||||
<TableCell>{preset.title}</TableCell>
|
||||
<TableCell>
|
||||
<Autocomplete
|
||||
disablePortal
|
||||
id="combo-box-demo"
|
||||
value={values.presets[preset.title]}
|
||||
options={[
|
||||
'<custom>',
|
||||
...Object.keys(preset.source.data).sort()
|
||||
]}
|
||||
sx={{ width: 300 }}
|
||||
onChange={(event, newValue) => {
|
||||
handleSelectedPresetChange(
|
||||
preset.title,
|
||||
newValue || '',
|
||||
values,
|
||||
updateField
|
||||
);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="Preset" />
|
||||
)}
|
||||
></Autocomplete>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: 'Variables',
|
||||
component: (
|
||||
@@ -330,9 +319,6 @@ export default async function makeTool(
|
||||
<TableCell>{variable.title}</TableCell>
|
||||
<TableCell>
|
||||
<NumericInputWithUnit
|
||||
description={
|
||||
valsBoundToPreset[variable.name] || ''
|
||||
}
|
||||
defaultPrefix={variable.defaultPrefix}
|
||||
value={values.vars[variable.name]}
|
||||
disabled={
|
||||
@@ -351,7 +337,6 @@ export default async function makeTool(
|
||||
updateField
|
||||
)
|
||||
}
|
||||
type="number"
|
||||
/>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -362,9 +347,6 @@ export default async function makeTool(
|
||||
<TableCell>
|
||||
<NumericInputWithUnit
|
||||
key={alt.title}
|
||||
description={
|
||||
valsBoundToPreset[alt.title] || ''
|
||||
}
|
||||
defaultPrefix={alt.defaultPrefix || ''}
|
||||
value={{
|
||||
value:
|
||||
@@ -442,7 +424,7 @@ export default async function makeTool(
|
||||
]}
|
||||
compute={(values) => {
|
||||
if (values.outputVariable === '') {
|
||||
setResult('Please select a solve for variable');
|
||||
showSnackBar('Please select a solve for variable', 'error');
|
||||
return;
|
||||
}
|
||||
let expr: nerdamer.Expression | null = null;
|
||||
@@ -491,8 +473,6 @@ export default async function makeTool(
|
||||
result = (result as unknown as nerdamer.Expression[])[0];
|
||||
}
|
||||
|
||||
setResult(result.toString());
|
||||
|
||||
if (result) {
|
||||
if (values.vars[values.outputVariable] != undefined) {
|
||||
values.vars[values.outputVariable].value = parseFloat(
|
||||
|
@@ -1,5 +0,0 @@
|
||||
import { InitialValuesType } from './types';
|
||||
|
||||
export function main(input: string, options: InitialValuesType): string {
|
||||
return input + 'pp';
|
||||
}
|
Reference in New Issue
Block a user