Make more Simple

This commit is contained in:
mickr777
2023-07-29 12:40:17 +10:00
committed by GitHub
parent 36455f6cac
commit 6886eb094d

View File

@ -1,24 +1,17 @@
import { memo, ChangeEvent } from 'react'; import { Input, Textarea } from '@chakra-ui/react';
import { Textarea, Input } from '@chakra-ui/react';
import { useAppDispatch } from 'app/store/storeHooks'; import { useAppDispatch } from 'app/store/storeHooks';
import { fieldValueChanged } from 'features/nodes/store/nodesSlice'; import { fieldValueChanged } from 'features/nodes/store/nodesSlice';
import { import {
StringInputFieldTemplate, StringInputFieldTemplate,
StringInputFieldValue, StringInputFieldValue,
} from 'features/nodes/types/types'; } from 'features/nodes/types/types';
import { ChangeEvent, memo } from 'react';
import { FieldComponentProps } from './types'; import { FieldComponentProps } from './types';
const FIELD_PADDING = 20;
const StringInputFieldComponent = ( const StringInputFieldComponent = (
props: FieldComponentProps< props: FieldComponentProps<StringInputFieldValue, StringInputFieldTemplate>
StringInputFieldValue,
StringInputFieldTemplate
> & {
nodeWidth: number;
}
) => { ) => {
const { nodeId, field, nodeWidth } = props; const { nodeId, field } = props;
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const handleValueChanged = ( const handleValueChanged = (
@ -33,30 +26,10 @@ const StringInputFieldComponent = (
); );
}; };
const textareaWidth = nodeWidth - FIELD_PADDING; return field.name.toLowerCase() === 'prompt' ? (
<Textarea onChange={handleValueChanged} value={field.value} rows={5} />
const textareaFieldNames = ['prompt', 'text'];
return (
<>
{textareaFieldNames.includes(field.name.toLowerCase()) ? (
<Textarea
style={{
height: '150px',
width: `${textareaWidth}px`,
overflowY: 'auto',
}}
onChange={handleValueChanged}
value={field.value}
/>
) : ( ) : (
<Input <Input onChange={handleValueChanged} value={field.value} />
style={{ width: `${textareaWidth}px` }}
onChange={handleValueChanged}
value={field.value}
/>
)}
</>
); );
}; };