Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5b56183
feat: EditCardContext에 대시보드 카드 드래그앤드랍 상태 관리 추가
lwjmcn Feb 15, 2026
f709a51
chore: import 경로 단축
lwjmcn Feb 15, 2026
8f126d8
feat: EditCardContext에 픽셀 좌표 계산을 위한 gridRef 추가
lwjmcn Feb 15, 2026
bf00cc2
refactor: 카드 상태 2차원 그리드 대신 카드 배열 기준으로 리팩터링
lwjmcn Feb 15, 2026
fa99942
feat: 그리드 셀 크기 계산을 위한 useGridCellSize 추가
lwjmcn Feb 15, 2026
3e281f5
feat: MiniViewActiveCard의 props 수정 (posX, posY -> colNo, rowNo)
lwjmcn Feb 15, 2026
ae9de0d
feat: 카드편집 뷰 카드 클릭 시 추가 이벤트 동작 및 클릭 이벤트 전파 방지
lwjmcn Feb 15, 2026
6b3a8d2
fix: parameter row,col 순서 변경 버그
lwjmcn Feb 15, 2026
d2103e0
feat: 드래그 앤 드롭 카드 기능 추가 및 카드 밀어내기 재귀 알고리즘 구현
lwjmcn Feb 15, 2026
fc3937f
feat: 카드 편집 및 미니 뷰에 드래그 앤 드롭 핸들러 연결 및 ghost 컴포넌트 추가
lwjmcn Feb 15, 2026
966d071
fix: 이미지 드래그 막기
lwjmcn Feb 15, 2026
e862450
fix: 이미 추가된 카드 드래그 시도 시 텍스트가 선택되는 문제
lwjmcn Feb 15, 2026
c17a05f
feat: dragOver 이벤트 핸들러에 스로틀링 추가
lwjmcn Feb 15, 2026
8077dfb
chore: 메트릭 이름 오타 수정
lwjmcn Feb 15, 2026
ca7e601
style: 메트릭 이름 줄바꿈 스타일링
lwjmcn Feb 15, 2026
bb21461
style: 드래그앤드랍 고스트 스타일링
lwjmcn Feb 15, 2026
30423b5
style: 삭제하기 오버레이 디자인 개선
lwjmcn Feb 18, 2026
bab413c
chore: import 경로 단축
lwjmcn Feb 18, 2026
8428a82
refactor: 드래그앤드랍 카드 위치 스타일링 left/top에서 translate로 개선
lwjmcn Feb 18, 2026
bbeba5d
refactor: 그리드 위치 계산 시 변수명을 rowPx/colPx에서 topInPixel/leftInPixel으로 개선
lwjmcn Feb 18, 2026
e2b4702
refactor: AABB 알고리즘 가독성 있게 변경
lwjmcn Feb 18, 2026
afd7181
refactor: 그리드 셀 거리 계산 방식을 유클리드에서 맨하탄으로 개선
lwjmcn Feb 18, 2026
5fa4f29
refactor: isSameGrid 함수 변수명 가독성 개선
lwjmcn Feb 18, 2026
68629c0
refactor: useRef로 throttle 인스턴스 재생성 방지 및 throttle cancel로 메모리 누수 방지
lwjmcn Feb 18, 2026
d02f297
refactor: throttle 함수에서 this 사용 제거
lwjmcn Feb 18, 2026
82d197b
refactor: useThrottle 훅을 추가하여 스로틀링 로직을 재사용 가능하게 함
lwjmcn Feb 18, 2026
ae14348
fix: 사파리 relatedTarget 이슈 해결
lwjmcn Feb 18, 2026
3a95eda
style: 카드 편집 뷰에 overflow 속성을 추가하여 레이아웃 개선
lwjmcn Feb 18, 2026
9ff5bd5
Merge branch 'develop' into feature/#54-fe-dashboard-edit-draggable
lwjmcn Feb 18, 2026
4393bd4
chore: 콘솔 로그 삭제
lwjmcn Feb 18, 2026
069402f
Merge branch 'develop' into feature/#54-fe-dashboard-edit-draggable
lwjmcn Feb 19, 2026
ff5d63e
fix: develop merge conflict
lwjmcn Feb 19, 2026
986292c
fix: useEffect dependency array 린트 에러 (develop)
lwjmcn Feb 19, 2026
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
24 changes: 22 additions & 2 deletions frontend/src/components/dashboard/dashboard-edit/CardEditView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useNavigate } from 'react-router-dom';

import { ButtonGroup } from '@/components/shared';
import { useEditCard } from '@/hooks/dashboard';
import { useDragAndDropCard, useEditCard } from '@/hooks/dashboard';
import { useEditCardContext } from '@/hooks/dashboard/useEditCardContext';

import { CardEditViewTabs } from './CardEditViewTabs';

Expand All @@ -10,6 +11,11 @@ export const CardEditView = () => {

const { isDirty } = useEditCard();

const { isOverList } = useEditCardContext();

const { handleListDragEnter, handleListDragLeave, handleListDrop } =
useDragAndDropCard();

const handleCancel = () => {
navigate(-1);
};
Expand All @@ -19,7 +25,13 @@ export const CardEditView = () => {
};

return (
<section className="bg-special-card-bg flex h-full w-[800px] shrink-0 flex-col pt-20 pr-5 pl-12.5">
<section
className="bg-special-card-bg relative flex h-full w-[800px] shrink-0 flex-col pt-20 pr-5 pl-12.5 select-none"
onDragEnter={handleListDragEnter}
onDragOver={(e) => e.preventDefault()}
onDragLeave={handleListDragLeave}
onDrop={handleListDrop}
>
<header className="flex items-center justify-between pr-5">
<h1 className="title-large-bold text-grey-900">카드 편집</h1>
<ButtonGroup>
Expand All @@ -32,6 +44,14 @@ export const CardEditView = () => {
</ButtonGroup>
</header>
<CardEditViewTabs />
{isOverList && (
<>
<div className="bg-grey-500 text-grey-0 absolute top-0 right-0 bottom-0 left-0 flex items-center justify-center opacity-50"></div>
<p className="headline-medium-bold text-grey-0 absolute top-1/2 right-0 bottom-0 left-0 text-center">
삭제하려면 여기에 놓으세요
</p>
</>
)}
</section>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useCallback, useMemo } from 'react';

import { EditCardWrapper } from '@/components/shared';
import {
DASHBOARD_EDIT_AREA,
DASHBOARD_METRIC_CARDS,
type MetricCardCode,
} from '@/constants/dashboard';
import { useEditCard } from '@/hooks/dashboard';
import { useDragAndDropCard, useEditCard } from '@/hooks/dashboard';

import { EditCardContent } from './EditCardContent';

Expand All @@ -15,6 +16,7 @@ interface CardEditViewCardProps {

export const CardEditViewCard = ({ cardCode }: CardEditViewCardProps) => {
const { addCard, removeCard, isAdded } = useEditCard();
const { handleDragStart, handleDragEnd } = useDragAndDropCard();

const card = useMemo(() => DASHBOARD_METRIC_CARDS[cardCode], [cardCode]);

Expand All @@ -35,7 +37,20 @@ export const CardEditViewCard = ({ cardCode }: CardEditViewCardProps) => {
const { period, sizeX, sizeY } = card;

return (
<li style={{ gridColumn: `span ${sizeX}` }}>
<li
style={{ gridColumn: `span ${sizeX}` }}
draggable={!memoisedIsAdded}
onDragStart={(e) =>
handleDragStart(e, DASHBOARD_EDIT_AREA.LIST, {
cardCode,
colNo: -1,
rowNo: -1,
})
}
onDragEnd={handleDragEnd}
className="translate-x-0 cursor-grab active:cursor-grabbing"
onClick={handleAddCard}
>
<EditCardWrapper
isAdded={memoisedIsAdded}
period={period}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CardEditViewTabContentGroup } from './CardEditViewTabContentGroup';
export const CardEditViewTabs = memo(() => {
const dashboardMetrics = useMemo(() => Object.values(DASHBOARD_METRICS), []);
return (
<Tabs defaultValue={dashboardMetrics[0].tab} className="h-full">
<Tabs defaultValue={dashboardMetrics[0].tab} className="overflow-hidden">
<TabsList className="mx-0 mt-10 gap-1000" variant="line">
{dashboardMetrics.map(({ tab }) => (
<TabsTrigger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MiniView } from './MiniView';

export const DashboardEditLayout = () => {
return (
<div className="flex size-full overflow-y-hidden">
<div className="flex size-full">
<EditCardProvider>
<MiniView />
<CardEditView />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
import { type PropsWithChildren, useState } from 'react';
import { type PropsWithChildren, useRef, useState } from 'react';

import {
GRID_COL_SIZE,
GRID_ROW_SIZE,
type MetricCardCode,
} from '@/constants/dashboard';
import { EditCardContext } from '@/constants/dashboard/editCardContext';

const EMPTY_GRID: (MetricCardCode | null)[][] = Array.from(
{ length: GRID_ROW_SIZE + 1 },
() => Array.from({ length: GRID_COL_SIZE + 1 }, () => null),
);
import type { DashboardCard, DragState, GhostState } from '@/types/dashboard';

export const EditCardProvider = ({ children }: PropsWithChildren) => {
const initGrid = EMPTY_GRID; // TODO: 초기 그리드 상태 서버에서 받아오기
const [grid, setGrid] = useState<(MetricCardCode | null)[][]>(EMPTY_GRID);
// TODO: 초기 그리드 상태 서버에서 받아오기
const initPlacedCards: DashboardCard[] = [];

// 카드 그리드 상태
const [placedCards, setPlacedCards] =
useState<DashboardCard[]>(initPlacedCards);

// 드래그앤드랍 관련 상태
const [dragState, setDragState] = useState<DragState | null>(null);
const [ghost, setGhost] = useState<GhostState | null>(null);
const [tempLayout, setTempLayout] = useState<DashboardCard[] | null>(null);
const [isOverList, setIsOverList] = useState(false);

const gridRef = useRef<HTMLDivElement>(null);

return (
<EditCardContext.Provider value={{ initGrid, grid, setGrid }}>
<EditCardContext.Provider
value={{
initPlacedCards,
placedCards,
setPlacedCards,
gridRef,
dragState,
setDragState,
ghost,
setGhost,
tempLayout,
setTempLayout,
isOverList,
setIsOverList,
}}
>
Comment on lines +23 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3: 이젠 진짜 state Provider, action Provider로 나누어야 할 것 같네요..
useReducer를 사용해서 state provider랑 dispatch provider를 분리하면 좋을 것 같습니다
아니면 context를 쪼갠다거나...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 dispatch 함수만을 구독하고 있는 컴포넌트가 없습니다 (다 state만 구독하거나 state & dispatch를 동시에 구독하고 있어요)
그래서 state provider와 dispatch provider를 분리해서 얻을 이점이 딱히 없을 것 같습니다.
지금 보기에도 context에 상태가 너무 많아서 분리해야 할 필요성은 있을 것 같습니다. 일단 카드 그리드 상태와 드래그앤드랍 상태를 나눌 수 있을 것 같아요. 다만 카드목록 전체 리렌더링 상황에서도 selector를 고려했어서, 대시보드 카드 관련 내용을 다 외부 스토어로 전환하는 게 어떤가 싶습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리팩터링 이슈 파두었습니다. #316

{children}
</EditCardContext.Provider>
);
Expand Down
52 changes: 37 additions & 15 deletions frontend/src/components/dashboard/dashboard-edit/MiniView.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
import { useLocation } from 'react-router-dom';

import { useEditCard } from '@/hooks/dashboard';
import { GRID_COL_SIZE, GRID_ROW_SIZE } from '@/constants/dashboard';
import { useDragAndDropCard, useEditCardContext } from '@/hooks/dashboard';

import { MiniViewActiveCard } from './MiniViewActiveCard';
import { MiniViewEmptyCard } from './MiniViewEmptyCard';
import { MiniViewGhost } from './MiniViewGhost';

export const MiniView = () => {
const searchParams = new URLSearchParams(useLocation().search);
const title = searchParams.get('tab') || '알 수 없음';

const { cards, emptyCellCount } = useEditCard();
const { gridRef, dragState, tempLayout, placedCards } = useEditCardContext();
const { handleGridDragOver, handleGridDragLeave, handleGridDrop } =
useDragAndDropCard();

return (
<section className="flex min-w-120 grow flex-col p-6.25 pt-20">
<section className="flex min-w-120 grow flex-col overflow-y-auto p-6.25 pt-20">
<header className="mb-20 pl-5">
<h1 className="title-large-bold text-grey-900">{title}</h1>
</header>
<div className="grid grow grid-cols-3 grid-rows-3 gap-5">
{Array.from({ length: emptyCellCount }).map((_, index) => (
<MiniViewEmptyCard key={`grid-${index}`} />
))}
<div
className="relative mx-auto min-h-181 min-w-137.5"
ref={gridRef}
onDragOver={handleGridDragOver}
onDragLeave={handleGridDragLeave}
onDrop={handleGridDrop}
>
{/* 그리드 셀 가이드라인 */}
<div className="grid h-full grow grid-cols-3 grid-rows-3 gap-5">
{Array.from({ length: GRID_ROW_SIZE * GRID_COL_SIZE }).map(
(_, index) => (
<MiniViewEmptyCard key={`grid-${index}`} />
),
)}
</div>

{/* 활성 카드 */}
{cards.map((card) => (
<MiniViewActiveCard
key={`mini-${card.cardCode}`}
cardCode={card.cardCode}
posX={card.colNo}
posY={card.rowNo}
/>
))}
{(tempLayout || placedCards).map((card) => {
const isDragging = dragState?.draggingCard.cardCode === card.cardCode;
return (
<MiniViewActiveCard
key={`mini-${card.cardCode}`}
cardCode={card.cardCode}
colNo={card.colNo}
rowNo={card.rowNo}
isDragging={isDragging}
/>
);
})}

<MiniViewGhost />
</div>
</section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@ import { XIcon } from 'lucide-react';
import { PeriodTag } from '@/components/shared';
import { Button } from '@/components/shared/shadcn-ui';
import {
DASHBOARD_EDIT_AREA,
DASHBOARD_METRIC_CARDS,
type MetricCardCode,
} from '@/constants/dashboard';
import { CDN_BASE_URL } from '@/constants/shared/cdnBaseUrl';
import { useEditCard } from '@/hooks/dashboard';
import { CDN_BASE_URL } from '@/constants/shared';
import {
useDragAndDropCard,
useEditCard,
useGridCellSize,
} from '@/hooks/dashboard';
import { cn } from '@/utils/shared';

interface MiniViewActiveCardProps {
cardCode: MetricCardCode;
posX: number;
posY: number;
colNo: number;
rowNo: number;
isDragging: boolean;
}
export const MiniViewActiveCard = ({
cardCode,
posX,
posY,
colNo,
rowNo,
isDragging,
}: MiniViewActiveCardProps) => {
const { removeCard } = useEditCard();
const { handleDragStart, handleDragEnd } = useDragAndDropCard();
const { getGridPosition, getGridCardSize } = useGridCellSize();

const card = DASHBOARD_METRIC_CARDS[cardCode];

const handleRemove = useCallback(
Expand All @@ -35,21 +46,39 @@ export const MiniViewActiveCard = ({
}
const { label, type, period, sizeX, sizeY } = card;

const { topInPixel, leftInPixel } = getGridPosition(rowNo, colNo);
const { widthInPixel, heightInPixel } = getGridCardSize(sizeX, sizeY);

return (
<div
className="rounded-400 bg-grey-0 relative border-none"
draggable
onDragStart={(e) =>
handleDragStart(e, DASHBOARD_EDIT_AREA.GRID, {
cardCode,
colNo,
rowNo,
})
}
onDragEnd={handleDragEnd}
className={cn(
'rounded-300 bg-grey-0 absolute top-0 left-0 cursor-grab border-none transition-all duration-200 select-none active:cursor-grabbing',
isDragging ? 'opacity-0' : 'opacity-100',
)}
style={{
gridColumn: `${posX} / span ${sizeX}`,
gridRow: `${posY} / span ${sizeY}`,
translate: `${leftInPixel}px ${topInPixel}px`,
width: widthInPixel,
height: heightInPixel,
}}
>
<div className="flex h-full flex-col items-center justify-center">
<div className="relative flex h-full flex-col items-center justify-center p-4">
<img
src={`${CDN_BASE_URL}/assets/images/${type}.svg`}
alt={`${label} 미니 뷰`}
className="size-15"
draggable={false}
/>
<p className="body-small-medium text-grey-900 mt-200 mb-100">{label}</p>
<p className="body-small-medium text-grey-900 mt-200 mb-100 text-center break-keep">
{label}
</p>
<PeriodTag isAdded period={period} />
</div>
{/* 상단 삭제 버튼 */}
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/components/dashboard/dashboard-edit/MiniViewGhost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DASHBOARD_METRIC_CARDS } from '@/constants/dashboard';
import { useEditCardContext, useGridCellSize } from '@/hooks/dashboard';
import { cn } from '@/utils/shared';

export const MiniViewGhost = () => {
const { dragState, ghost, isOverList } = useEditCardContext();
const { getGridPosition, getGridCardSize } = useGridCellSize();

if (!dragState || !ghost || isOverList) {
return null;
}

const draggingCardDef =
DASHBOARD_METRIC_CARDS[dragState.draggingCard.cardCode];

const { topInPixel, leftInPixel } = getGridPosition(ghost.rowNo, ghost.colNo);
const { widthInPixel, heightInPixel } = getGridCardSize(
draggingCardDef.sizeX,
draggingCardDef.sizeY,
);

return (
<div
className={cn(
'rounded-400 pointer-events-none absolute top-0 left-0 shadow-[2px_2px_8px_0_rgba(0,0,0,0.15)_inset] transition-all duration-200',
ghost.isValid ? 'bg-grey-200' : 'bg-others-negative opacity-40',
)}
style={{
translate: `${leftInPixel}px ${topInPixel}px`,
width: widthInPixel,
height: heightInPixel,
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ interface PlusIconButtonProps {
export const PlusIconButton = ({ onClickAddButton }: PlusIconButtonProps) => {
return (
<Button
onClick={onClickAddButton}
onClick={(e) => {
e.stopPropagation();
onClickAddButton?.();
}}
className="rounded-unlimit border-grey-200 bg-grey-100 text-grey-900 hover:border-grey-900 active:bg-grey-900 active:text-grey-50 flex size-6.5 items-center justify-center border"
>
<Plus className="size-4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const TrashCanIconButton = ({
}: TrashCanIconButtonProps) => {
return (
<Button
onClick={onClickDeleteButton}
onClick={(e) => {
e.stopPropagation();
onClickDeleteButton?.();
}}
className="rounded-unlimit hover:text-others-negative border-grey-200 bg-grey-100 text-grey-900 active:bg-grey-900 active:text-grey-50 flex size-6.5 items-center justify-center border"
>
<Trash2 className="size-4" />
Expand Down
Loading