From e7ef2e9a05d1cc1df5cf2f9442c1af4c53f729e3 Mon Sep 17 00:00:00 2001 From: "lkh14011424@gmail.com" Date: Tue, 10 Sep 2024 02:31:46 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#46]=20=EC=95=8C=EB=A6=BC=20=EB=AC=B8?= =?UTF-8?q?=EA=B5=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PoseDetector.tsx | 36 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/components/PoseDetector.tsx b/src/components/PoseDetector.tsx index e806802..f92ef5b 100644 --- a/src/components/PoseDetector.tsx +++ b/src/components/PoseDetector.tsx @@ -126,7 +126,7 @@ const PoseDetector: React.FC = () => { const req = { snapshot: { keypoints, score }, type: poseType } sendPoseMutation.mutate(req) cntRef.current = cntRef.current + 1 - if (isShowNoti) showNotification(`${getPoseName(poseType)} 감지! 자세를 바르게 앉아주세요.`) + if (isShowNoti) showNotification(`척추 건강 위험! ${getPoseName(poseType)} 감지! 자세를 바르게 앉아주세요.`) } }, 30 * 1000) } @@ -260,22 +260,17 @@ const PoseDetector: React.FC = () => { } } - const sendNotification = (minutes: number | null): void => { - const total = turtleNeckCnt.current + shoulderTwistCnt.current + chinUtpCnt.current + tailboneSitCnt.current - if (random) { - showNotification( - `지난 ${minutes}분 동안 총 ${total}회 감지! ${ - total > 0 ? "자세를 바르게 앉아주세요." : "좋은 자세를 유지해주세요." - }` - ) + const sendNotification = (): void => { + const message: string[] = [] + if (turtleNeckCnt.current > 0) message.push("거북목") + if (shoulderTwistCnt.current > 0) message.push("어깨 틀어짐") + if (chinUtpCnt.current > 0) message.push("턱 괴기") + if (tailboneSitCnt.current > 0) message.push("꼬리뼈로 앉기") + + if (message.length > 0) { + showNotification(`척추 건강 위험! ${message.join(", ")} 감지! 자세를 바르게 앉아주세요.`) } else { - showNotification( - `지난 ${minutes}분 동안 거북목 ${turtleNeckCnt.current}회, 어깨틀어짐 ${shoulderTwistCnt.current}회, 턱 괴기 ${ - chinUtpCnt.current - }회, 꼬리뼈 앉기 ${tailboneSitCnt.current}회 감지! ${ - total > 0 ? "자세를 바르게 앉아주세요." : "좋은 자세를 유지해주세요." - }` - ) + showNotification(`좋은 자세를 유지해주세요.`) } } @@ -291,11 +286,11 @@ const PoseDetector: React.FC = () => { }, []) useEffect(() => { - if (!isSnapSaved) { + if (!isSnapSaved || !hasPermission) { clearTimers() // 스냅샷이 저장되지 않았을 때 타이머들을 초기화 clearCnt() // 횟수도 초기화 } - }, [isSnapSaved]) + }, [isSnapSaved, hasPermission]) useEffect(() => { if (isModelLoaded && hasPermission) { @@ -320,7 +315,10 @@ const PoseDetector: React.FC = () => { if (userNoti.isActive && userNoti.duration && userNoti.duration !== "IMMEDIATELY") { const t = getDurationInMinutes(userNoti?.duration) notificationTimer.current = setInterval(() => { - if (userNoti.duration) sendNotification(t) + if (userNoti.duration) { + sendNotification() + clearCnt() + } }, 1000 * 60 * t) } }, [userNoti, isSnapSaved])