Skip to content

Commit

Permalink
[feat/#58] 가이드 팝업 메시지 뜨는 방식에 상황에 따라 다르게 표시되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
G-hoon committed Sep 27, 2024
1 parent 8ee704e commit 93ce1e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/components/PoseDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { duration } from "@/api/notification"
import { poseType } from "@/api/pose"
import { useCameraPermission } from "@/hooks/useCameraPermission"
import { useGuidePopup } from "@/hooks/useGuidePopup"
import { useModals } from "@/hooks/useModals"
import useNotification from "@/hooks/useNotification"
import { useSendPose } from "@/hooks/usePoseMutation"
import usePushNotification from "@/hooks/usePushNotification"
import { useCreateSnaphot } from "@/hooks/useSnapshotMutation"
Expand All @@ -14,10 +16,10 @@ import { worker } from "@/utils/worker"
import { useCallback, useEffect, useRef, useState } from "react"
import { useLocation } from "react-router-dom"
import Camera from "./Camera"
import { modals } from "./Modal/Modals"
import Controls from "./Posture/Controls"
import GuidePopupModal from "./Posture/GuidePopup/GuidePopupModal"
import PostureMessage from "./Posture/PostureMessage"
import useNotification from "@/hooks/useNotification"

const PoseDetector: React.FC = () => {
const [isScriptLoaded, setIsScriptLoaded] = useState<boolean>(false)
Expand All @@ -31,7 +33,9 @@ const PoseDetector: React.FC = () => {

const { showNotification, hasPermission: hasNotiPermisson } = usePushNotification()

const { isPopupOpen, handleClosePopup, openPopup } = useGuidePopup()
const { isPopupOpen, handleClosePopup } = useGuidePopup()

const { openModal, isModalOpen } = useModals()

const modelRef = useRef<any>(null)
const snapRef = useRef<pose[] | null>(null)
Expand All @@ -55,7 +59,6 @@ const PoseDetector: React.FC = () => {

// const userNoti = useNotificationStore((state) => state.notification)
const { notification } = useNotification()

const { hasPermission } = useCameraPermission()

const location = useLocation() // 페이지 이동 감지
Expand Down Expand Up @@ -325,12 +328,14 @@ const PoseDetector: React.FC = () => {

// 팝업 열기
const handleShowPopup = (): void => {
openPopup()
// openPopup()
openModal(modals.postureGuideModal, {})
}

useEffect(() => {
console.log(notification)
}, [notification])

return (
<>
{isScriptError ? (
Expand All @@ -342,7 +347,7 @@ const PoseDetector: React.FC = () => {
<Camera detectStart={detectStart} canvasRef={canvasRef} />
{isModelLoaded && (
<>
{!isPopupOpen && (
{!isPopupOpen && !isModalOpen && (
<PostureMessage
isSnapShotSaved={isSnapShotSaved}
isShoulderTwist={isShoulderTwist}
Expand All @@ -357,7 +362,7 @@ const PoseDetector: React.FC = () => {
)}
</>
)}
{isPopupOpen && <GuidePopupModal onClose={handleClosePopup} />}
{!isSnapShotSaved && isPopupOpen && <GuidePopupModal onClose={handleClosePopup} />}
</div>
)}
</>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Posture/PostrueCrew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ export default function PostrueCrew(props: PostureCrewProps): ReactElement {
resetSnapShot()
}

console.log("notification: ", notification)

return (
<div className="flex h-full flex-col rounded-lg bg-[#FAFAFA] p-4">
<button onClick={onClickCloseSideNavButton} className="mb-8 p-1">
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/useModals.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { ModalComponent, ModalProps, ModalsDispatchContext } from "@/contexts/ModalsContext"
import { ModalComponent, ModalProps, ModalsDispatchContext, ModalsStateContext } from "@/contexts/ModalsContext"
import { useContext } from "react"

interface UseModalResult {
openModal: (Component: ModalComponent, props: ModalProps) => void
closeModal: (Component: ModalComponent) => void
isModalOpen: boolean
}

export const useModals = (): UseModalResult => {
const { open, close } = useContext(ModalsDispatchContext)
const modalsState = useContext(ModalsStateContext)

const openModal = (Component: ModalComponent, props: ModalProps): void => {
open(Component, props)
Expand All @@ -17,8 +19,11 @@ export const useModals = (): UseModalResult => {
close(Component)
}

const isModalOpen = modalsState.length > 0

return {
openModal,
closeModal,
isModalOpen,
}
}
2 changes: 0 additions & 2 deletions src/pages/AnalysisDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const AnalysisDashboard = () => {
return () => window.removeEventListener("resize", checkViewportSize)
}, [])

console.log("totalAnalysis: ", dateRange)

const getPoseCount = (type: poseType) => {
return todayAnalysis?.count.find((item: any) => item.type === type)?.count || 0
}
Expand Down

0 comments on commit 93ce1e4

Please sign in to comment.