Skip to content

Commit 8d7f440

Browse files
committed
refactor: response 핸들러 type 오류 해결
1 parent dffd34b commit 8d7f440

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/components/Home/Home.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@ export interface ScanResult {
1616

1717
const Home = () => {
1818
const { send, receive } = useAppBridge();
19+
1920
const { setScanData } = useScanDataStore();
21+
2022
const { navigateToReceiptEdit } = useRoute();
2123

2224
const handleScanResult = (jsonData: string) => {
2325
try {
2426
const data: ScanResult[] = JSON.parse(jsonData);
27+
2528
receive({
2629
type: AppBridgeMessageType.RECEIVE_SCAN_RESULT,
2730
payload: data,
2831
});
32+
2933
setScanData(data);
34+
3035
navigateToReceiptEdit();
3136
} catch (error) {
3237
console.error("스캔 결과 JSON 파싱 오류:", error);
@@ -35,13 +40,12 @@ const Home = () => {
3540
};
3641

3742
useEffect(() => {
38-
if (typeof window !== "undefined" && !window.response) {
39-
window.response = {
40-
receiveScanResult: handleScanResult,
41-
receiveGeneratedReview: (jsonData: string) => {
42-
console.log("Generated review received:", jsonData);
43-
},
44-
};
43+
const responseHandler = {
44+
receiveScanResult: handleScanResult,
45+
};
46+
47+
if (typeof window !== "undefined") {
48+
window.response = Object.assign({}, window.response, responseHandler);
4549
}
4650

4751
return () => {
@@ -51,10 +55,6 @@ const Home = () => {
5155
};
5256
}, [receive, navigateToReceiptEdit, setScanData]);
5357

54-
const handleCameraClick = () => {
55-
send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" });
56-
};
57-
5858
return (
5959
<div className={styles.Home}>
6060
<div className={styles.HomeTitle}>
@@ -74,7 +74,11 @@ const Home = () => {
7474
iconName="gallery"
7575
onClick={() => send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" })}
7676
/>
77-
<IconButton text="카메라" iconName="camera" onClick={handleCameraClick} />
77+
<IconButton
78+
text="카메라"
79+
iconName="camera"
80+
onClick={() => send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" })}
81+
/>
7882
</div>
7983
</div>
8084
);

0 commit comments

Comments
 (0)