diff --git a/src/components/Home/Home.tsx b/src/components/Home/Home.tsx index 8770f4e..f79d86e 100644 --- a/src/components/Home/Home.tsx +++ b/src/components/Home/Home.tsx @@ -15,45 +15,17 @@ export interface ScanResult { } const Home = () => { - const { send, receive } = useAppBridge(); + const { send } = useAppBridge(); - const { setScanData } = useScanDataStore(); + const { scanData } = useScanDataStore(); const { navigateToReceiptEdit } = useRoute(); - const handleScanResult = (jsonData: string) => { - try { - const data: ScanResult[] = JSON.parse(jsonData); - - receive({ - type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, - payload: data, - }); - - setScanData(data); - - navigateToReceiptEdit(); - } catch (error) { - console.error("스캔 결과 JSON 파싱 오류:", error); - alert("스캔 데이터를 처리하는 중 오류가 발생했습니다. 다시 시도해 주세요."); - } - }; - useEffect(() => { - const responseHandler = { - receiveScanResult: handleScanResult, - }; - - if (typeof window !== "undefined") { - window.response = Object.assign({}, window.response, responseHandler); + if (scanData.length > 0) { + navigateToReceiptEdit(); } - - return () => { - if (typeof window !== "undefined") { - delete window.response; - } - }; - }, [receive, navigateToReceiptEdit, setScanData]); + }, [scanData]); return (
@@ -72,12 +44,20 @@ const Home = () => { send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" })} + onClick={() => { + send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" }); + + send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData }); + }} /> send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" })} + onClick={() => { + send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" }); + + send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData }); + }} />
diff --git a/src/components/ReceiptEdit/ReceiptEdit.tsx b/src/components/ReceiptEdit/ReceiptEdit.tsx index cdef199..d7f863e 100644 --- a/src/components/ReceiptEdit/ReceiptEdit.tsx +++ b/src/components/ReceiptEdit/ReceiptEdit.tsx @@ -11,7 +11,7 @@ import { useCreateReviewStore } from "@/store/useReviewStore"; import { useScanDataStore } from "@/store/useScanDataStore"; const ReceiptEdit = () => { - const { navigateToSelectTag } = useRoute(); + const { navigateToHome, navigateToSelectTag } = useRoute(); const { scanData } = useScanDataStore(); @@ -114,7 +114,7 @@ const ReceiptEdit = () => { /> ) : ( <> -