diff --git a/src/hooks/usePlan.js b/src/hooks/usePlan.js index 2bb37a1e..04bb983f 100644 --- a/src/hooks/usePlan.js +++ b/src/hooks/usePlan.js @@ -3,7 +3,7 @@ import { useContext, useEffect, useState } from 'react' import { usePathname, useRouter, useSearchParams } from 'next/navigation' -import { useRecoilState } from 'recoil' +import { useRecoilState, useResetRecoilState } from 'recoil' import { canvasState, currentCanvasPlanState, plansState } from '@/store/canvasAtom' import { useAxios } from '@/hooks/useAxios' @@ -14,6 +14,8 @@ import { SAVE_KEY } from '@/common/common' import { readImage, removeImage } from '@/lib/fileAction' import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider' import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController' +import { outerLinePointsState } from '@/store/outerLineAtom' +import { placementShapeDrawingPointsState } from '@/store/placementShapeDrawingAtom' export function usePlan(params = {}) { const { floorPlanState } = useContext(FloorPlanContext) @@ -33,6 +35,10 @@ export function usePlan(params = {}) { const { get, promisePost, promisePut, promiseDel, promiseGet } = useAxios() const { setEstimateContextState } = useEstimateController() + + const resetOuterLinePoints = useResetRecoilState(outerLinePointsState) + const resetPlacementShapeDrawingPoints = useResetRecoilState(placementShapeDrawingPointsState) + /** * 마우스 포인터의 가이드라인을 제거합니다. */ @@ -284,6 +290,8 @@ export function usePlan(params = {}) { } else { if (!currentCanvasPlan || currentCanvasPlan.id !== newCurrentId) { await saveCanvas(true) + + clearRecoilState() } setCurrentCanvasPlan(plans.find((plan) => plan.id === newCurrentId)) setPlans((plans) => plans.map((plan) => ({ ...plan, isCurrent: plan.id === newCurrentId }))) @@ -296,6 +304,12 @@ export function usePlan(params = {}) { // setBgImage() }, [currentCanvasPlan]) + const clearRecoilState = () => { + //clear가 필요한 recoil state 관리 + resetOuterLinePoints() + resetPlacementShapeDrawingPoints() + } + const handleCurrentPlanUrl = () => { const currentPlan = plans.find((plan) => plan.isCurrent) // if (currentPlan) router.push(`${pathname}?pid=${currentPlan?.planNo}&objectNo=${floorPlanState?.objectNo}`)