refactor: CanvasLayout 컴포넌트 내 objNo 수정, 특정 plan에 포커싱되도록 수정

This commit is contained in:
Daseul Kim 2024-11-25 14:56:12 +09:00
parent 1ba86c3369
commit bfeba67088
2 changed files with 12 additions and 9 deletions

View File

@ -2,7 +2,7 @@
import { useContext, useEffect, useState } from 'react' import { useContext, useEffect, useState } from 'react'
import { useRecoilValue } from 'recoil' import { useRecoilValue } from 'recoil'
import CanvasFrame from './CanvasFrame' import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider'
import { useMessage } from '@/hooks/useMessage' import { useMessage } from '@/hooks/useMessage'
import { useSwal } from '@/hooks/useSwal' import { useSwal } from '@/hooks/useSwal'
import { usePlan } from '@/hooks/usePlan' import { usePlan } from '@/hooks/usePlan'
@ -14,7 +14,8 @@ export default function CanvasLayout({ children }) {
// const { menuNumber } = props // const { menuNumber } = props
const { menuNumber } = useCanvasMenu() const { menuNumber } = useCanvasMenu()
const { session } = useContext(SessionContext) const { session } = useContext(SessionContext)
const [objectNo, setObjectNo] = useState('test123240822001') // const { floorPlanState } = useContext(FloorPlanContext)
const { objectNo, pid } = floorPlanState
const globalLocaleState = useRecoilValue(globalLocaleStore) const globalLocaleState = useRecoilValue(globalLocaleStore)
const { getMessage } = useMessage() const { getMessage } = useMessage()
@ -22,7 +23,7 @@ export default function CanvasLayout({ children }) {
const { plans, modifiedPlans, loadCanvasPlanData, handleCurrentPlan, handleAddPlan, handleDeletePlan } = usePlan() const { plans, modifiedPlans, loadCanvasPlanData, handleCurrentPlan, handleAddPlan, handleDeletePlan } = usePlan()
useEffect(() => { useEffect(() => {
loadCanvasPlanData(session.userId, objectNo) loadCanvasPlanData(session.userId, objectNo, pid)
}, []) }, [])
return ( return (

View File

@ -23,6 +23,9 @@ export function usePlan() {
const { getMessage } = useMessage() const { getMessage } = useMessage()
const { get, promisePost, promisePut, promiseDel } = useAxios() const { get, promisePost, promisePut, promiseDel } = useAxios()
const planLabel = 'Plan '
const newPlanLabel = 'New Plan '
/** /**
* 마우스 포인터의 가이드라인을 제거합니다. * 마우스 포인터의 가이드라인을 제거합니다.
*/ */
@ -184,7 +187,7 @@ export function usePlan() {
return get({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}/${userId}` }).then((res) => return get({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}/${userId}` }).then((res) =>
res.map((item) => ({ res.map((item) => ({
id: item.id, id: item.id,
name: item.objectNo + '-' + item.id, // tab button에 표출될 이름 (임시) name: planLabel + item.id,
userId: item.userId, userId: item.userId,
canvasStatus: dbToCanvasFormat(item.canvasStatus), canvasStatus: dbToCanvasFormat(item.canvasStatus),
isCurrent: false, isCurrent: false,
@ -213,7 +216,7 @@ export function usePlan() {
? { ? {
...plan, ...plan,
id: res.data, id: res.data,
name: currentCanvasPlan.objectNo + '-' + res.data, name: planLabel + res.data,
canvasStatus: canvasStatus, canvasStatus: canvasStatus,
} }
: plan, : plan,
@ -318,7 +321,7 @@ export function usePlan() {
const id = uuidv4() const id = uuidv4()
const newPlan = { const newPlan = {
id: id, id: id,
name: `Plan ${planNum + 1}`, name: newPlanLabel + `${planNum + 1}`,
objectNo: objectNo, objectNo: objectNo,
userId: userId, userId: userId,
canvasStatus: canvasStatus, canvasStatus: canvasStatus,
@ -364,14 +367,13 @@ export function usePlan() {
/** /**
* plan 조회 * plan 조회
*/ */
const loadCanvasPlanData = (userId, objectNo) => { const loadCanvasPlanData = (userId, objectNo, pid) => {
getCanvasByObjectNo(userId, objectNo).then((res) => { getCanvasByObjectNo(userId, objectNo).then((res) => {
// console.log('canvas 목록 ', res) // console.log('canvas 목록 ', res)
if (res.length > 0) { if (res.length > 0) {
setInitCanvasPlans(res) setInitCanvasPlans(res)
setPlans(res) setPlans(res)
updateCurrentPlan(res.at(-1).id) // last 데이터에 포커싱 updateCurrentPlan(Number(pid)) // last 데이터에 포커싱
setPlanNum(res.length)
} else { } else {
addPlan(userId, objectNo) addPlan(userId, objectNo)
} }