Skip to content

Commit 45abc03

Browse files
committed
refactor: 영수증, 갤러리 ocr 인식 수정
1 parent 8d7f440 commit 45abc03

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

src/components/Home/Home.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,17 @@ export interface ScanResult {
1515
}
1616

1717
const Home = () => {
18-
const { send, receive } = useAppBridge();
18+
const { send } = useAppBridge();
1919

20-
const { setScanData } = useScanDataStore();
20+
const { scanData } = useScanDataStore();
2121

2222
const { navigateToReceiptEdit } = useRoute();
2323

24-
const handleScanResult = (jsonData: string) => {
25-
try {
26-
const data: ScanResult[] = JSON.parse(jsonData);
27-
28-
receive({
29-
type: AppBridgeMessageType.RECEIVE_SCAN_RESULT,
30-
payload: data,
31-
});
32-
33-
setScanData(data);
34-
35-
navigateToReceiptEdit();
36-
} catch (error) {
37-
console.error("스캔 결과 JSON 파싱 오류:", error);
38-
alert("스캔 데이터를 처리하는 중 오류가 발생했습니다. 다시 시도해 주세요.");
39-
}
40-
};
41-
4224
useEffect(() => {
43-
const responseHandler = {
44-
receiveScanResult: handleScanResult,
45-
};
46-
47-
if (typeof window !== "undefined") {
48-
window.response = Object.assign({}, window.response, responseHandler);
25+
if (scanData.length > 0) {
26+
navigateToReceiptEdit();
4927
}
50-
51-
return () => {
52-
if (typeof window !== "undefined") {
53-
delete window.response;
54-
}
55-
};
56-
}, [receive, navigateToReceiptEdit, setScanData]);
28+
}, [scanData]);
5729

5830
return (
5931
<div className={styles.Home}>
@@ -72,12 +44,20 @@ const Home = () => {
7244
<IconButton
7345
text="갤러리"
7446
iconName="gallery"
75-
onClick={() => send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" })}
47+
onClick={() => {
48+
send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" });
49+
50+
send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
51+
}}
7652
/>
7753
<IconButton
7854
text="카메라"
7955
iconName="camera"
80-
onClick={() => send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" })}
56+
onClick={() => {
57+
send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" });
58+
59+
send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData });
60+
}}
8161
/>
8262
</div>
8363
</div>

src/components/ReceiptEdit/ReceiptEdit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useCreateReviewStore } from "@/store/useReviewStore";
1111
import { useScanDataStore } from "@/store/useScanDataStore";
1212

1313
const ReceiptEdit = () => {
14-
const { navigateToSelectTag } = useRoute();
14+
const { navigateToHome, navigateToSelectTag } = useRoute();
1515

1616
const { scanData } = useScanDataStore();
1717

@@ -114,7 +114,7 @@ const ReceiptEdit = () => {
114114
/>
115115
) : (
116116
<>
117-
<Button text="다시 스캔하기" variant="secondary" />
117+
<Button text="다시 스캔하기" variant="secondary" onClick={navigateToHome} />
118118
<Button
119119
text="정보가 맞아요"
120120
disabled={formData.some((item) => Object.values(item).some((value) => !value))}

src/components/provider/AppBridgeProvider/AppBridgeProvider.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ interface AppBridgeProviderProps {
1616

1717
interface AppBridge {
1818
send: (message: AppBridgeMessage) => void;
19-
receive: (message: AppBridgeMessage) => void;
2019
}
2120

2221
export const AppBridgeContext = createContext<null | AppBridge>(null);
@@ -37,15 +36,6 @@ export function AppBridgeProvider({ children }: AppBridgeProviderProps) {
3736
}
3837
};
3938

40-
const receive = (message: AppBridgeMessage) => {
41-
try {
42-
if (isIOS) return convertToIOSAppBridge(message);
43-
return convertToAndroidAppBridge(message);
44-
} catch {
45-
alert("App Bridge API called: " + message.type);
46-
}
47-
};
48-
4939
useEffect(() => {
5040
if (typeof window !== "undefined") {
5141
window.response = {
@@ -69,9 +59,7 @@ export function AppBridgeProvider({ children }: AppBridgeProviderProps) {
6959
}
7060
}, []);
7161

72-
return (
73-
<AppBridgeContext.Provider value={{ send, receive }}>{children}</AppBridgeContext.Provider>
74-
);
62+
return <AppBridgeContext.Provider value={{ send }}>{children}</AppBridgeContext.Provider>;
7563
}
7664

7765
export function useAppBridge() {

0 commit comments

Comments
 (0)