Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 167 additions & 55 deletions src/components/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,159 @@ export interface ScanResult {
[key: string]: string;
}

// const Home = () => {
// const { send } = useAppBridge();
// const { receive } = useWebBridge();

// const { scanData, setScanData } = useScanDataStore();

// const { navigateToReceiptEdit } = useRoute();

// // receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });

// useEffect(() => {
// // receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
// // window.response = {
// // receiveScanResult: (jsonData: string) => {
// // try {
// // const data: ScanResult[] = JSON.parse(jsonData);
// // setAbc(true);
// // setScanData(data);
// // // navigateToReceiptEdit();
// // } catch (error) {
// // console.error("Error parsing scan result JSON:", error);
// // }
// // },
// // };
// }, []);

// return (
// <div className={styles.Home}>
// <div className={styles.HomeTitle}>
// <Text variant="titleLg" color="gradient" align="center" as="h1">
// {`영수증으로\nAI 음식 리뷰 남겨요`}
// </Text>
// <Text variant="bodyLg" color="secondary" align="center">
// {scanData.length > 0 &&
// scanData.map((data) => (
// <>
// {Object.keys(data).map((key) => (
// <div key={key}>
// <Text variant="bodyXsm" color="secondary">
// {key}
// </Text>
// <Text variant="bodyXsm" color="secondary">
// {data[key]}
// </Text>
// </div>
// ))}
// </>
// ))}
// 손쉬운 음식 리뷰 작성
// </Text>
// </div>
// <div className={styles.HomeImage}>
// <img src="/assets/img/img-graphic-logo.png" alt="mainLogo" />
// </div>
// <div className={styles.HomeBottom}>
// <IconButton
// text="갤러리"
// iconName="gallery"
// onClick={() => send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" })}
// />
// <IconButton
// text="카메라"
// iconName="camera"
// onClick={() => {
// send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" });

// // 네이티브 데이터 수신 핸들러 등록
// window.response = {
// receiveScanResult: (jsonData: string) => {
// try {
// const data: ScanResult[] = JSON.parse(jsonData);
// receive({
// type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
// payload: data,
// });

// // 데이터 저장 및 페이지 이동
// setScanData(data);
// setTimeout(() => {
// navigateToReceiptEdit();
// }, 0);
// // navigateToReceiptEdit();
// } catch (error) {
// console.error("Error parsing scan result JSON:", error);
// }
// },
// };
// }}
// />

// {/* <button
// onClick={() => {
// receive({
// type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
// payload: [{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }],
// });
// // if (window.response) {
// // window.response.receiveScanResult(
// // JSON.stringify([{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }]),
// // );
// // }
// }}
// >
// 테스트 데이터 전송
// </button> */}

// <button
// onClick={() => {
// receive({
// type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
// payload: [{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }],
// });
// }}
// >
// 테스트
// </button>
// </div>
// </div>
// );
// };

// export default Home;

const Home = () => {
const { send } = useAppBridge();
const { receive } = useWebBridge();

const { scanData, setScanData } = useScanDataStore();

const { navigateToReceiptEdit } = useRoute();

// receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });

useEffect(() => {
// receive({ type: WebBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
// window.response = {
// receiveScanResult: (jsonData: string) => {
// try {
// const data: ScanResult[] = JSON.parse(jsonData);
// setAbc(true);
// setScanData(data);
// // navigateToReceiptEdit();
// } catch (error) {
// console.error("Error parsing scan result JSON:", error);
// }
// },
// };
}, []);
if (typeof window !== "undefined" && !window.response) {
window.response = {
receiveScanResult: (jsonData: string) => {
try {
const data: ScanResult[] = JSON.parse(jsonData);
receive({
type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
payload: data,
});

// 데이터 저장 및 페이지 이동
setScanData(data);
setTimeout(() => {
navigateToReceiptEdit();
}, 0);
} catch (error) {
console.error("Error parsing scan result JSON:", error);
}
},
};
}
}, [receive, navigateToReceiptEdit, setScanData]);

return (
<div className={styles.Home}>
Expand Down Expand Up @@ -81,47 +209,31 @@ const Home = () => {
iconName="camera"
onClick={() => {
send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" });
// 네이티브에서 데이터를 수신하는 핸들러 설정
if (typeof window !== "undefined" && !window.response) {
window.response = {
receiveScanResult: (jsonData: string) => {
try {
const data: ScanResult[] = JSON.parse(jsonData);
receive({
type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
payload: data,
});

// 네이티브 데이터 수신 핸들러 등록
window.response = {
receiveScanResult: (jsonData: string) => {
try {
const data: ScanResult[] = JSON.parse(jsonData);
receive({
type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
payload: data,
});

// 데이터 저장 및 페이지 이동
setScanData(data);
setTimeout(() => {
navigateToReceiptEdit();
}, 0);
// navigateToReceiptEdit();
} catch (error) {
console.error("Error parsing scan result JSON:", error);
}
},
};
// 데이터 저장 및 페이지 이동
setScanData(data);
setTimeout(() => {
navigateToReceiptEdit();
}, 0);
} catch (error) {
console.error("Error parsing scan result JSON:", error);
}
},
};
}
}}
/>

{/* <button
onClick={() => {
receive({
type: WebBridgeMessageType.RECEIVE_SCAN_RESULT,
payload: [{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }],
});
// if (window.response) {
// window.response.receiveScanResult(
// JSON.stringify([{ sampleKey: "sampleValue" }, { sampleKey2: "sampleValue2" }]),
// );
// }
}}
>
테스트 데이터 전송
</button> */}

{/* 테스트용 버튼 */}
<button
onClick={() => {
receive({
Expand Down