From c56390050d7c6e87831e6b27fa0d02592e704160 Mon Sep 17 00:00:00 2001 From: Minhyeok Park Date: Tue, 12 Nov 2024 11:14:53 +0900 Subject: [PATCH] feat: add more transform trigger point --- src/TransformGridItem/index.tsx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/TransformGridItem/index.tsx b/src/TransformGridItem/index.tsx index 0e1db13..9e39f78 100644 --- a/src/TransformGridItem/index.tsx +++ b/src/TransformGridItem/index.tsx @@ -32,6 +32,14 @@ export const TransformGridItem: FC = ({ transform }) => { value: '' }) + const triggerTransform = async () => + await transform + .fn(value, options) + .then((result) => { + setResult(result) + return result + }) + useEffect(() => { setAlreadyClosed(closed) }, []) @@ -40,9 +48,7 @@ export const TransformGridItem: FC = ({ transform }) => { if (closed) return - transform - .fn(value, options) - .then(setResult.bind(this)) + triggerTransform() }, [value, options, closed]) useEffect(() => { @@ -54,6 +60,7 @@ export const TransformGridItem: FC = ({ transform }) => { if (previewDisabled) { setClosed(alreadyClosed) + triggerTransform() setPreviewDisabled(false) } }, [value]) @@ -107,17 +114,23 @@ export const TransformGridItem: FC = ({ transform }) => { setOptions(new Map(options)) } - const onForwardButtonPressed = () => { + const onForwardButtonPressed = async () => { + const result = + await triggerTransform() + if (result.error) return setValue(result.value) } - const onLabelClicked = () => { + const onLabelClicked = async () => { if (previewDisabled) return + if (closed) + triggerTransform() + setClosed(!closed) setAlreadyClosed(!closed) }