fix: 캔버스 화면에서 벗어난 뒤 기존과 다른 plan으로 진입 시 이전 캔버스 데이터가 표출되는 현상 수정

This commit is contained in:
Daseul Kim 2025-02-08 17:46:58 +09:00
parent a614629b89
commit decec520c1
2 changed files with 27 additions and 12 deletions

View File

@ -34,7 +34,7 @@ export default function CanvasFrame() {
const currentMenu = useRecoilValue(currentMenuState)
const { floorPlanState } = useContext(FloorPlanContext)
const { contextMenu, handleClick } = useContextMenu()
const { plans, currentCanvasPlan } = usePlan()
const { plans, currentCanvasPlan, resetCanvasStatus } = usePlan()
const totalDisplay = useRecoilValue(totalDisplaySelector) //
const { setIsGlobalLoading } = useContext(QcastContext)
const resetModuleStatisticsState = useResetRecoilState(moduleStatisticsState)
@ -45,20 +45,21 @@ export default function CanvasFrame() {
const resetSelectedModelsState = useResetRecoilState(selectedModelsState)
const resetPcsCheckState = useResetRecoilState(pcsCheckState)
const { handleModuleSelectionTotal } = useCanvasPopupStatusController()
const loadCanvas = () => {
if (canvas) {
canvas?.clear() // .
if (currentCanvasPlan) {
const plan = plans.find((plan) => plan.id === currentCanvasPlan.id)
if (plan?.canvasStatus && floorPlanState.objectNo === currentCanvasPlan.objectNo) {
canvas?.loadFromJSON(JSON.parse(plan.canvasStatus), function () {
canvasLoadInit() //config
canvas?.renderAll() // .
})
}
if (!canvas) return
canvas?.clear() // .
if (currentCanvasPlan) {
const plan = plans.find((plan) => plan.id === currentCanvasPlan.id)
if (plan?.canvasStatus && floorPlanState.objectNo === currentCanvasPlan.objectNo) {
canvas?.loadFromJSON(JSON.parse(plan.canvasStatus), function () {
canvasLoadInit() //config
canvas?.renderAll() // .
})
}
gridInit()
}
gridInit()
}
useEffect(() => {
@ -69,6 +70,11 @@ export default function CanvasFrame() {
useEffect(() => {
setIsGlobalLoading(false)
return () => {
canvas?.clear()
resetCanvasStatus()
}
}, [])
const resetRecoilData = () => {

View File

@ -407,6 +407,14 @@ export function usePlan(params = {}) {
})
}
/**
* plan canvasStatus 초기화
*/
const resetCanvasStatus = () => {
setCurrentCanvasPlan((prev) => ({ ...prev, canvasStatus: null }))
setPlans((plans) => plans.map((plan) => ({ ...plan, canvasStatus: null })))
}
/**
* 현재 plan 이동 -> 새로운 링크로 이동
*/
@ -425,5 +433,6 @@ export function usePlan(params = {}) {
handleAddPlan,
handleDeletePlan,
loadCanvasPlanData,
resetCanvasStatus,
}
}