Skip to content

Commit

Permalink
fix: radio and list sort init
Browse files Browse the repository at this point in the history
  • Loading branch information
iib0011 committed Jun 27, 2024
1 parent 8650703 commit a6eb5d5
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 79 deletions.
40 changes: 22 additions & 18 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ export default function Hero() {
/>
)}
renderOption={(props, option) => (
<Box component="li" {...props} onClick={() => navigate(option.path)}>
<Box
component="li"
{...props}
onClick={() => navigate('/' + option.path)}
>
<Box>
<Typography fontWeight={'bold'}>{option.name}</Typography>
<Typography fontSize={12}>{option.shortDescription}</Typography>
Expand Down
23 changes: 10 additions & 13 deletions src/components/options/RadioWithTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@ import React from 'react';
import TextFieldWithDesc from './TextFieldWithDesc';
import SimpleRadio from './SimpleRadio';

const RadioWithTextField = <T,>({
fieldName,
radioValue,
const RadioWithTextField = ({
title,
onRadioChange,
onRadioClick,
checked,
value,
description,
onTextChange,
typeDescription
radioDescription
}: {
fieldName: string;
title: string;
radioValue: T;
onRadioChange: (val: T) => void;
checked: boolean;
onRadioClick: () => void;
value: string;
description: string;
onTextChange: (value: string) => void;
typeDescription?: string;
radioDescription?: string;
}) => {
const onChange = () => onRadioChange(radioValue);
return (
<Box>
<SimpleRadio
value={radioValue}
onChange={onChange}
fieldName={fieldName}
checked={checked}
onClick={onRadioClick}
title={title}
description={typeDescription}
description={radioDescription}
/>
<TextFieldWithDesc
value={value}
Expand Down
36 changes: 15 additions & 21 deletions src/components/options/SimpleRadio.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
import { Box, Stack } from '@mui/material';
import { Field } from 'formik';
import { Box, Radio, Stack } from '@mui/material';
import { Field, useFormikContext } from 'formik';
import Typography from '@mui/material/Typography';
import { globalDescriptionFontSize } from '../../config/uiConfig';
import React from 'react';
import { globalDescriptionFontSize } from '../../config/uiConfig';

interface SimpleRadioProps {
onChange: () => void;
fieldName: string;
value: any;
title: string;
description?: string;
checked: boolean;
onClick: () => void;
}

export default function SimpleRadio({
onChange,
fieldName,
value,
const SimpleRadio: React.FC<SimpleRadioProps> = ({
onClick,
title,
description
}: SimpleRadioProps) {
description,
checked
}) => {
return (
<Box>
<Stack
direction={'row'}
sx={{ mt: 2, mb: 1, cursor: 'pointer' }}
onClick={onChange}
alignItems={'center'}
spacing={1}
onClick={onClick}
>
<Field
type="radio"
name={fieldName}
value={value}
onChange={onChange}
/>
<Radio checked={checked} onClick={onClick} />
<Typography>{title}</Typography>
</Stack>
{description && (
Expand All @@ -43,4 +35,6 @@ export default function SimpleRadio({
)}
</Box>
);
}
};

export default SimpleRadio;
10 changes: 6 additions & 4 deletions src/components/options/TextFieldWithDesc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Typography from '@mui/material/Typography';
import React from 'react';

type OwnProps = {
description: string;
description?: string;
value: string | number;
onChange: (value: string) => void;
placeholder?: string;
Expand All @@ -24,9 +24,11 @@ const TextFieldWithDesc = ({
onChange={(event) => onChange(event.target.value)}
{...props}
/>
<Typography fontSize={12} mt={1}>
{description}
</Typography>
{description && (
<Typography fontSize={12} mt={1}>
{description}
</Typography>
)}
</Box>
);
};
Expand Down
3 changes: 2 additions & 1 deletion src/pages/list/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { tool as listSort } from './sort/meta';
export const listTools = [];

export const listTools = [listSort];
110 changes: 103 additions & 7 deletions src/pages/list/sort/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,107 @@
import { Box } from '@mui/material';
import React from 'react';
import React, { useState } from 'react';
import ToolTextInput from '../../../components/input/ToolTextInput';
import ToolTextResult from '../../../components/result/ToolTextResult';
import * as Yup from 'yup';
import ToolOptions from '../../../components/options/ToolOptions';
import { Sort, SortingMethod, SplitOperatorType } from './service';
import ToolInputAndResult from '../../../components/ToolInputAndResult';
import SimpleRadio from '../../../components/options/SimpleRadio';

const initialValues = {};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
export default function Sort() {
return <Box>Lorem ipsum</Box>;
const initialValues = {
splitSeparatorType: 'symbol' as SplitOperatorType,
sortingMethod: 'alphabetic' as SortingMethod,
increasing: true,
splitSeparator: ',',
joinSeparator: ',',
removeDuplicated: false,
caseSensitive: false
};
const splitOperators: {
title: string;
description: string;
type: SplitOperatorType;
}[] = [
{
title: 'Use a Symbol for Splitting',
description: 'Delimit input list items with a character.',
type: 'symbol'
},
{
title: 'Use a Regex for Splitting',
type: 'regex',
description: 'Delimit input list items with a regular expression.'
}
];

export default function SplitText() {
const [input, setInput] = useState<string>('');
const [result, setResult] = useState<string>('');
// const formRef = useRef<FormikProps<typeof initialValues>>(null);
const computeExternal = (optionsValues: typeof initialValues, input: any) => {
const {
splitSeparatorType,
joinSeparator,
splitSeparator,
increasing,
caseSensitive,
removeDuplicated,
sortingMethod
} = optionsValues;

setResult(
Sort(
sortingMethod,
splitSeparatorType,
input,
increasing,
splitSeparator,
joinSeparator,
removeDuplicated,
caseSensitive
)
);
};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});

return (
<Box>
<ToolInputAndResult
input={
<ToolTextInput
title={'Input list'}
value={input}
onChange={setInput}
/>
}
result={<ToolTextResult title={'Sorted list'} value={result} />}
/>
<ToolOptions
compute={computeExternal}
getGroups={({ values, setFieldValue, handleChange }) => [
{
title: 'Input item separator',
component: splitOperators.map(({ title, description, type }) => (
<SimpleRadio
key={type}
onClick={() => setFieldValue('splitSeparatorType', type)}
title={title}
description={description}
checked={values.splitSeparatorType === type}
/>
))
},
{
title: 'Sort method',
component: <Box></Box>
}
]}
initialValues={initialValues}
input={input}
validationSchema={validationSchema}
/>
</Box>
);
}
5 changes: 3 additions & 2 deletions src/pages/list/sort/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export const tool = defineTool('list', {
name: 'Sort',
path: 'sort',
// image,
description: '',
shortDescription: '',
description:
'This is a super simple browser-based application that sorts items in a list and arranges them in increasing or decreasing order. You can sort the items alphabetically, numerically, or by their length. You can also remove duplicate and empty items, as well as trim individual items that have whitespace around them. You can use any separator character to separate the input list items or alternatively use a regular expression to separate them. Additionally, you can create a new delimiter for the sorted output list.',
shortDescription: 'Quickly sort a list',
keywords: ['sort'],
component: lazy(() => import('./index'))
});
11 changes: 4 additions & 7 deletions src/pages/number/sum/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function SplitText() {
withTextField ? (
<RadioWithTextField
key={type}
radioValue={type}
checked={type === values.extractionType}
title={title}
fieldName={'extractionType'}
description={description}
Expand All @@ -76,9 +76,7 @@ export default function SplitText() {
? values[textValueAccessor].toString()
: ''
}
onRadioChange={(type) =>
setFieldValue('extractionType', type)
}
onRadioClick={() => setFieldValue('extractionType', type)}
onTextChange={(val) =>
textValueAccessor
? setFieldValue(textValueAccessor, val)
Expand All @@ -88,9 +86,8 @@ export default function SplitText() {
) : (
<SimpleRadio
key={title}
onChange={() => setFieldValue('extractionType', type)}
fieldName={'extractionType'}
value={values.extractionType}
onClick={() => setFieldValue('extractionType', type)}
checked={values.extractionType === type}
description={description}
title={title}
/>
Expand Down
Loading

0 comments on commit a6eb5d5

Please sign in to comment.