11import { Droppable } from '@hello-pangea/dnd' ;
22import { Box , Typography , useTheme } from '@mui/material' ;
3- import { useState } from 'react' ;
3+ import { useEffect , useRef , useState } from 'react' ;
44import { Project , Task , TaskStatus , TaskWithIndex } from 'shared' ;
55import { statusNames , TaskCard } from '.' ;
66import { NERButton } from '../../../../../components/NERButton' ;
@@ -13,22 +13,44 @@ export const TaskColumn = ({
1313 status,
1414 tasks,
1515 project,
16+ equalizedHeight,
1617 onEditTask,
1718 onDeleteTask,
18- onAddTask
19+ onAddTask,
20+ onHeightChange
1921} : {
2022 status : Task [ 'status' ] ;
2123 tasks : TaskWithIndex [ ] ;
2224 project : Project ;
25+ equalizedHeight : number ;
2326 onEditTask : ( task : Task ) => void ;
2427 onDeleteTask : ( taskId : string ) => void ;
2528 onAddTask : ( task : Task ) => void ;
29+ onHeightChange : ( status : Task [ 'status' ] , height : number ) => void ;
2630} ) => {
2731 const { mutateAsync : createTask } = useCreateTask ( ) ;
2832 const [ showCreateTaskModal , setShowCreateTaskModal ] = useState ( false ) ;
2933 const toast = useToast ( ) ;
3034 const theme = useTheme ( ) ;
3135
36+ // create ref to droppable box dom node so we can measure height
37+ const droppableBoxRef = useRef < HTMLElement | null > ( null ) ;
38+
39+ // effectively runs once on mount because both deps (task status and callback func) are stable
40+ useEffect ( ( ) => {
41+ if ( ! droppableBoxRef . current ) return ;
42+
43+ const droppableBox = droppableBoxRef . current ;
44+
45+ const observer = new ResizeObserver ( ( ) => {
46+ onHeightChange ( status , droppableBox . scrollHeight ) ;
47+ } ) ;
48+ observer . observe ( droppableBox ) ;
49+
50+ // cleanup func to disconnect observer when component unmounts
51+ return ( ) => observer . disconnect ( ) ;
52+ } , [ status , onHeightChange ] ) ;
53+
3254 const handleCreateTask = async ( { notes, title, deadline, assignees, priority, startDate } : EditTaskFormInput ) => {
3355 try {
3456 const task = await createTask ( {
@@ -75,14 +97,18 @@ export const TaskColumn = ({
7597 < Droppable droppableId = { status } >
7698 { ( droppableProvided , snapshot ) => (
7799 < Box
78- ref = { droppableProvided . innerRef }
100+ ref = { ( droppableBox : HTMLElement | null ) => {
101+ droppableProvided . innerRef ( droppableBox ) ; // give dnd lib access to dom node
102+ droppableBoxRef . current = droppableBox ; // give ourselves access to dom node
103+ } }
79104 { ...droppableProvided . droppableProps }
80105 className = { snapshot . isDraggingOver ? ' isDraggingOver' : '' }
81106 sx = { {
82107 display : 'flex' ,
83108 flexDirection : 'column' ,
84109 borderRadius : 5 ,
85110 padding : '5px' ,
111+ minHeight : `${ equalizedHeight } px` ,
86112 '&.isDraggingOver' : {
87113 bgcolor : '#dadadf'
88114 }
0 commit comments