@@ -16,31 +16,159 @@ export interface ScanResult {
1616 [ key : string ] : string ;
1717}
1818
19+ // const Home = () => {
20+ // const { send } = useAppBridge();
21+ // const { receive } = useWebBridge();
22+
23+ // const { scanData, setScanData } = useScanDataStore();
24+
25+ // const { navigateToReceiptEdit } = useRoute();
26+
27+ // // receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
28+
29+ // useEffect(() => {
30+ // // receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
31+ // // window.response = {
32+ // // receiveScanResult: (jsonData: string) => {
33+ // // try {
34+ // // const data: ScanResult[] = JSON.parse(jsonData);
35+ // // setAbc(true);
36+ // // setScanData(data);
37+ // // // navigateToReceiptEdit();
38+ // // } catch (error) {
39+ // // console.error("Error parsing scan result JSON:", error);
40+ // // }
41+ // // },
42+ // // };
43+ // }, []);
44+
45+ // return (
46+ // <div className={styles.Home}>
47+ // <div className={styles.HomeTitle}>
48+ // <Text variant="titleLg" color="gradient" align="center" as="h1">
49+ // {`영수증으로\nAI 음식 리뷰 남겨요`}
50+ // </Text>
51+ // <Text variant="bodyLg" color="secondary" align="center">
52+ // {scanData.length > 0 &&
53+ // scanData.map((data) => (
54+ // <>
55+ // {Object.keys(data).map((key) => (
56+ // <div key={key}>
57+ // <Text variant="bodyXsm" color="secondary">
58+ // {key}
59+ // </Text>
60+ // <Text variant="bodyXsm" color="secondary">
61+ // {data[key]}
62+ // </Text>
63+ // </div>
64+ // ))}
65+ // </>
66+ // ))}
67+ // 손쉬운 음식 리뷰 작성
68+ // </Text>
69+ // </div>
70+ // <div className={styles.HomeImage}>
71+ // <img src="/assets/img/img-graphic-logo.png" alt="mainLogo" />
72+ // </div>
73+ // <div className={styles.HomeBottom}>
74+ // <IconButton
75+ // text="갤러리"
76+ // iconName="gallery"
77+ // onClick={() => send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" })}
78+ // />
79+ // <IconButton
80+ // text="카메라"
81+ // iconName="camera"
82+ // onClick={() => {
83+ // send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" });
84+
85+ // // 네이티브 데이터 수신 핸들러 등록
86+ // window.response = {
87+ // receiveScanResult: (jsonData: string) => {
88+ // try {
89+ // const data: ScanResult[] = JSON.parse(jsonData);
90+ // receive({
91+ // type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
92+ // payload: data,
93+ // });
94+
95+ // // 데이터 저장 및 페이지 이동
96+ // setScanData(data);
97+ // setTimeout(() => {
98+ // navigateToReceiptEdit();
99+ // }, 0);
100+ // // navigateToReceiptEdit();
101+ // } catch (error) {
102+ // console.error("Error parsing scan result JSON:", error);
103+ // }
104+ // },
105+ // };
106+ // }}
107+ // />
108+
109+ // {/* <button
110+ // onClick={() => {
111+ // receive({
112+ // type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
113+ // payload: [{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }],
114+ // });
115+ // // if (window.response) {
116+ // // window.response.receiveScanResult(
117+ // // JSON.stringify([{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }]),
118+ // // );
119+ // // }
120+ // }}
121+ // >
122+ // 테스트 데이터 전송
123+ // </button> */}
124+
125+ // <button
126+ // onClick={() => {
127+ // receive({
128+ // type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
129+ // payload: [{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }],
130+ // });
131+ // }}
132+ // >
133+ // 테스트
134+ // </button>
135+ // </div>
136+ // </div>
137+ // );
138+ // };
139+
140+ // export default Home;
141+
19142const Home = ( ) => {
20143 const { send } = useAppBridge ( ) ;
21144 const { receive } = useWebBridge ( ) ;
22-
23145 const { scanData, setScanData } = useScanDataStore ( ) ;
24-
25146 const { navigateToReceiptEdit } = useRoute ( ) ;
26147
27- // receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
28-
29148 useEffect ( ( ) => {
30149 // receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
31- // window.response = {
32- // receiveScanResult: (jsonData: string) => {
33- // try {
34- // const data: ScanResult[] = JSON.parse(jsonData);
35- // setAbc(true);
36- // setScanData(data);
37- // // navigateToReceiptEdit();
38- // } catch (error) {
39- // console.error("Error parsing scan result JSON:", error);
40- // }
41- // },
42- // };
43- } , [ ] ) ;
150+ if ( typeof window !== "undefined" && ! window . response ) {
151+ window . response = {
152+ receiveScanResult : ( jsonData : string ) => {
153+ try {
154+ const data : ScanResult [ ] = JSON . parse ( jsonData ) ;
155+ receive ( {
156+ type : WebBridgeMessageType . RECEIVE_SCAN_RESULT ,
157+ payload : data ,
158+ } ) ;
159+
160+ // 데이터 저장 및 페이지 이동
161+ setScanData ( data ) ;
162+ setTimeout ( ( ) => {
163+ navigateToReceiptEdit ( ) ;
164+ } , 0 ) ;
165+ } catch ( error ) {
166+ console . error ( "Error parsing scan result JSON:" , error ) ;
167+ }
168+ } ,
169+ } ;
170+ }
171+ } , [ receive , navigateToReceiptEdit , setScanData ] ) ;
44172
45173 return (
46174 < div className = { styles . Home } >
@@ -81,47 +209,31 @@ const Home = () => {
81209 iconName = "camera"
82210 onClick = { ( ) => {
83211 send ( { type : AppBridgeMessageType . OPEN_CAMERA , payload : "" } ) ;
212+ // 네이티브에서 데이터를 수신하는 핸들러 설정
213+ if ( typeof window !== "undefined" && ! window . response ) {
214+ window . response = {
215+ receiveScanResult : ( jsonData : string ) => {
216+ try {
217+ const data : ScanResult [ ] = JSON . parse ( jsonData ) ;
218+ receive ( {
219+ type : WebBridgeMessageType . RECEIVE_SCAN_RESULT ,
220+ payload : data ,
221+ } ) ;
84222
85- // 네이티브 데이터 수신 핸들러 등록
86- window . response = {
87- receiveScanResult : ( jsonData : string ) => {
88- try {
89- const data : ScanResult [ ] = JSON . parse ( jsonData ) ;
90- receive ( {
91- type : WebBridgeMessageType . RECEIVE_SCAN_RESULT ,
92- payload : data ,
93- } ) ;
94-
95- // 데이터 저장 및 페이지 이동
96- setScanData ( data ) ;
97- setTimeout ( ( ) => {
98- navigateToReceiptEdit ( ) ;
99- } , 0 ) ;
100- // navigateToReceiptEdit();
101- } catch ( error ) {
102- console . error ( "Error parsing scan result JSON:" , error ) ;
103- }
104- } ,
105- } ;
223+ // 데이터 저장 및 페이지 이동
224+ setScanData ( data ) ;
225+ setTimeout ( ( ) => {
226+ navigateToReceiptEdit ( ) ;
227+ } , 0 ) ;
228+ } catch ( error ) {
229+ console . error ( "Error parsing scan result JSON:" , error ) ;
230+ }
231+ } ,
232+ } ;
233+ }
106234 } }
107235 />
108-
109- { /* <button
110- onClick={() => {
111- receive({
112- type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
113- payload: [{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }],
114- });
115- // if (window.response) {
116- // window.response.receiveScanResult(
117- // JSON.stringify([{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }]),
118- // );
119- // }
120- }}
121- >
122- 테스트 데이터 전송
123- </button> */ }
124-
236+ { /* 테스트용 버튼 */ }
125237 < button
126238 onClick = { ( ) => {
127239 receive ( {
0 commit comments