From 4c439987e95d0bd704320e99f5bd092a6f975a32 Mon Sep 17 00:00:00 2001 From: judymoody59 Date: Wed, 4 Jun 2025 19:39:48 +0900 Subject: [PATCH 1/2] =?UTF-8?q?KW-594/fix:=20QR=20=EC=8A=A4=EC=BA=94=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EC=9D=B4=ED=83=88=20=EC=8B=9C=20=EC=B9=B4?= =?UTF-8?q?=EB=A9=94=EB=9D=BC=20=EC=A0=95=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 56 ++++++++++++++++++++++++++++++++++++- src/pages/QRCodeScanner.tsx | 19 ++----------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e8d1c8b..271776b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,13 +1,67 @@ -import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; +import { BrowserRouter as Router, Routes, Route, useLocation } from 'react-router-dom'; +import { useEffect } from 'react'; + import LoginSwitcher from './components/switcher/LoginSwitcher'; import BuildingSelectPage from './pages/BuildingSelectPage'; import ZoneSelectPage from './pages/ZoneSelectPage'; import QRCodeScanner from './pages/QRCodeScanner'; +function GlobalPopStateHandler() { + useEffect(() => { + const handlePopState = () => { + const currentPath = window.location.pathname; + console.log("[Global] popstate 발생:", currentPath); + + const scannerInstance = (window as any).scannerRef?.current; + if (scannerInstance?.clear) { + scannerInstance.clear() + .then(() => { + console.log("[Global] 카메라 정리 완료 (popstate)"); + }) + .catch(console.error) + .finally(() => { + (window as any).scannerRef = null; + }); + } else { + console.log("[Global] scannerRef가 없음 (이미 null?)"); + } + }; + + window.addEventListener("popstate", handlePopState); + return () => window.removeEventListener("popstate", handlePopState); + }, []); + + return null; +} + +function LocationWatcher() { + const location = useLocation(); + + useEffect(() => { + if (!location.pathname.startsWith('/qr')) { + const scannerInstance = (window as any).scannerRef?.current; + if (scannerInstance?.clear) { + scannerInstance.clear() + .then(() => { + console.log("[Global] 카메라 정리 완료 (location change)"); + }) + .catch(console.error) + .finally(() => { + (window as any).scannerRef = null; + }); + } + } + }, [location.pathname]); + + return null; +} + function App() { return ( + + } /> } /> diff --git a/src/pages/QRCodeScanner.tsx b/src/pages/QRCodeScanner.tsx index 0a6b37b..56e39c9 100644 --- a/src/pages/QRCodeScanner.tsx +++ b/src/pages/QRCodeScanner.tsx @@ -80,6 +80,9 @@ const QRCodeScanner = () => { } }; + scannerRef.current = scanner; + (window as any).scannerRef = scannerRef; + showMessage(STATUS_MESSAGES.SCANNING); scanner.render( @@ -118,22 +121,6 @@ const QRCodeScanner = () => { () => {} ); - scannerRef.current = scanner; - - return () => { - const instance = scannerRef.current; - if (instance && instance.qrCodeScanner) { - const html5QrInstance = instance.qrCodeScanner; - - html5QrInstance - .stop() - .then(() => html5QrInstance.clear()) - .catch(console.error) - .finally(() => { - scannerRef.current = null; - }); - } - }; }, []); useEffect(() => { From 108abaf552fe3dd454a29833d27e8354c9a5b24e Mon Sep 17 00:00:00 2001 From: judymoody59 Date: Wed, 4 Jun 2025 19:54:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?KW-594/fix:=20App.tsx=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index 271776b..d53332e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,7 +23,7 @@ function GlobalPopStateHandler() { (window as any).scannerRef = null; }); } else { - console.log("[Global] scannerRef가 없음 (이미 null?)"); + console.log("[Global] scannerRef가 없음"); } };