From c1f0697ca04806c9baa3d5b69c526a24607a0a3c Mon Sep 17 00:00:00 2001 From: pipisebastian Date: Thu, 5 Dec 2024 14:19:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=ED=95=A0=EB=95=8C=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EB=B2=97=EC=96=B4=EB=82=98=EA=B0=80=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=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 #255 --- .../workSpace/hooks/usePagesManage.ts | 61 +++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/client/src/features/workSpace/hooks/usePagesManage.ts b/client/src/features/workSpace/hooks/usePagesManage.ts index 07e1f28..9977da5 100644 --- a/client/src/features/workSpace/hooks/usePagesManage.ts +++ b/client/src/features/workSpace/hooks/usePagesManage.ts @@ -10,6 +10,7 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useSocketStore } from "@src/stores/useSocketStore"; import { useToastStore } from "@src/stores/useToastStore"; import { Page } from "@src/types/page"; +import { PAGE, SIDE_BAR } from "@src/constants/size"; const PAGE_OFFSET = 60; @@ -86,6 +87,42 @@ export const usePagesManage = (workspace: WorkSpace | null, clientId: number | n return Math.max(0, ...pages.map((page) => page.zIndex)) + 1; }; + const adjustPagePosition = (page: Page) => { + const PADDING = 20; + const maxWidth = window.innerWidth - SIDE_BAR.WIDTH - PADDING * 2; + const maxHeight = window.innerHeight - PADDING * 2; + + // 페이지가 최소 크기보다 작아지지 않도록 보장 + const width = PAGE.WIDTH; + const height = PAGE.HEIGHT; + + // 새로운 위치 계산 + let newX = page.x; + let newY = page.y; + + // 오른쪽 경계를 벗어나는 경우 + if (newX + width > maxWidth) { + newX = Math.max(0, maxWidth - width); + } + + // 왼쪽 경계를 벗어나는 경우 + if (newX < 0) { + newX = 0; + } + + // 아래쪽 경계를 벗어나는 경우 + if (newY + height > maxHeight) { + newY = Math.max(0, maxHeight - height); + } + + // 위쪽 경계를 벗어나는 경우 + if (newY < 0) { + newY = 0; + } + + return { x: newX, y: newY }; + }; + const fetchPage = () => { const operation = { type: "pageCreate", @@ -170,11 +207,25 @@ export const usePagesManage = (workspace: WorkSpace | null, clientId: number | n // 페이지를 활성화하고 표시 setPages((prevPages) => - prevPages.map((p) => - p.id === pageId - ? { ...p, isActive: true, isVisible: true, zIndex: getZIndex() } - : { ...p, isActive: false }, - ), + prevPages.map((p) => { + if (p.id === pageId) { + // isLoaded가 false일 때만 위치 재조정 + if (!p.isLoaded) { + const adjustedPosition = adjustPagePosition(p); + return { + ...p, + isActive: true, + isVisible: true, + zIndex: getZIndex(), + x: adjustedPosition.x, + y: adjustedPosition.y, + }; + } + // 이미 로드된 페이지는 위치 유지 + return { ...p, isActive: true, isVisible: true, zIndex: getZIndex() }; + } + return { ...p, isActive: false }; + }), ); setTimeout(() => { From 5fe0bd8aa35bece33f2c11b9c116499ccdea330b Mon Sep 17 00:00:00 2001 From: pipisebastian Date: Thu, 5 Dec 2024 14:22:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20dom=20nesting=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #298 --- .../components/sidebar/components/menuButton/MenuButton.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/components/sidebar/components/menuButton/MenuButton.tsx b/client/src/components/sidebar/components/menuButton/MenuButton.tsx index 5601b70..7b38834 100644 --- a/client/src/components/sidebar/components/menuButton/MenuButton.tsx +++ b/client/src/components/sidebar/components/menuButton/MenuButton.tsx @@ -111,7 +111,7 @@ export const MenuButton = () => { onClick={handleMenuClick} data-onboarding="menu-button" > - +