refactor: use ToolContent

This commit is contained in:
Ibrahima G. Coulibaly
2025-03-09 17:22:14 +00:00
parent b4322335cc
commit b168edea82
8 changed files with 250 additions and 271 deletions

1
.gitignore vendored
View File

@@ -40,3 +40,4 @@ yarn-error.log*
/playwright-report /playwright-report
dist.zip dist.zip
.aider*

50
.idea/workspace.xml generated
View File

@@ -4,9 +4,15 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="chore: remove unnecessary files"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="refactor: validateJson">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/string/text-replacer/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/string/text-replacer/service.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/tools/list/duplicate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/list/duplicate/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/list/find-unique/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/list/find-unique/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/list/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/list/index.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/list/shuffle/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/list/shuffle/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/string/join/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/string/join/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/tools/string/to-morse/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/string/to-morse/index.tsx" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -23,7 +29,7 @@
<option name="PUSH_AUTO_UPDATE" value="true" /> <option name="PUSH_AUTO_UPDATE" value="true" />
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$" value="truncate" /> <entry key="$PROJECT_DIR$" value="fork/ady-cf/feature/validate-json" />
</map> </map>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@@ -68,6 +74,13 @@
&quot;number&quot;: 33 &quot;number&quot;: 33
}, },
&quot;lastSeen&quot;: 1741282429036 &quot;lastSeen&quot;: 1741282429036
},
{
&quot;id&quot;: {
&quot;id&quot;: &quot;PR_kwDOMJIfts5zyFTs&quot;,
&quot;number&quot;: 15
},
&quot;lastSeen&quot;: 1741535540953
} }
] ]
}</component> }</component>
@@ -77,6 +90,9 @@
&quot;accountId&quot;: &quot;45f8cd51-000f-4ba4-a4c6-c4d96ac9b1e5&quot; &quot;accountId&quot;: &quot;45f8cd51-000f-4ba4-a4c6-c4d96ac9b1e5&quot;
} }
}</component> }</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/node_modules/react-image-crop/dist/index.d.ts" root0="SKIP_INSPECTION" />
</component>
<component name="KubernetesApiProvider">{ <component name="KubernetesApiProvider">{
&quot;isMigrated&quot;: true &quot;isMigrated&quot;: true
}</component> }</component>
@@ -119,7 +135,7 @@
"git-widget-placeholder": "main", "git-widget-placeholder": "main",
"ignore.virus.scanning.warn.message": "true", "ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true", "kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/.husky", "last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/src/pages/tools/list/duplicate/index.tsx",
"node.js.detected.package.eslint": "true", "node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true", "node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.eslint": "(autodetect)",
@@ -137,7 +153,7 @@
"project.structure.last.edited": "Problems", "project.structure.last.edited": "Problems",
"project.structure.proportion": "0.0", "project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.2", "project.structure.side.proportion": "0.2",
"settings.editor.selected.configurable": "settings.typescriptcompiler", "settings.editor.selected.configurable": "refactai_advanced_settings",
"ts.external.directory.path": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib", "ts.external.directory.path": "C:\\Users\\Ibrahima\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
"vue.rearranger.settings.migration": "true" "vue.rearranger.settings.migration": "true"
} }
@@ -323,14 +339,8 @@
<workItem from="1740933006573" duration="3679000" /> <workItem from="1740933006573" duration="3679000" />
<workItem from="1741475969294" duration="4215000" /> <workItem from="1741475969294" duration="4215000" />
<workItem from="1741494053121" duration="178000" /> <workItem from="1741494053121" duration="178000" />
</task> <workItem from="1741537936314" duration="1294000" />
<task id="LOCAL-00105" summary="feat: compress png"> <workItem from="1741539602311" duration="1240000" />
<option name="closed" value="true" />
<created>1740321912140</created>
<option name="number" value="00105" />
<option name="presentableId" value="LOCAL-00105" />
<option name="project" value="LOCAL" />
<updated>1740321912140</updated>
</task> </task>
<task id="LOCAL-00106" summary="fix: compress png"> <task id="LOCAL-00106" summary="fix: compress png">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -716,7 +726,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1741492943849</updated> <updated>1741492943849</updated>
</task> </task>
<option name="localTasksCounter" value="154" /> <task id="LOCAL-00154" summary="refactor: validateJson">
<option name="closed" value="true" />
<created>1741535390090</created>
<option name="number" value="00154" />
<option name="presentableId" value="LOCAL-00154" />
<option name="project" value="LOCAL" />
<updated>1741535390090</updated>
</task>
<option name="localTasksCounter" value="155" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -763,7 +781,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="chore: handle enter press on search" />
<MESSAGE value="chore: show tooloptions in example" /> <MESSAGE value="chore: show tooloptions in example" />
<MESSAGE value="refact: examples" /> <MESSAGE value="refact: examples" />
<MESSAGE value="fix: examples" /> <MESSAGE value="fix: examples" />
@@ -788,7 +805,8 @@
<MESSAGE value="feat: change pgn opacity" /> <MESSAGE value="feat: change pgn opacity" />
<MESSAGE value="feat: crop png" /> <MESSAGE value="feat: crop png" />
<MESSAGE value="chore: remove unnecessary files" /> <MESSAGE value="chore: remove unnecessary files" />
<option name="LAST_COMMIT_MESSAGE" value="chore: remove unnecessary files" /> <MESSAGE value="refactor: validateJson" />
<option name="LAST_COMMIT_MESSAGE" value="refactor: validateJson" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -8,12 +8,5 @@ const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required') // splitSeparator: Yup.string().required('The separator is required')
}); });
export default function Duplicate() { export default function Duplicate() {
return ( return <Box>Lorem ipsum</Box>;
<ToolContent
title="Duplicate"
initialValues={initialValues}
compute={() => {}}
resultComponent={<Box>Lorem ipsum</Box>}
/>
);
} }

View File

@@ -2,9 +2,8 @@ import { Box } from '@mui/material';
import React, { useState } from 'react'; import React, { useState } from 'react';
import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult'; import ToolTextResult from '@components/result/ToolTextResult';
import ToolOptions from '@components/options/ToolOptions'; import ToolContent from '@components/ToolContent';
import { findUniqueCompute, SplitOperatorType } from './service'; import { findUniqueCompute, SplitOperatorType } from './service';
import ToolInputAndResult from '@components/ToolInputAndResult';
import SimpleRadio from '@components/options/SimpleRadio'; import SimpleRadio from '@components/options/SimpleRadio';
import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
import CheckboxWithDesc from '@components/options/CheckboxWithDesc'; import CheckboxWithDesc from '@components/options/CheckboxWithDesc';
@@ -64,19 +63,16 @@ export default function FindUnique() {
}; };
return ( return (
<Box> <ToolContent
<ToolInputAndResult title="Find Unique"
input={ initialValues={initialValues}
<ToolTextInput
title={'Input list'}
value={input}
onChange={setInput}
/>
}
result={<ToolTextResult title={'Unique items'} value={result} />}
/>
<ToolOptions
compute={compute} compute={compute}
input={input}
setInput={setInput}
inputComponent={
<ToolTextInput title={'Input list'} value={input} onChange={setInput} />
}
resultComponent={<ToolTextResult title={'Unique items'} value={result} />}
getGroups={({ values, updateField }) => [ getGroups={({ values, updateField }) => [
{ {
title: 'Input List Delimiter', title: 'Input List Delimiter',
@@ -150,9 +146,6 @@ export default function FindUnique() {
) )
} }
]} ]}
initialValues={initialValues}
input={input}
/> />
</Box>
); );
} }

View File

@@ -11,15 +11,15 @@ import { tool as listShuffle } from './shuffle/meta';
import { tool as listSort } from './sort/meta'; import { tool as listSort } from './sort/meta';
export const listTools = [ export const listTools = [
listSort, // TODO: Check if uses ToolContent - Needs update to use ToolContent - Implemented ToolContent listSort,
// listUnwrap, // listUnwrap,
listReverse, // TODO: Check if uses ToolContent - Needs update to use ToolContent listReverse,
listFindUnique, // TODO: Check if uses ToolContent - Needs update to use ToolContent listFindUnique,
listFindMostPopular, // TODO: Check if uses ToolContent - Needs update to use ToolContent listFindMostPopular,
listGroup, // TODO: Check if uses ToolContent - Needs update to use ToolContent listGroup,
// listWrap, // listWrap,
listRotate, // TODO: Check if uses ToolContent - Needs update to use ToolContent listRotate,
listShuffle // TODO: Check if uses ToolContent - Needs update to use ToolContent listShuffle
// listTruncate, // listTruncate,
// listDuplicate // listDuplicate
]; ];

View File

@@ -2,12 +2,11 @@ import { Box } from '@mui/material';
import React, { useState } from 'react'; import React, { useState } from 'react';
import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult'; import ToolTextResult from '@components/result/ToolTextResult';
import ToolOptions from '@components/options/ToolOptions'; import ToolContent from '@components/ToolContent';
import { shuffleList, SplitOperatorType } from './service'; import { shuffleList, SplitOperatorType } from './service';
import ToolInputAndResult from '@components/ToolInputAndResult';
import SimpleRadio from '@components/options/SimpleRadio'; import SimpleRadio from '@components/options/SimpleRadio';
import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
import { isNumber } from '../../../../utils/string'; import { isNumber } from '@utils/string';
const initialValues = { const initialValues = {
splitOperatorType: 'symbol' as SplitOperatorType, splitOperatorType: 'symbol' as SplitOperatorType,
@@ -51,19 +50,18 @@ export default function Shuffle() {
}; };
return ( return (
<Box> <ToolContent
<ToolInputAndResult title="Shuffle"
input={ initialValues={initialValues}
<ToolTextInput
title={'Input list'}
value={input}
onChange={setInput}
/>
}
result={<ToolTextResult title={'Shuffled list'} value={result} />}
/>
<ToolOptions
compute={compute} compute={compute}
input={input}
setInput={setInput}
inputComponent={
<ToolTextInput title={'Input list'} value={input} onChange={setInput} />
}
resultComponent={
<ToolTextResult title={'Shuffled list'} value={result} />
}
getGroups={({ values, updateField }) => [ getGroups={({ values, updateField }) => [
{ {
title: 'Input list separator', title: 'Input list separator',
@@ -111,9 +109,6 @@ export default function Shuffle() {
) )
} }
]} ]}
initialValues={initialValues}
input={input}
/> />
</Box>
); );
} }

View File

@@ -1,20 +1,13 @@
import { Box } from '@mui/material'; import React, { useState } from 'react';
import React, { useRef, useState } from 'react';
import * as Yup from 'yup'; import * as Yup from 'yup';
import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult'; import ToolTextResult from '@components/result/ToolTextResult';
import ToolOptions, { GetGroupsType } from '@components/options/ToolOptions'; import ToolContent from '@components/ToolContent';
import { GetGroupsType } from '@components/options/ToolOptions';
import { mergeText } from './service'; import { mergeText } from './service';
import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
import CheckboxWithDesc from '@components/options/CheckboxWithDesc'; import CheckboxWithDesc from '@components/options/CheckboxWithDesc';
import ToolInputAndResult from '@components/ToolInputAndResult'; import { CardExampleType } from '@components/examples/ToolExamples';
import ToolInfo from '@components/ToolInfo';
import Separator from '@components/Separator';
import ToolExamples, {
CardExampleType
} from '@components/examples/ToolExamples';
import { FormikProps } from 'formik';
import { ToolComponentProps } from '@tools/defineTool'; import { ToolComponentProps } from '@tools/defineTool';
const initialValues = { const initialValues = {
@@ -116,7 +109,6 @@ s
export default function JoinText({ title }: ToolComponentProps) { export default function JoinText({ title }: ToolComponentProps) {
const [input, setInput] = useState<string>(''); const [input, setInput] = useState<string>('');
const [result, setResult] = useState<string>(''); const [result, setResult] = useState<string>('');
const formRef = useRef<FormikProps<InitialValuesType>>(null);
const compute = (optionsValues: InitialValuesType, input: any) => { const compute = (optionsValues: InitialValuesType, input: any) => {
const { joinCharacter, deleteBlank, deleteTrailing } = optionsValues; const { joinCharacter, deleteBlank, deleteTrailing } = optionsValues;
setResult(mergeText(input, deleteBlank, deleteTrailing, joinCharacter)); setResult(mergeText(input, deleteBlank, deleteTrailing, joinCharacter));
@@ -151,36 +143,27 @@ export default function JoinText({ title }: ToolComponentProps) {
} }
]; ];
return ( return (
<Box> <ToolContent
<ToolInputAndResult title={title}
input={ initialValues={initialValues}
compute={compute}
input={input}
setInput={setInput}
inputComponent={
<ToolTextInput <ToolTextInput
title={'Text Pieces'} title={'Text Pieces'}
value={input} value={input}
onChange={setInput} onChange={setInput}
/> />
} }
result={<ToolTextResult title={'Joined Text'} value={result} />} resultComponent={<ToolTextResult title={'Joined Text'} value={result} />}
/>
<ToolOptions
formRef={formRef}
compute={compute}
getGroups={getGroups} getGroups={getGroups}
initialValues={initialValues} toolInfo={{
input={input} title: 'What Is a Text Joiner?',
/> description:
<ToolInfo 'With this tool you can join parts of the text together. It takes a list of text values, separated by newlines, and merges them together. You can set the character that will be placed between the parts of the combined text. Also, you can ignore all empty lines and remove spaces and tabs at the end of all lines. Textabulous!'
title="What Is a Text Joiner?" }}
description="With this tool you can join parts of the text together. It takes a list of text values, separated by newlines, and merges them together. You can set the character that will be placed between the parts of the combined text. Also, you can ignore all empty lines and remove spaces and tabs at the end of all lines. Textabulous!"
/>
<Separator backgroundColor="#5581b5" margin="50px" />
<ToolExamples
title={title}
exampleCards={exampleCards} exampleCards={exampleCards}
getGroups={getGroups}
formRef={formRef}
setInput={setInput}
/> />
</Box>
); );
} }

View File

@@ -1,11 +1,9 @@
import { Box } from '@mui/material'; import ToolContent from '@components/ToolContent';
import React, { useState } from 'react'; import React, { useState } from 'react';
import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult'; import ToolTextResult from '@components/result/ToolTextResult';
import ToolOptions from '@components/options/ToolOptions';
import { compute } from './service'; import { compute } from './service';
import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
import ToolInputAndResult from '@components/ToolInputAndResult';
const initialValues = { const initialValues = {
dotSymbol: '.', dotSymbol: '.',
@@ -22,13 +20,14 @@ export default function ToMorse() {
}; };
return ( return (
<Box> <ToolContent
<ToolInputAndResult title="To Morse"
input={<ToolTextInput value={input} onChange={setInput} />} initialValues={initialValues}
result={<ToolTextResult title={'Morse code'} value={result} />}
/>
<ToolOptions
compute={computeOptions} compute={computeOptions}
input={input}
setInput={setInput}
inputComponent={<ToolTextInput value={input} onChange={setInput} />}
resultComponent={<ToolTextResult title={'Morse code'} value={result} />}
getGroups={({ values, updateField }) => [ getGroups={({ values, updateField }) => [
{ {
title: 'Short Signal', title: 'Short Signal',
@@ -55,9 +54,6 @@ export default function ToMorse() {
) )
} }
]} ]}
initialValues={initialValues}
input={input}
/> />
</Box>
); );
} }