📌fix: plan 탭 링크 이동 로직 수정

- 탭 변경시 링크 이동 안되던 문제 해결
- 현재 plan 기준으로 로직 추가
This commit is contained in:
yoosangwook 2025-01-08 09:52:36 +09:00
parent 2980b07265
commit 3a89f8532f
2 changed files with 22 additions and 3 deletions

View File

@ -20,7 +20,7 @@ export default function CanvasLayout({ children }) {
const { getMessage } = useMessage()
const { swalFire } = useSwal()
const { plans, loadCanvasPlanData, handleCurrentPlan, handleAddPlan, handleDeletePlan } = usePlan()
const { plans, loadCanvasPlanData, handleCurrentPlan, handleAddPlan, handleDeletePlan } = usePlan({ objectNo })
useEffect(() => {
loadCanvasPlanData(session.userId, objectNo, pid)

View File

@ -1,15 +1,20 @@
'use client'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
import { useRecoilState } from 'recoil'
import { v4 as uuidv4 } from 'uuid'
import { canvasState, currentCanvasPlanState, plansState } from '@/store/canvasAtom'
import { useAxios } from '@/hooks/useAxios'
import { useMessage } from '@/hooks/useMessage'
import { useSwal } from '@/hooks/useSwal'
import { useCanvas } from '@/hooks/useCanvas'
import { SAVE_KEY } from '@/common/common'
import { readImage, removeImage } from '@/lib/fileAction'
import { useCanvas } from '@/hooks/useCanvas'
export function usePlan() {
export function usePlan(params = {}) {
const [planNum, setPlanNum] = useState(0)
const [selectedPlan, setSelectedPlan] = useState(null)
@ -18,6 +23,8 @@ export function usePlan() {
const [currentCanvasPlan, setCurrentCanvasPlan] = useRecoilState(currentCanvasPlanState)
const [plans, setPlans] = useRecoilState(plansState) // 전체 plan
const router = useRouter()
const { swalFire } = useSwal()
const { getMessage } = useMessage()
const { get, promisePost, promisePut, promiseDel } = useAxios()
@ -211,6 +218,11 @@ export function usePlan() {
// setBgImage()
}, [plans])
// 현재 plan이 변경될 때 마다 현재 plan의 링크로 이동
useEffect(() => {
handlePlanMove()
}, [currentCanvasPlan])
const setBgImage = () => {
// readImage(selectedPlan?.id)
}
@ -296,6 +308,13 @@ export function usePlan() {
})
}
/**
* 현재 plan 이동 -> 새로운 링크로 이동
*/
const handlePlanMove = () => {
router.push(`/floor-plan?objectNo=${params?.objectNo}&pid=${currentCanvasPlan?.ordering}`)
}
return {
canvas,
plans,