📌fix: floorPlan 리팩토링
This commit is contained in:
parent
dd45849c75
commit
ebfa44ee6b
@ -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) {
|
||||
|
||||
@ -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 (
|
||||
<>
|
||||
<div className="canvas-wrap">
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user