Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/#46] 알림 문구 수정 #52

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading