From 4d147e459f62688dceae4619c52447f0fac3c536 Mon Sep 17 00:00:00 2001 From: sikkzz Date: Sat, 15 Feb 2025 19:43:15 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20any=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Home/Home.tsx | 4 ++-- src/components/ReceiptEdit/ReceiptEdit.tsx | 5 +---- .../AppBridgeProvider/AppBridgeMessage.types.ts | 6 +++--- .../AppBridgeProvider/AppBridgeProvider.tsx | 1 - .../AppBridgeProvider/convertToNativeMessage.ts | 6 ++---- src/store/useScanDataStore.ts | 13 +++++-------- src/types/global.d.ts | 4 ++++ 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/components/Home/Home.tsx b/src/components/Home/Home.tsx index 0c97cd8..e786ada 100644 --- a/src/components/Home/Home.tsx +++ b/src/components/Home/Home.tsx @@ -46,7 +46,7 @@ const Home = () => { onClick={() => { send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" }); - send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData }); + send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: { result: "" } }); }} /> { onClick={() => { send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" }); - send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: scanData }); + send({ type: AppBridgeMessageType.RECEIVE_SCAN_RESULT, payload: { result: "" } }); }} /> diff --git a/src/components/ReceiptEdit/ReceiptEdit.tsx b/src/components/ReceiptEdit/ReceiptEdit.tsx index f9c29b7..773a78e 100644 --- a/src/components/ReceiptEdit/ReceiptEdit.tsx +++ b/src/components/ReceiptEdit/ReceiptEdit.tsx @@ -17,10 +17,7 @@ const ReceiptEdit = () => { const { setOcrText } = useCreateReviewStore(); - const [formData, setFormData] = useState<{ [key: string]: string }[]>([ - { test: "abc" }, - { test2: "aadsasf" }, - ]); + const [formData, setFormData] = useState<{ key: string; value: string }[]>([]); const [focusState, setFocusState] = useState<{ [key: string]: boolean }>({}); useEffect(() => { diff --git a/src/components/provider/AppBridgeProvider/AppBridgeMessage.types.ts b/src/components/provider/AppBridgeProvider/AppBridgeMessage.types.ts index 27353de..5eb4ec3 100644 --- a/src/components/provider/AppBridgeProvider/AppBridgeMessage.types.ts +++ b/src/components/provider/AppBridgeProvider/AppBridgeMessage.types.ts @@ -50,9 +50,9 @@ export interface CopyMessage { export interface ReceiveScanResultMessage { type: AppBridgeMessageType.RECEIVE_SCAN_RESULT; - // payload: Array<{ [key: string]: string }>; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - payload: any; + payload: { + result: string; + }; } export interface ReceiveGeneratedReviewMessage { diff --git a/src/components/provider/AppBridgeProvider/AppBridgeProvider.tsx b/src/components/provider/AppBridgeProvider/AppBridgeProvider.tsx index 6fdedea..859a1fd 100644 --- a/src/components/provider/AppBridgeProvider/AppBridgeProvider.tsx +++ b/src/components/provider/AppBridgeProvider/AppBridgeProvider.tsx @@ -44,7 +44,6 @@ export function AppBridgeProvider({ children }: AppBridgeProviderProps) { // eslint-disable-next-line @typescript-eslint/no-explicit-any receiveScanResult: (jsonData: any) => { try { - // alert("Scan Result: " + jsonData); setScanData(JSON.parse(jsonData)); } catch (error) { console.error("Invalid JSON data for scan result:", error); diff --git a/src/components/provider/AppBridgeProvider/convertToNativeMessage.ts b/src/components/provider/AppBridgeProvider/convertToNativeMessage.ts index 5ea1809..4e52cd7 100644 --- a/src/components/provider/AppBridgeProvider/convertToNativeMessage.ts +++ b/src/components/provider/AppBridgeProvider/convertToNativeMessage.ts @@ -13,8 +13,7 @@ const iosHandlers = { }) => window.webkit?.messageHandlers.createReview.postMessage(message.payload), [AppBridgeMessageType.COPY]: (message: { payload: { review: string } }) => window.webkit?.messageHandlers.copy.postMessage(message.payload), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [AppBridgeMessageType.RECEIVE_SCAN_RESULT]: (message: { payload: { result: any } }) => + [AppBridgeMessageType.RECEIVE_SCAN_RESULT]: (message: { payload: { result: string } }) => window.response?.receiveScanResult(message.payload.result), [AppBridgeMessageType.RECEIVE_GENERATED_REVIEW]: (message: { payload: { result: string } }) => window.response?.receiveGeneratedReview(message.payload.result), @@ -29,8 +28,7 @@ const androidHandlers = { }) => window.AndroidBridge?.createReview(JSON.stringify(message.payload)), [AppBridgeMessageType.COPY]: (message: { payload: { review: string } }) => window.AndroidBridge?.copy(JSON.stringify(message.payload)), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [AppBridgeMessageType.RECEIVE_SCAN_RESULT]: (message: { payload: { result: any } }) => + [AppBridgeMessageType.RECEIVE_SCAN_RESULT]: (message: { payload: { result: string } }) => window.response?.receiveScanResult(message.payload.result), [AppBridgeMessageType.RECEIVE_GENERATED_REVIEW]: (message: { payload: { result: string } }) => window.response?.receiveGeneratedReview(message.payload.result), diff --git a/src/store/useScanDataStore.ts b/src/store/useScanDataStore.ts index 82c2dbb..19d4baa 100644 --- a/src/store/useScanDataStore.ts +++ b/src/store/useScanDataStore.ts @@ -1,16 +1,13 @@ import { create } from "zustand"; interface ScanDataStoreProps { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - scanData: any; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - setScanData: (scanData: any[]) => void; + scanData: ScanResultPayload; + setScanData: (scanData: ScanResultPayload) => void; resetScanData: () => void; } export const useScanDataStore = create((set) => ({ - scanData: [], - // eslint-disable-next-line @typescript-eslint/no-explicit-any - setScanData: (scanData: any[]) => set({ scanData }), - resetScanData: () => set({ scanData: [] }), + scanData: { parsed: [] }, + setScanData: (scanData: ScanResultPayload) => set({ scanData }), + resetScanData: () => set({ scanData: { parsed: [] } }), })); diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 58a5550..6f160c2 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -19,6 +19,10 @@ declare global { interface CopyMessagePayload { review: string; } + + interface ScanResultPayload { + parsed: Array<{ key: string; value: string }>; + } interface Window { response?: { // eslint-disable-next-line @typescript-eslint/no-explicit-any