From bfeba67088d9faf400b260889ee7ecc250c5e8f4 Mon Sep 17 00:00:00 2001 From: Daseul Kim Date: Mon, 25 Nov 2024 14:56:12 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20CanvasLayout=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8=20=EB=82=B4=20objNo=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20plan=EC=97=90=20=ED=8F=AC=EC=BB=A4?= =?UTF-8?q?=EC=8B=B1=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/floor-plan/CanvasLayout.jsx | 7 ++++--- src/hooks/usePlan.js | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/floor-plan/CanvasLayout.jsx b/src/components/floor-plan/CanvasLayout.jsx index 1604a28f..1e69ec40 100644 --- a/src/components/floor-plan/CanvasLayout.jsx +++ b/src/components/floor-plan/CanvasLayout.jsx @@ -2,7 +2,7 @@ import { useContext, useEffect, useState } from 'react' import { useRecoilValue } from 'recoil' -import CanvasFrame from './CanvasFrame' +import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider' import { useMessage } from '@/hooks/useMessage' import { useSwal } from '@/hooks/useSwal' import { usePlan } from '@/hooks/usePlan' @@ -14,7 +14,8 @@ export default function CanvasLayout({ children }) { // const { menuNumber } = props const { menuNumber } = useCanvasMenu() const { session } = useContext(SessionContext) - const [objectNo, setObjectNo] = useState('test123240822001') // 이후 삭제 필요 + const { floorPlanState } = useContext(FloorPlanContext) + const { objectNo, pid } = floorPlanState const globalLocaleState = useRecoilValue(globalLocaleStore) const { getMessage } = useMessage() @@ -22,7 +23,7 @@ export default function CanvasLayout({ children }) { const { plans, modifiedPlans, loadCanvasPlanData, handleCurrentPlan, handleAddPlan, handleDeletePlan } = usePlan() useEffect(() => { - loadCanvasPlanData(session.userId, objectNo) + loadCanvasPlanData(session.userId, objectNo, pid) }, []) return ( diff --git a/src/hooks/usePlan.js b/src/hooks/usePlan.js index b0ed47d6..946cc628 100644 --- a/src/hooks/usePlan.js +++ b/src/hooks/usePlan.js @@ -23,6 +23,9 @@ export function usePlan() { const { getMessage } = useMessage() 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) => res.map((item) => ({ id: item.id, - name: item.objectNo + '-' + item.id, // tab button에 표출될 이름 (임시) + name: planLabel + item.id, userId: item.userId, canvasStatus: dbToCanvasFormat(item.canvasStatus), isCurrent: false, @@ -213,7 +216,7 @@ export function usePlan() { ? { ...plan, id: res.data, - name: currentCanvasPlan.objectNo + '-' + res.data, + name: planLabel + res.data, canvasStatus: canvasStatus, } : plan, @@ -318,7 +321,7 @@ export function usePlan() { const id = uuidv4() const newPlan = { id: id, - name: `Plan ${planNum + 1}`, + name: newPlanLabel + `${planNum + 1}`, objectNo: objectNo, userId: userId, canvasStatus: canvasStatus, @@ -364,14 +367,13 @@ export function usePlan() { /** * plan 조회 */ - const loadCanvasPlanData = (userId, objectNo) => { + const loadCanvasPlanData = (userId, objectNo, pid) => { getCanvasByObjectNo(userId, objectNo).then((res) => { // console.log('canvas 목록 ', res) if (res.length > 0) { setInitCanvasPlans(res) setPlans(res) - updateCurrentPlan(res.at(-1).id) // last 데이터에 포커싱 - setPlanNum(res.length) + updateCurrentPlan(Number(pid)) // last 데이터에 포커싱 } else { addPlan(userId, objectNo) }