@@ -29,7 +29,7 @@ const PoseDetector: React.FC = () => {
29
29
const [ isModelLoaded , setIsModelLoaded ] = useState < boolean > ( false )
30
30
// const [isSnapShotSaved, setIsSnapSaved] = useState<boolean>(false)
31
31
32
- const { showNotification } = usePushNotification ( )
32
+ const { showNotification, hasPermission : hasNotiPermisson } = usePushNotification ( )
33
33
34
34
const { isPopupOpen, handleClosePopup, openPopup } = useGuidePopup ( )
35
35
@@ -46,7 +46,7 @@ const PoseDetector: React.FC = () => {
46
46
const shoulderTwistCnt = useRef < number > ( 0 )
47
47
const chinUtpCnt = useRef < number > ( 0 )
48
48
const tailboneSitCnt = useRef < number > ( 0 )
49
-
49
+ const isShowImmediNotiRef = useRef < boolean > ( false )
50
50
const canvasRef = useRef < HTMLCanvasElement > ( null )
51
51
52
52
const { isSnapShotSaved, snapshot, setSnapShot } = useSnapShotStore ( )
@@ -56,7 +56,6 @@ const PoseDetector: React.FC = () => {
56
56
// const userNoti = useNotificationStore((state) => state.notification)
57
57
const { notification } = useNotification ( )
58
58
59
- const { requestNotificationPermission } = usePushNotification ( )
60
59
const { hasPermission } = useCameraPermission ( )
61
60
62
61
const location = useLocation ( ) // 페이지 이동 감지
@@ -119,8 +118,7 @@ const PoseDetector: React.FC = () => {
119
118
timerRef : React . MutableRefObject < any > ,
120
119
poseType : poseType ,
121
120
isSnapShotSaved : boolean ,
122
- cntRef : React . MutableRefObject < any > ,
123
- isShowNoti : boolean | undefined
121
+ cntRef : React . MutableRefObject < any >
124
122
) : void => {
125
123
if ( condition && isSnapShotSaved ) {
126
124
if ( ! timerRef . current ) {
@@ -130,7 +128,7 @@ const PoseDetector: React.FC = () => {
130
128
const req = { snapshot : { keypoints, score } , type : poseType }
131
129
sendPoseMutation . mutate ( req )
132
130
cntRef . current = cntRef . current + 1
133
- if ( isShowNoti )
131
+ if ( isShowImmediNotiRef . current )
134
132
showNotification ( `척추 건강 위험! ${ getPoseName ( poseType ) } 감지! 자세를 바르게 앉아주세요.` )
135
133
}
136
134
} , 30 * 1000 )
@@ -151,25 +149,17 @@ const PoseDetector: React.FC = () => {
151
149
const _isTextNeck = detectTextNeck ( snapRef . current , results , true , 0.88 )
152
150
const _isHandOnChin = detectHandOnChin ( snapRef . current , results )
153
151
const _isTailboneSit = detectTailboneSit ( snapRef . current , results )
154
- const _isShowNoti = notification ?. duration === "IMMEDIATELY" && notification ?. isActive
155
152
156
153
if ( _isShoulderTwist !== null ) setIsShoulderTwist ( _isShoulderTwist )
157
154
if ( _isTextNeck !== null ) setIsTextNeck ( _isTextNeck )
158
155
if ( _isHandOnChin !== null ) setIsHandOnChin ( _isHandOnChin )
159
156
if ( _isTailboneSit !== null ) setIsTailboneSit ( _isTailboneSit )
160
157
161
158
// 공통 타이머 관리 함수 호출
162
- managePoseTimer ( _isTextNeck , turtleNeckTimer , "TURTLE_NECK" , isSnapShotSaved , turtleNeckCnt , _isShowNoti )
163
- managePoseTimer (
164
- _isShoulderTwist ,
165
- shoulderTwistTimer ,
166
- "SHOULDER_TWIST" ,
167
- isSnapShotSaved ,
168
- shoulderTwistCnt ,
169
- _isShowNoti
170
- )
171
- managePoseTimer ( _isTailboneSit , tailboneSitTimer , "TAILBONE_SIT" , isSnapShotSaved , tailboneSitCnt , _isShowNoti )
172
- managePoseTimer ( _isHandOnChin , chinUtpTimer , "CHIN_UTP" , isSnapShotSaved , chinUtpCnt , _isShowNoti )
159
+ managePoseTimer ( _isTextNeck , turtleNeckTimer , "TURTLE_NECK" , isSnapShotSaved , turtleNeckCnt )
160
+ managePoseTimer ( _isShoulderTwist , shoulderTwistTimer , "SHOULDER_TWIST" , isSnapShotSaved , shoulderTwistCnt )
161
+ managePoseTimer ( _isTailboneSit , tailboneSitTimer , "TAILBONE_SIT" , isSnapShotSaved , tailboneSitCnt )
162
+ managePoseTimer ( _isHandOnChin , chinUtpTimer , "CHIN_UTP" , isSnapShotSaved , chinUtpCnt )
173
163
const isRight = ! _isTextNeck && ! _isHandOnChin && ! _isShoulderTwist && ! _isTailboneSit
174
164
if ( canvasRef . current ) drawPose ( results , canvasRef . current , isRight )
175
165
} else {
@@ -288,7 +278,6 @@ const PoseDetector: React.FC = () => {
288
278
} , [ location ] )
289
279
290
280
useEffect ( ( ) => {
291
- requestNotificationPermission ( )
292
281
getScript ( )
293
282
} , [ ] )
294
283
@@ -328,6 +317,12 @@ const PoseDetector: React.FC = () => {
328
317
}
329
318
} , [ notification , isSnapShotSaved ] )
330
319
320
+ // 즉시 알림을 사용 하는 경우, 푸시를 보낼지 여부를 저장
321
+ useEffect ( ( ) => {
322
+ isShowImmediNotiRef . current =
323
+ notification ?. duration === "IMMEDIATELY" && ( notification ?. isActive as boolean ) && hasNotiPermisson
324
+ } , [ notification ?. duration , notification ?. isActive , hasNotiPermisson ] )
325
+
331
326
// 팝업 열기
332
327
const handleShowPopup = ( ) : void => {
333
328
openPopup ( )
0 commit comments