From ebfa44ee6b75ed7f7a5a6d839ac774196dca9cce Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Wed, 22 Jan 2025 16:21:27 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8Cfix:=20floorPlan=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/GlobalDataProvider.js | 29 +++++++------- src/components/floor-plan/FloorPlan.jsx | 51 +++++++++++++------------ src/hooks/option/useCanvasSetting.js | 4 +- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/app/GlobalDataProvider.js b/src/app/GlobalDataProvider.js index c4441d2c..4f6eabca 100644 --- a/src/app/GlobalDataProvider.js +++ b/src/app/GlobalDataProvider.js @@ -1,9 +1,6 @@ 'use client' -import { correntObjectNoState } from '@/store/settingAtom' -import { usePathname, useSearchParams } from 'next/navigation' import { createContext, useEffect, useState } from 'react' -import { useSetRecoilState } from 'recoil' import { useLocalStorage } from 'usehooks-ts' // export const GlobalDataContext = createContext({ @@ -18,19 +15,19 @@ const GlobalDataProvider = ({ children }) => { // TODO: 임시 조치이며 개발 완료시 삭제 예정 -> 잊지말기... const [managementStateLoaded, setManagementStateLoaded] = useLocalStorage('managementStateLoaded', null) - const pathname = usePathname() - const setCorrentObjectNo = useSetRecoilState(correntObjectNoState) - const searchParams = useSearchParams() - const objectNo = searchParams.get('objectNo') - const pid = searchParams.get('pid') - useEffect(() => { - if (pathname === '/floor-plan') { - if (pid === undefined || pid === '' || pid === null || objectNo === undefined || objectNo === '' || objectNo === null) { - notFound() - } - setCorrentObjectNo(objectNo) - } - }, []) + // const pathname = usePathname() + // const setCorrentObjectNo = useSetRecoilState(correntObjectNoState) + // const searchParams = useSearchParams() + // const objectNo = searchParams.get('objectNo') + // const pid = searchParams.get('pid') + // useEffect(() => { + // if (pathname === '/floor-plan') { + // if (pid === undefined || pid === '' || pid === null || objectNo === undefined || objectNo === '' || objectNo === null) { + // notFound() + // } + // setCorrentObjectNo(objectNo) + // } + // }, [pathname]) useEffect(() => { if (managementState !== null) { diff --git a/src/components/floor-plan/FloorPlan.jsx b/src/components/floor-plan/FloorPlan.jsx index 8cd320f0..0c1e0ba6 100644 --- a/src/components/floor-plan/FloorPlan.jsx +++ b/src/components/floor-plan/FloorPlan.jsx @@ -7,44 +7,45 @@ import { useCanvasSetting } from '@/hooks/option/useCanvasSetting' import { usePopup } from '@/hooks/usePopup' import '@/styles/contents.scss' import { notFound, usePathname, useSearchParams } from 'next/navigation' -import { useSetRecoilState } from 'recoil' +import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil' import { correntObjectNoState } from '@/store/settingAtom' export default function FloorPlan({ children }) { - // const pathname = usePathname() - // const setCurrentObjectNo = useSetRecoilState(correntObjectNoState) - // const searchParams = useSearchParams() - // const objectNo = searchParams.get('objectNo') - // const pid = searchParams.get('pid') - // useEffect(() => { - // if (pathname === '/floor-plan') { - // if (pid === undefined || pid === '' || pid === null || objectNo === undefined || objectNo === '' || objectNo === null) { - // notFound() - // } - // setCurrentObjectNo(objectNo) - // } - // }, [pathname]) + const [correntObjectNo, setCurrentObjectNo] = useRecoilState(correntObjectNoState) + const searchParams = useSearchParams() + const objectNo = searchParams.get('objectNo') + const pid = searchParams.get('pid') const { closeAll } = usePopup() const { menuNumber, setMenuNumber } = useCanvasMenu() const { fetchSettings, fetchBasicSettings } = useCanvasSetting() + // URL 파라미터에서 objectNo 설정 + useEffect(() => { + if (!objectNo) { + notFound() + } + setCurrentObjectNo(objectNo) + }, [objectNo, setCurrentObjectNo]) + + // 설정 데이터 fetch + useEffect(() => { + if (!correntObjectNo) return // correntObjectNo가 없으면 실행하지 않음 + + setMenuNumber(1) + fetchSettings() + fetchBasicSettings() + + return () => { + closeAll() + } + }, [correntObjectNo]) + const modalProps = { menuNumber, setMenuNumber, } - useEffect(() => { - ///setCorrentObjectNo(floorPlanState.objectNo) - //console.log('FloorPlan objectNo ', floorPlanState.objectNo, correntObjectNo) - setMenuNumber(1) - fetchSettings() // Canvas 설정 정보 조회 - fetchBasicSettings() // 기본 설정 정보 조회 - return () => { - closeAll() - } - }, []) - return ( <>
diff --git a/src/hooks/option/useCanvasSetting.js b/src/hooks/option/useCanvasSetting.js index 056f3c64..b91d8991 100644 --- a/src/hooks/option/useCanvasSetting.js +++ b/src/hooks/option/useCanvasSetting.js @@ -301,7 +301,7 @@ export function useCanvasSetting() { // 기본설정(PlacementShapeSetting) 조회 및 초기화 const fetchBasicSettings = async () => { try { - await get({ url: `/api/canvas-management/canvas-basic-settings/by-object/${floorPlanState.objectNo}` }).then((res) => { + await get({ url: `/api/canvas-management/canvas-basic-settings/by-object/${correntObjectNo}` }).then((res) => { let roofsRow = {} let roofsArray = {} @@ -452,7 +452,7 @@ export function useCanvasSetting() { // CanvasSetting 조회 및 초기화 const fetchSettings = async () => { try { - const res = await get({ url: `/api/canvas-management/canvas-settings/by-object/${floorPlanState.objectNo}` }) + const res = await get({ url: `/api/canvas-management/canvas-settings/by-object/${correntObjectNo}` }) console.log('res', res) if (Object.keys(res).length > 0) {