📌fix: floorPlan 리팩토링
This commit is contained in:
parent
dd45849c75
commit
ebfa44ee6b
@ -1,9 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { correntObjectNoState } from '@/store/settingAtom'
|
|
||||||
import { usePathname, useSearchParams } from 'next/navigation'
|
|
||||||
import { createContext, useEffect, useState } from 'react'
|
import { createContext, useEffect, useState } from 'react'
|
||||||
import { useSetRecoilState } from 'recoil'
|
|
||||||
import { useLocalStorage } from 'usehooks-ts'
|
import { useLocalStorage } from 'usehooks-ts'
|
||||||
|
|
||||||
// export const GlobalDataContext = createContext({
|
// export const GlobalDataContext = createContext({
|
||||||
@ -18,19 +15,19 @@ const GlobalDataProvider = ({ children }) => {
|
|||||||
// TODO: 임시 조치이며 개발 완료시 삭제 예정 -> 잊지말기...
|
// TODO: 임시 조치이며 개발 완료시 삭제 예정 -> 잊지말기...
|
||||||
const [managementStateLoaded, setManagementStateLoaded] = useLocalStorage('managementStateLoaded', null)
|
const [managementStateLoaded, setManagementStateLoaded] = useLocalStorage('managementStateLoaded', null)
|
||||||
|
|
||||||
const pathname = usePathname()
|
// const pathname = usePathname()
|
||||||
const setCorrentObjectNo = useSetRecoilState(correntObjectNoState)
|
// const setCorrentObjectNo = useSetRecoilState(correntObjectNoState)
|
||||||
const searchParams = useSearchParams()
|
// const searchParams = useSearchParams()
|
||||||
const objectNo = searchParams.get('objectNo')
|
// const objectNo = searchParams.get('objectNo')
|
||||||
const pid = searchParams.get('pid')
|
// const pid = searchParams.get('pid')
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (pathname === '/floor-plan') {
|
// if (pathname === '/floor-plan') {
|
||||||
if (pid === undefined || pid === '' || pid === null || objectNo === undefined || objectNo === '' || objectNo === null) {
|
// if (pid === undefined || pid === '' || pid === null || objectNo === undefined || objectNo === '' || objectNo === null) {
|
||||||
notFound()
|
// notFound()
|
||||||
}
|
// }
|
||||||
setCorrentObjectNo(objectNo)
|
// setCorrentObjectNo(objectNo)
|
||||||
}
|
// }
|
||||||
}, [])
|
// }, [pathname])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (managementState !== null) {
|
if (managementState !== null) {
|
||||||
|
|||||||
@ -7,44 +7,45 @@ import { useCanvasSetting } from '@/hooks/option/useCanvasSetting'
|
|||||||
import { usePopup } from '@/hooks/usePopup'
|
import { usePopup } from '@/hooks/usePopup'
|
||||||
import '@/styles/contents.scss'
|
import '@/styles/contents.scss'
|
||||||
import { notFound, usePathname, useSearchParams } from 'next/navigation'
|
import { notFound, usePathname, useSearchParams } from 'next/navigation'
|
||||||
import { useSetRecoilState } from 'recoil'
|
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'
|
||||||
import { correntObjectNoState } from '@/store/settingAtom'
|
import { correntObjectNoState } from '@/store/settingAtom'
|
||||||
|
|
||||||
export default function FloorPlan({ children }) {
|
export default function FloorPlan({ children }) {
|
||||||
// const pathname = usePathname()
|
const [correntObjectNo, setCurrentObjectNo] = useRecoilState(correntObjectNoState)
|
||||||
// const setCurrentObjectNo = useSetRecoilState(correntObjectNoState)
|
const searchParams = useSearchParams()
|
||||||
// const searchParams = useSearchParams()
|
const objectNo = searchParams.get('objectNo')
|
||||||
// const objectNo = searchParams.get('objectNo')
|
const pid = searchParams.get('pid')
|
||||||
// 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 { closeAll } = usePopup()
|
const { closeAll } = usePopup()
|
||||||
const { menuNumber, setMenuNumber } = useCanvasMenu()
|
const { menuNumber, setMenuNumber } = useCanvasMenu()
|
||||||
const { fetchSettings, fetchBasicSettings } = useCanvasSetting()
|
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 = {
|
const modalProps = {
|
||||||
menuNumber,
|
menuNumber,
|
||||||
setMenuNumber,
|
setMenuNumber,
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
///setCorrentObjectNo(floorPlanState.objectNo)
|
|
||||||
//console.log('FloorPlan objectNo ', floorPlanState.objectNo, correntObjectNo)
|
|
||||||
setMenuNumber(1)
|
|
||||||
fetchSettings() // Canvas 설정 정보 조회
|
|
||||||
fetchBasicSettings() // 기본 설정 정보 조회
|
|
||||||
return () => {
|
|
||||||
closeAll()
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="canvas-wrap">
|
<div className="canvas-wrap">
|
||||||
|
|||||||
@ -301,7 +301,7 @@ export function useCanvasSetting() {
|
|||||||
// 기본설정(PlacementShapeSetting) 조회 및 초기화
|
// 기본설정(PlacementShapeSetting) 조회 및 초기화
|
||||||
const fetchBasicSettings = async () => {
|
const fetchBasicSettings = async () => {
|
||||||
try {
|
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 roofsRow = {}
|
||||||
let roofsArray = {}
|
let roofsArray = {}
|
||||||
|
|
||||||
@ -452,7 +452,7 @@ export function useCanvasSetting() {
|
|||||||
// CanvasSetting 조회 및 초기화
|
// CanvasSetting 조회 및 초기화
|
||||||
const fetchSettings = async () => {
|
const fetchSettings = async () => {
|
||||||
try {
|
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)
|
console.log('res', res)
|
||||||
|
|
||||||
if (Object.keys(res).length > 0) {
|
if (Object.keys(res).length > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user