-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] 픽 렌더링 카드에서 리스트 아이템으로 교체 (#501)
* feat: PickRenderModeState 구현 * feat: PickRecordListLayout 컴포넌트 구현 * feat: PickCard대신 PickRecord 렌더링으로 변경 * feat: usePickRenderModeStore 의존성 제거
- Loading branch information
Showing
15 changed files
with
226 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
frontend/techpick/src/components/PickListViewer/PickDndRecord.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use client'; | ||
|
||
import { MouseEvent, useCallback, type CSSProperties } from 'react'; | ||
import { useSortable } from '@dnd-kit/sortable'; | ||
import { CSS } from '@dnd-kit/utilities'; | ||
import { usePickStore } from '@/stores'; | ||
import { isSelectionActive } from '@/utils'; | ||
import { | ||
isActiveDraggingItemStyle, | ||
selectedDragItemStyle, | ||
} from './pickDnDCard.css'; | ||
import { getSelectedPickRange } from './pickDnDCard.util'; | ||
import { PickRecord } from './PickRecord'; | ||
import type { PickViewDnDItemComponentProps } from './PickListViewer'; | ||
|
||
export function PickDndRecord({ pickInfo }: PickViewDnDItemComponentProps) { | ||
const { | ||
selectedPickIdList, | ||
selectSinglePick, | ||
getOrderedPickIdListByFolderId, | ||
focusPickId, | ||
setSelectedPickIdList, | ||
isDragging, | ||
} = usePickStore(); | ||
const { linkInfo, id: pickId, parentFolderId } = pickInfo; | ||
const { url } = linkInfo; | ||
const isSelected = selectedPickIdList.includes(pickId); | ||
const { | ||
attributes, | ||
listeners, | ||
setNodeRef, | ||
transform, | ||
transition, | ||
isDragging: isActiveDragging, | ||
} = useSortable({ | ||
id: pickId, | ||
data: { | ||
id: pickId, | ||
type: 'pick', | ||
parentFolderId: parentFolderId, | ||
}, | ||
}); | ||
const pickElementId = `pickId-${pickId}`; | ||
|
||
const style: CSSProperties = { | ||
transform: CSS.Transform.toString(transform), | ||
transition, | ||
opacity: 1, | ||
}; | ||
|
||
const openUrl = useCallback(() => { | ||
window.open(url, '_blank'); | ||
}, [url]); | ||
|
||
const handleShiftSelect = (parentFolderId: number, pickId: number) => { | ||
if (!focusPickId) { | ||
return; | ||
} | ||
|
||
// 새로운 선택된 배열 만들기. | ||
const orderedPickIdList = getOrderedPickIdListByFolderId(parentFolderId); | ||
|
||
const newSelectedPickIdList = getSelectedPickRange({ | ||
orderedPickIdList, | ||
startPickId: focusPickId, | ||
endPickId: pickId, | ||
}); | ||
|
||
setSelectedPickIdList(newSelectedPickIdList); | ||
}; | ||
|
||
const handleClick = ( | ||
pickId: number, | ||
event: MouseEvent<HTMLDivElement, globalThis.MouseEvent> | ||
) => { | ||
if (event.shiftKey && isSelectionActive(selectedPickIdList.length)) { | ||
event.preventDefault(); | ||
handleShiftSelect(parentFolderId, pickId); | ||
return; | ||
} | ||
|
||
selectSinglePick(pickId); | ||
}; | ||
|
||
if (isDragging && isSelected && !isActiveDragging) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<div ref={setNodeRef} {...attributes} {...listeners} style={style}> | ||
<div | ||
className={`${isSelected ? selectedDragItemStyle : ''} ${isActiveDragging ? isActiveDraggingItemStyle : ''}`} | ||
onDoubleClick={openUrl} | ||
onClick={(event) => handleClick(pickId, event)} | ||
id={pickElementId} | ||
> | ||
<PickRecord pickInfo={pickInfo} /> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
frontend/techpick/src/components/PickListViewer/PickDndRecordListLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PickViewDnDItemListLayoutComponentProps } from './DraggablePickListViewer'; | ||
import { PickListSortableContext } from './PickListSortableContext'; | ||
import { PickRecordListLayout } from './PickRecordListLayout'; | ||
|
||
export function PickDndRecordListLayout({ | ||
children, | ||
folderId, | ||
viewType, | ||
}: PickViewDnDItemListLayoutComponentProps) { | ||
return ( | ||
<PickRecordListLayout> | ||
<PickListSortableContext folderId={folderId} viewType={viewType}> | ||
{children} | ||
</PickListSortableContext> | ||
</PickRecordListLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
frontend/techpick/src/components/PickListViewer/PickRecordListLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use client'; | ||
import { PickViewItemListLayoutComponentProps } from './PickListViewer'; | ||
import { pickRecordListLayoutStyle } from './pickRecordListLayout.css'; | ||
|
||
export function PickRecordListLayout({ | ||
children, | ||
}: PickViewItemListLayoutComponentProps) { | ||
return <div className={pickRecordListLayoutStyle}>{children}</div>; | ||
} |
15 changes: 13 additions & 2 deletions
15
frontend/techpick/src/components/PickListViewer/pickRecordListLayout.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
import { CSSProperties } from 'react'; | ||
import type { CSSProperties } from 'react'; | ||
import { style } from '@vanilla-extract/css'; | ||
import { sizes, space } from 'techpick-shared'; | ||
|
||
export const RECORD_HEIGHT = 100; | ||
|
||
export const pickRecordListLayoutStyle: CSSProperties = {}; | ||
export const pickRecordListLayoutInlineStyle: CSSProperties = {}; | ||
|
||
export const pickRecordListLayoutStyle = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: space['12'], | ||
width: sizes['full'], | ||
height: sizes['full'], | ||
overflowY: 'scroll', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { useTagStore } from './tagStore'; | ||
export { usePickStore } from './pickStore/pickStore'; | ||
export { useTreeStore } from './dndTreeStore/dndTreeStore'; | ||
export { usePickRenderModeStore } from './pickRenderModeStore'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { create } from 'zustand'; | ||
import { immer } from 'zustand/middleware/immer'; | ||
import type { | ||
PickRenderModeAction, | ||
PickRenderModeState, | ||
} from './pickRenderModeStore.type'; | ||
|
||
const initialState: PickRenderModeState = { | ||
pickRenderMode: 'list', | ||
}; | ||
|
||
export const usePickRenderModeStore = create< | ||
PickRenderModeState & PickRenderModeAction | ||
>()( | ||
immer((set) => ({ | ||
...initialState, | ||
|
||
setPickRenderMode: (newPickRenderMode) => { | ||
set((state) => { | ||
state.pickRenderMode = newPickRenderMode; | ||
}); | ||
}, | ||
})) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PickRenderModeType } from '@/types'; | ||
|
||
export type PickRenderModeState = { | ||
pickRenderMode: PickRenderModeType; | ||
}; | ||
|
||
export type PickRenderModeAction = { | ||
setPickRenderMode: (newPickRenderMode: PickRenderModeType) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* @description PickRenderModeType은 Pick의 렌더링 UI 중 무엇을 보여줄지 나타냅니다. ex) card, list | ||
*/ | ||
export type PickRenderModeType = 'card' | 'list'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters