-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: #33 컴포넌트 분리 / types & constants 등 관심사 분리
- Loading branch information
Showing
7 changed files
with
139 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Draggable, DraggableId } from '@hello-pangea/dnd'; | ||
|
||
type TaskItemProps = { | ||
draggableId: DraggableId; | ||
name: string; | ||
color: string; | ||
index: number; | ||
}; | ||
|
||
export default function TaskItem({ draggableId, name, color, index }: TaskItemProps) { | ||
return ( | ||
<Draggable draggableId={draggableId} index={index}> | ||
{(dragProvided) => ( | ||
<div | ||
className="m-5 flex h-30 items-center justify-start gap-5 rounded-sl bg-[#FEFEFE] p-5" | ||
ref={dragProvided.innerRef} | ||
{...dragProvided.draggableProps} | ||
{...dragProvided.dragHandleProps} | ||
> | ||
<div style={{ borderColor: color }} className="h-8 w-8 rounded-full border" /> | ||
<div className="select-none overflow-hidden text-ellipsis text-nowrap">{name}</div> | ||
</div> | ||
)} | ||
</Draggable> | ||
); | ||
} |
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,36 @@ | ||
import { useMemo } from 'react'; | ||
import { Droppable } from '@hello-pangea/dnd'; | ||
import TaskItem from '@components/task/kanban/TaskItem'; | ||
import { generatePrefixId } from '@utils/converter'; | ||
import { DND_DRAGGABLE_PREFIX, DND_DROPPABLE_PREFIX, DND_TYPE } from '@constants/dnd'; | ||
import type { Task } from '@/types/TaskType'; | ||
|
||
type TaskItemListProps = { | ||
statusId: number; | ||
color: string; | ||
tasks: Task[]; | ||
}; | ||
|
||
export default function TaskItemList({ statusId, color, tasks }: TaskItemListProps) { | ||
const droppableId = useMemo(() => generatePrefixId(statusId, DND_DROPPABLE_PREFIX.TASK), [statusId]); | ||
return ( | ||
<Droppable droppableId={droppableId} type={DND_TYPE.TASK}> | ||
{(taskDropProvided) => ( | ||
<article | ||
style={{ borderColor: color }} | ||
className="h-full w-full grow border-l-[3px] bg-scroll" | ||
ref={taskDropProvided.innerRef} | ||
{...taskDropProvided.droppableProps} | ||
> | ||
{tasks.map((task) => { | ||
const { taskId, name, order } = task; | ||
const draggableId = generatePrefixId(taskId, DND_DRAGGABLE_PREFIX.TASK); | ||
const index = order - 1; | ||
return <TaskItem key={taskId} draggableId={draggableId} color={color} index={index} name={name} />; | ||
})} | ||
{taskDropProvided.placeholder} | ||
</article> | ||
)} | ||
</Droppable> | ||
); | ||
} |
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,37 @@ | ||
import { useMemo } from 'react'; | ||
import { Draggable } from '@hello-pangea/dnd'; | ||
import TaskItemList from '@components/task/kanban/TaskItemList'; | ||
import { generatePrefixId } from '@utils/converter'; | ||
import { DND_DRAGGABLE_PREFIX } from '@constants/dnd'; | ||
import { BsPencil } from 'react-icons/bs'; | ||
import { TaskWithStatus } from '@/types/TaskType'; | ||
|
||
type TaskStatusContainerProps = { | ||
statusTask: TaskWithStatus; | ||
}; | ||
|
||
export default function TaskStatusContainer({ statusTask }: TaskStatusContainerProps) { | ||
const { statusId, name, color, order, tasks } = statusTask; | ||
const draggableId = useMemo(() => generatePrefixId(statusId, DND_DRAGGABLE_PREFIX.STATUS), [statusId]); | ||
const index = useMemo(() => order - 1, [order]); | ||
|
||
return ( | ||
<Draggable draggableId={draggableId} index={index} key={statusId}> | ||
{(statusDragProvided) => ( | ||
<article | ||
className="flex min-w-125 grow basis-1/3 flex-col" | ||
ref={statusDragProvided.innerRef} | ||
{...statusDragProvided.draggableProps} | ||
> | ||
<header className="flex items-center gap-4" {...statusDragProvided.dragHandleProps}> | ||
<h2 className="select-none font-bold text-emphasis">{name}</h2> | ||
<span> | ||
<BsPencil className="cursor-pointer" /> | ||
</span> | ||
</header> | ||
<TaskItemList statusId={statusId} color={color} tasks={tasks} /> | ||
</article> | ||
)} | ||
</Draggable> | ||
); | ||
} |
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,19 @@ | ||
type DndTypeKeys = keyof typeof DND_TYPE; | ||
type DndTypeValues = (typeof DND_TYPE)[DndTypeKeys]; | ||
type DndDroppablePrefix = { | ||
[K in DndTypeKeys]: `${DndTypeValues}-CONTAINER`; | ||
}; | ||
|
||
export const DND_TYPE = Object.freeze({ | ||
STATUS: 'STATUS', | ||
TASK: 'TASK', | ||
}); | ||
|
||
export const DND_DROPPABLE_PREFIX: Readonly<DndDroppablePrefix> = Object.freeze( | ||
Object.entries(DND_TYPE).reduce((obj, [key, value]) => { | ||
obj[key as DndTypeKeys] = `${value}-CONTAINER`; | ||
return obj; | ||
}, {} as DndDroppablePrefix), | ||
); | ||
|
||
export const DND_DRAGGABLE_PREFIX = Object.freeze({ ...DND_TYPE }); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function generatePrefixId(id: number | string, prefix: string, delimiter: string = '-') { | ||
return `${prefix}${delimiter}${id}`; | ||
} | ||
|
||
export function parsePrefixId(prefixId: string, delimiter: string = '-') { | ||
const result = prefixId.split(delimiter); | ||
return result[result.length - 1]; | ||
} |