-
Notifications
You must be signed in to change notification settings - Fork 0
[FE] 대시보드 지표 카드 드래그앤드롭 편집 기능 구현 #276
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5b56183
f709a51
8f126d8
bf00cc2
fa99942
3e281f5
ae9de0d
6b3a8d2
d2103e0
fc3937f
966d071
e862450
c17a05f
8077dfb
ca7e601
bb21461
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3: 이젠 진짜 state Provider, action Provider로 나누어야 할 것 같네요..
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금 dispatch 함수만을 구독하고 있는 컴포넌트가 없습니다 (다 state만 구독하거나 state & dispatch를 동시에 구독하고 있어요) |
||
| {children} | ||
| </EditCardContext.Provider> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 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 { rowPx, colPx } = getGridPosition(ghost.rowNo, ghost.colNo); | ||
| const { widthPx, heightPx } = getGridCardSize( | ||
| draggingCardDef.sizeX, | ||
| draggingCardDef.sizeY, | ||
| ); | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| 'rounded-400 pointer-events-none absolute 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={{ | ||
| left: colPx, | ||
| top: rowPx, | ||
lwjmcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| width: widthPx, | ||
| height: heightPx, | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { ValueOf } from '@/utils/shared'; | ||
|
|
||
| export const DIRECTIONS = { | ||
| DOWN: { dx: 0, dy: 1 }, | ||
| RIGHT: { dx: 1, dy: 0 }, | ||
| UP: { dx: 0, dy: -1 }, | ||
| LEFT: { dx: -1, dy: 0 }, | ||
| }; | ||
|
|
||
| export const DASHBOARD_EDIT_AREA = { | ||
| LIST: 'list', | ||
| GRID: 'grid', | ||
| } as const; | ||
|
|
||
| export type DashboardEditArea = ValueOf<typeof DASHBOARD_EDIT_AREA>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3: 카드 영역으로 드래그하면 삭제 처리 되는거 좋네요. UI가 아직은 빨간 배경에
DROP TO DELETE문구만 있어서 따로 정해지면 좋을거 같아요Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빨간색이 별로라는 평이 있어서 아래처럼 바꿔보았습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋아용 ㅎㅎ