Skip to content

Commit 8c74083

Browse files
committed
Optimize copied task highlight reset to trigger only on structural changes rather than all task updates
1 parent ebaff21 commit 8c74083

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

  • packages/ui/src/components/editor/panel/Tasks

‎packages/ui/src/components/editor/panel/Tasks/Tasks.tsx‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ const remove_ids = (tasks: SortableTask[]): Task[] => {
3737
}))
3838
}
3939

40+
const get_structure_signature = (tasks: Task[]): string => {
41+
return tasks
42+
.map(
43+
(t) =>
44+
`${t.created_at}` +
45+
(t.children && t.children.length > 0
46+
? `[${get_structure_signature(t.children)}]`
47+
: '')
48+
)
49+
.join(',')
50+
}
51+
4052
export const Tasks: React.FC<Props> = (props) => {
4153
use_periodic_re_render(60 * 1000)
4254
const [editing_timestamp, set_editing_timestamp] = useState<number | null>(
@@ -47,9 +59,16 @@ export const Tasks: React.FC<Props> = (props) => {
4759
>(null)
4860
const prevent_edit_ref = useRef(false)
4961

62+
const structure_signature = useMemo(
63+
() => get_structure_signature(props.tasks),
64+
[props.tasks]
65+
)
66+
67+
// Reset copied highlight only on structural changes to tasks
68+
// so it stays highlighted when set as done by response preview.
5069
useEffect(() => {
5170
set_last_copied_timestamp(null)
52-
}, [props.tasks])
71+
}, [structure_signature])
5372

5473
const tree = useMemo(() => add_ids(props.tasks), [props.tasks])
5574

0 commit comments

Comments
 (0)