Skip to content

Commit

Permalink
[feat/#46] 알림 문구 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
lkhoony committed Sep 9, 2024
1 parent d772584 commit e7ef2e9
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/components/PoseDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(`좋은 자세를 유지해주세요.`)
}
}

Expand All @@ -291,11 +286,11 @@ const PoseDetector: React.FC = () => {
}, [])

useEffect(() => {
if (!isSnapSaved) {
if (!isSnapSaved || !hasPermission) {
clearTimers() // 스냅샷이 저장되지 않았을 때 타이머들을 초기화
clearCnt() // 횟수도 초기화
}
}, [isSnapSaved])
}, [isSnapSaved, hasPermission])

useEffect(() => {
if (isModelLoaded && hasPermission) {
Expand All @@ -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])
Expand Down

0 comments on commit e7ef2e9

Please sign in to comment.