diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c30d211..4604c7d 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,15 +4,13 @@
-
+
-
-
-
+
@@ -211,14 +209,6 @@
-
-
- 1719096551866
-
-
-
- 1719096551866
-
1719102365836
@@ -603,7 +593,15 @@
1719516424652
-
+
+
+ 1719519913328
+
+
+
+ 1719519913328
+
+
@@ -636,7 +634,6 @@
-
@@ -661,7 +658,8 @@
-
+
+
diff --git a/src/components/options/ToolOptions.tsx b/src/components/options/ToolOptions.tsx
index efe2706..1547492 100644
--- a/src/components/options/ToolOptions.tsx
+++ b/src/components/options/ToolOptions.tsx
@@ -30,6 +30,43 @@ const FormikListenerComponent = ({
return null; // This component doesn't render anything
};
+
+interface FormikHelperProps {
+ compute: (optionsValues: T, input: any) => void;
+ input: any;
+ children?: ReactNode;
+ getGroups: (
+ formikProps: FormikProps & { updateField: UpdateField }
+ ) => ToolOptionGroup[];
+ formikProps: FormikProps;
+}
+
+const ToolBody = ({
+ compute,
+ input,
+ children,
+ getGroups,
+ formikProps
+}: FormikHelperProps) => {
+ const { values, setFieldValue } = useFormikContext();
+
+ const updateField: UpdateField = (field, value) => {
+ // @ts-ignore
+ setFieldValue(field, value);
+ };
+
+ return (
+
+
+ compute={compute}
+ input={input}
+ initialValues={values}
+ />
+
+ {children}
+
+ );
+};
export default function ToolOptions({
children,
initialValues,
@@ -50,10 +87,6 @@ export default function ToolOptions({
formRef?: RefObject>;
}) {
const theme = useTheme();
- const updateField: UpdateField = (field, value) => {
- // @ts-ignore
- formRef?.current?.setFieldValue(field, value);
- };
return (
({
onSubmit={() => {}}
>
{(formikProps) => (
-
-
-
+
{children}
-
+
)}
diff --git a/src/pages/image/png/change-colors-in-png/index.tsx b/src/pages/image/png/change-colors-in-png/index.tsx
index 445d2c6..d4a36f3 100644
--- a/src/pages/image/png/change-colors-in-png/index.tsx
+++ b/src/pages/image/png/change-colors-in-png/index.tsx
@@ -22,6 +22,7 @@ export default function ChangeColorsInPng() {
const [result, setResult] = useState(null);
const compute = (optionsValues: typeof initialValues, input: any) => {
+ if (!input) return;
const { fromColor, toColor, similarity } = optionsValues;
let fromRgb: [number, number, number];
let toRgb: [number, number, number];
@@ -117,24 +118,24 @@ export default function ChangeColorsInPng() {
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'From color and to color',
component: (
setFieldValue('fromColor', val)}
+ onChange={(val) => updateField('fromColor', val)}
description={'Replace this color (from color)'}
/>
setFieldValue('toColor', val)}
+ onChange={(val) => updateField('toColor', val)}
description={'With this color (to color)'}
/>
setFieldValue('similarity', val)}
+ onOwnChange={(val) => updateField('similarity', val)}
description={
'Match this % of similar colors of the from color. For example, 10% white will match white and a little bit of gray.'
}
diff --git a/src/pages/image/png/create-transparent/index.tsx b/src/pages/image/png/create-transparent/index.tsx
index 4df0571..ff4a560 100644
--- a/src/pages/image/png/create-transparent/index.tsx
+++ b/src/pages/image/png/create-transparent/index.tsx
@@ -21,6 +21,7 @@ export default function ChangeColorsInPng() {
const [result, setResult] = useState(null);
const compute = (optionsValues: typeof initialValues, input: any) => {
+ if (!input) return;
const { fromColor, similarity } = optionsValues;
let fromRgb: [number, number, number];
@@ -110,19 +111,19 @@ export default function ChangeColorsInPng() {
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'From color and similarity',
component: (
setFieldValue('fromColor', val)}
+ onChange={(val) => updateField('fromColor', val)}
description={'Replace this color (from color)'}
/>
setFieldValue('similarity', val)}
+ onOwnChange={(val) => updateField('similarity', val)}
description={
'Match this % of similar colors of the from color. For example, 10% white will match white and a little bit of gray.'
}
diff --git a/src/pages/number/generate/index.tsx b/src/pages/number/generate/index.tsx
index 1002bc4..33de7f9 100644
--- a/src/pages/number/generate/index.tsx
+++ b/src/pages/number/generate/index.tsx
@@ -26,7 +26,7 @@ export default function SplitText() {
result={}
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'Arithmetic sequence option',
component: (
@@ -34,19 +34,19 @@ export default function SplitText() {
setFieldValue('firstValue', val)}
+ onOwnChange={(val) => updateField('firstValue', val)}
type={'number'}
/>
setFieldValue('step', val)}
+ onOwnChange={(val) => updateField('step', val)}
type={'number'}
/>
setFieldValue('numberOfNumbers', val)}
+ onOwnChange={(val) => updateField('numberOfNumbers', val)}
type={'number'}
/>
@@ -60,7 +60,7 @@ export default function SplitText() {
'Separate elements in the arithmetic sequence by this character.'
}
value={values.separator}
- onOwnChange={(val) => setFieldValue('separator', val)}
+ onOwnChange={(val) => updateField('separator', val)}
/>
)
}
diff --git a/src/pages/number/sum/index.tsx b/src/pages/number/sum/index.tsx
index c8cd1eb..e156ccc 100644
--- a/src/pages/number/sum/index.tsx
+++ b/src/pages/number/sum/index.tsx
@@ -53,7 +53,7 @@ export default function SplitText() {
result={}
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'Number extraction',
component: extractionTypes.map(
@@ -76,17 +76,17 @@ export default function SplitText() {
? values[textValueAccessor].toString()
: ''
}
- onRadioClick={() => setFieldValue('extractionType', type)}
+ onRadioClick={() => updateField('extractionType', type)}
onTextChange={(val) =>
textValueAccessor
- ? setFieldValue(textValueAccessor, val)
+ ? updateField(textValueAccessor, val)
: null
}
/>
) : (
setFieldValue('extractionType', type)}
+ onClick={() => updateField('extractionType', type)}
checked={values.extractionType === type}
description={description}
title={title}
@@ -101,7 +101,7 @@ export default function SplitText() {
title={'Print Running Sum'}
description={"Display the sum as it's calculated step by step."}
checked={values.printRunningSum}
- onChange={(value) => setFieldValue('printRunningSum', value)}
+ onChange={(value) => updateField('printRunningSum', value)}
/>
)
}
diff --git a/src/pages/string/join/index.tsx b/src/pages/string/join/index.tsx
index ddc2b91..04dc576 100644
--- a/src/pages/string/join/index.tsx
+++ b/src/pages/string/join/index.tsx
@@ -142,7 +142,7 @@ export default function JoinText() {
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'Text Merged Options',
component: (
@@ -150,7 +150,7 @@ export default function JoinText() {
placeholder={mergeOptions.placeholder}
value={values['joinCharacter']}
onOwnChange={(value) =>
- setFieldValue(mergeOptions.accessor, value)
+ updateField(mergeOptions.accessor, value)
}
description={mergeOptions.description}
/>
@@ -163,7 +163,7 @@ export default function JoinText() {
key={option.accessor}
title={option.title}
checked={!!values[option.accessor]}
- onChange={(value) => setFieldValue(option.accessor, value)}
+ onChange={(value) => updateField(option.accessor, value)}
description={option.description}
/>
))
diff --git a/src/pages/string/split/index.tsx b/src/pages/string/split/index.tsx
index 4d3ac88..2ffe7f2 100644
--- a/src/pages/string/split/index.tsx
+++ b/src/pages/string/split/index.tsx
@@ -116,7 +116,7 @@ export default function SplitText() {
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'Split separator options',
component: splitOperators.map(({ title, description, type }) => (
@@ -127,8 +127,8 @@ export default function SplitText() {
fieldName={'splitSeparatorType'}
description={description}
value={values[`${type}Value`]}
- onRadioClick={() => setFieldValue('splitSeparatorType', type)}
- onTextChange={(val) => setFieldValue(`${type}Value`, val)}
+ onRadioClick={() => updateField('splitSeparatorType', type)}
+ onTextChange={(val) => updateField(`${type}Value`, val)}
/>
))
},
@@ -138,7 +138,7 @@ export default function SplitText() {
setFieldValue(option.accessor, value)}
+ onOwnChange={(value) => updateField(option.accessor, value)}
description={option.description}
/>
))
diff --git a/src/pages/string/to-morse/index.tsx b/src/pages/string/to-morse/index.tsx
index f7ce286..42d1d4c 100644
--- a/src/pages/string/to-morse/index.tsx
+++ b/src/pages/string/to-morse/index.tsx
@@ -33,7 +33,7 @@ export default function ToMorse() {
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'Short Signal',
component: (
@@ -42,7 +42,7 @@ export default function ToMorse() {
'Symbol that will correspond to the dot in Morse code.'
}
value={values.dotSymbol}
- onOwnChange={(val) => setFieldValue('dotSymbol', val)}
+ onOwnChange={(val) => updateField('dotSymbol', val)}
/>
)
},
@@ -54,7 +54,7 @@ export default function ToMorse() {
'Symbol that will correspond to the dash in Morse code.'
}
value={values.dashSymbol}
- onOwnChange={(val) => setFieldValue('dashSymbol', val)}
+ onOwnChange={(val) => updateField('dashSymbol', val)}
/>
)
}
diff --git a/src/pages/video/gif/change-speed/index.tsx b/src/pages/video/gif/change-speed/index.tsx
index 8277e43..f45b8e0 100644
--- a/src/pages/video/gif/change-speed/index.tsx
+++ b/src/pages/video/gif/change-speed/index.tsx
@@ -21,6 +21,7 @@ export default function ChangeSpeed() {
const [result, setResult] = useState(null);
const compute = (optionsValues: typeof initialValues, input: File) => {
+ if (!input) return;
const { newSpeed } = optionsValues;
const processImage = async (file: File, newSpeed: number) => {
@@ -123,14 +124,14 @@ export default function ChangeSpeed() {
/>
[
+ getGroups={({ values, updateField }) => [
{
title: 'New GIF speed',
component: (
setFieldValue('newSpeed', val)}
+ onOwnChange={(val) => updateField('newSpeed', Number(val))}
description={'Default new GIF speed.'}
InputProps={{ endAdornment: ms }}
type={'number'}