|
1 | 1 | import { Droppable } from '@hello-pangea/dnd'; |
2 | 2 | import { Box, Typography, useTheme } from '@mui/material'; |
3 | | -import { useState } from 'react'; |
| 3 | +import { useEffect, useRef, useState } from 'react'; |
4 | 4 | import { Project, Task, TaskStatus, TaskWithIndex } from 'shared'; |
5 | 5 | import { statusNames, TaskCard } from '.'; |
6 | 6 | import { NERButton } from '../../../../../components/NERButton'; |
@@ -34,6 +34,17 @@ export const TaskColumn = ({ |
34 | 34 | const [showCreateTaskModal, setShowCreateTaskModal] = useState(false); |
35 | 35 | const toast = useToast(); |
36 | 36 | const theme = useTheme(); |
| 37 | + const droppableBoxRef = useRef<HTMLElement | null>(null); |
| 38 | + |
| 39 | + useEffect(() => { |
| 40 | + const box = droppableBoxRef.current; |
| 41 | + if (!box) return; |
| 42 | + const observer = new ResizeObserver(() => { |
| 43 | + onHeightChange(status, box.scrollHeight); |
| 44 | + }); |
| 45 | + observer.observe(box); |
| 46 | + return () => observer.disconnect(); |
| 47 | + }, [status, onHeightChange]); |
37 | 48 |
|
38 | 49 | const handleCreateTask = async ({ notes, title, deadline, assignees, priority, startDate }: EditTaskFormInput) => { |
39 | 50 | try { |
@@ -96,14 +107,8 @@ export const TaskColumn = ({ |
96 | 107 | {(droppableProvided, snapshot) => ( |
97 | 108 | <Box |
98 | 109 | ref={(droppableBox: HTMLElement | null) => { |
99 | | - droppableProvided.innerRef(droppableBox); // give dnd lib access to dom node |
100 | | - if (!droppableBox) return; |
101 | | - |
102 | | - const observer = new ResizeObserver(() => { |
103 | | - onHeightChange(status, droppableBox.scrollHeight); |
104 | | - }); |
105 | | - observer.observe(droppableBox); |
106 | | - return () => observer.disconnect(); |
| 110 | + droppableProvided.innerRef(droppableBox); |
| 111 | + droppableBoxRef.current = droppableBox; |
107 | 112 | }} |
108 | 113 | {...droppableProvided.droppableProps} |
109 | 114 | className={snapshot.isDraggingOver ? ' isDraggingOver' : ''} |
|
0 commit comments