-
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
Changes from 30 commits
5b56183
f709a51
8f126d8
bf00cc2
fa99942
3e281f5
ae9de0d
6b3a8d2
d2103e0
fc3937f
966d071
e862450
c17a05f
8077dfb
ca7e601
bb21461
30423b5
bab413c
8428a82
bbeba5d
e2b4702
afd7181
5fa4f29
68629c0
d02f297
82d197b
ae14348
3a95eda
9ff5bd5
4393bd4
069402f
ff5d63e
986292c
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를 동시에 구독하고 있어요)
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. 리팩터링 이슈 파두었습니다. #316 |
||
| {children} | ||
| </EditCardContext.Provider> | ||
| ); | ||
|
|
||
| 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, | ||
| }} | ||
| /> | ||
| ); | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.