Skip to content

Commit 0eef5c7

Browse files
committed
#4020 refactor taskcolumn to do all height change obs inside ref prop
1 parent 65a8c1b commit 0eef5c7

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

  • src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/TaskList/v2

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/TaskList/v2/TaskColumn.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Droppable } from '@hello-pangea/dnd';
22
import { Box, Typography, useTheme } from '@mui/material';
3-
import { useEffect, useRef, useState } from 'react';
3+
import { useState } from 'react';
44
import { Project, Task, TaskStatus, TaskWithIndex } from 'shared';
55
import { statusNames, TaskCard } from '.';
66
import { NERButton } from '../../../../../components/NERButton';
@@ -35,23 +35,6 @@ export const TaskColumn = ({
3535
const toast = useToast();
3636
const theme = useTheme();
3737

38-
// create ref to droppable box dom node so we can measure height
39-
const droppableBoxRef = useRef<HTMLElement | null>(null);
40-
41-
// effectively runs once on mount because both deps (task status and callback func) are stable
42-
useEffect(() => {
43-
if (!droppableBoxRef.current) return;
44-
45-
const droppableBox = droppableBoxRef.current;
46-
const observer = new ResizeObserver(() => {
47-
onHeightChange(status, droppableBox.scrollHeight);
48-
});
49-
observer.observe(droppableBox);
50-
51-
// cleanup func to disconnect observer when component unmounts
52-
return () => observer.disconnect();
53-
}, [status, onHeightChange]);
54-
5538
const handleCreateTask = async ({ notes, title, deadline, assignees, priority, startDate }: EditTaskFormInput) => {
5639
try {
5740
const task = await createTask({
@@ -114,7 +97,13 @@ export const TaskColumn = ({
11497
<Box
11598
ref={(droppableBox: HTMLElement | null) => {
11699
droppableProvided.innerRef(droppableBox); // give dnd lib access to dom node
117-
droppableBoxRef.current = droppableBox; // give ourselves 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();
118107
}}
119108
{...droppableProvided.droppableProps}
120109
className={snapshot.isDraggingOver ? ' isDraggingOver' : ''}

0 commit comments

Comments
 (0)