Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#255 페이지 선택할때 화면 벗어나가지 않도록 수정 #302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const MenuButton = () => {
onClick={handleMenuClick}
data-onboarding="menu-button"
>
<button className={menuItemWrapper}>
<div className={menuItemWrapper} role="button">
<MenuIcon />
<p className={textBox}>{name ?? "Nocta"}</p>
{/* <div className={nameWrapper}>
Expand All @@ -122,7 +122,7 @@ export const MenuButton = () => {
</div>
)}
</div> */}
</button>
</div>
<WorkspaceSelectModal isOpen={isOpen} userName={name} onInviteClick={handleInviteModal} />
<InviteModal
isOpen={isInviteModalOpen}
Expand Down
61 changes: 56 additions & 5 deletions client/src/features/workSpace/hooks/usePagesManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(() => {
Expand Down
Loading