feat: auto-close preview screen when input value is longer than 30000 chars
All checks were successful
/ deploy_site (push) Successful in 4m44s

This commit is contained in:
Minhyeok Park 2024-11-12 10:50:42 +09:00
parent b843facac6
commit ba76193d33
Signed by: pmh_only
SSH Key Fingerprint: SHA256:g/OyGvi2pcd8ub9mqge/ohmDP0fZX/xOPWPIcM+9XpI
2 changed files with 34 additions and 6 deletions

View File

@ -24,17 +24,37 @@ interface TransformGridItemProp {
export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => { export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
const [value, setValue] = useRecoilState(EditorValueState) const [value, setValue] = useRecoilState(EditorValueState)
const [options, setOptions] = useState(transform.options) const [options, setOptions] = useState(transform.options)
const [previewDisabled, setPreviewDisabled] = useState(false)
const [alreadyClosed, setAlreadyClosed] = useState(false)
const [closed, setClosed] = useLocalStorage(`transform_closed__${transform.name}`, false) const [closed, setClosed] = useLocalStorage(`transform_closed__${transform.name}`, false)
const [result, setResult] = useState<WrappedTransformResult>({ const [result, setResult] = useState<WrappedTransformResult>({
error: false, error: false,
value: '' value: ''
}) })
useEffect(() => {
setAlreadyClosed(closed)
}, [])
useEffect(() => { useEffect(() => {
if (closed)
return
transform transform
.fn(value, options) .fn(value, options)
.then(setResult.bind(this)) .then(setResult.bind(this))
}, [value, options]) }, [value, options, closed])
useEffect(() => {
if (value.length > 30000) {
setClosed(true)
setPreviewDisabled(true)
return
}
setClosed(alreadyClosed)
setPreviewDisabled(false)
}, [value])
const onCheckboxOptionChanged = const onCheckboxOptionChanged =
(option: TransformCheckboxOption) => (option: TransformCheckboxOption) =>
@ -92,6 +112,14 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
setValue(result.value) setValue(result.value)
} }
const onLabelClicked = () => {
if (previewDisabled)
return
setClosed(!closed)
setAlreadyClosed(!closed)
}
return ( return (
<div className={clsx(style.item, closed && style.closed)}> <div className={clsx(style.item, closed && style.closed)}>
<div className={style.toolbar}> <div className={style.toolbar}>
@ -100,8 +128,8 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
</Button> </Button>
<h2 <h2
onClick={() => setClosed(!closed)} onClick={onLabelClicked}
className={style.name}> className={clsx(style.name, previewDisabled && style.previewDisabled)}>
{transform.name} {transform.name}
</h2> </h2>

View File

@ -16,9 +16,9 @@
.name { .name {
font-size: inherit; font-size: inherit;
padding: 14px 6px; padding: 14px 6px;
cursor: pointer;
&:hover:not(.previewDisabled) {
&:hover { cursor: pointer;
text-decoration: underline dotted; text-decoration: underline dotted;
} }
} }