1- import { useState , useRef , useEffect } from 'react'
1+ import { useState , useRef } from 'react'
22import styles from './Home.module.scss'
33import { Scrollable } from '@ui/components/editor/panel/Scrollable'
44import { Timeline } from '@ui/components/editor/panel/Timeline'
@@ -15,6 +15,7 @@ import { IconButton } from '@ui/components/editor/panel/IconButton'
1515import { Tasks } from '@ui/components/editor/panel/Tasks'
1616import { Task } from '@shared/types/task'
1717import { use_tasks } from './hooks/use-tasks'
18+ import { use_timeline_scroll } from './hooks/use-timeline-scroll'
1819
1920type Props = {
2021 vscode : any
@@ -45,33 +46,9 @@ type Props = {
4546export const Home : React . FC < Props > = ( props ) => {
4647 const { t } = use_translation ( )
4748 const [ is_mode_sticky , set_is_mode_sticky ] = useState ( false )
48- const [ is_timeline_reached , set_is_timeline_reached ] = useState ( true )
4949 const full_mode_height_ref = useRef < number > ( 0 )
5050 const responses_ref = useRef < HTMLDivElement > ( null )
5151 const mode_ref = useRef < HTMLDivElement > ( null )
52- const timeline_ref = useRef < HTMLDivElement > ( null )
53-
54- useEffect ( ( ) => {
55- const observer = new IntersectionObserver (
56- ( [ entry ] ) => {
57- const is_above_viewport =
58- entry . boundingClientRect . top <
59- ( entry . rootBounds ?. height ?? window . innerHeight ) / 2
60- set_is_timeline_reached ( entry . isIntersecting || is_above_viewport )
61- } ,
62- {
63- threshold : 0.1
64- }
65- )
66-
67- if ( timeline_ref . current ) {
68- observer . observe ( timeline_ref . current )
69- }
70-
71- return ( ) => {
72- observer . disconnect ( )
73- }
74- } , [ ] )
7552
7653 const {
7754 handle_reorder,
@@ -82,6 +59,9 @@ export const Home: React.FC<Props> = (props) => {
8259 handle_copy
8360 } = use_tasks ( props . on_tasks_change , props . on_task_delete , props . on_task_copy )
8461
62+ const { is_timeline_reached, timeline_ref, handle_scroll_to_timeline } =
63+ use_timeline_scroll ( )
64+
8565 const handle_settings_click = ( ) => {
8666 post_message ( props . vscode , {
8767 command : 'EXECUTE_COMMAND' ,
@@ -101,15 +81,6 @@ export const Home: React.FC<Props> = (props) => {
10181 } as FrontendMessage )
10282 }
10383
104- const handle_scroll_to_timeline = ( ) => {
105- if ( timeline_ref . current ) {
106- timeline_ref . current . style . scrollMarginTop = '55px'
107- timeline_ref . current . scrollIntoView ( {
108- behavior : 'smooth'
109- } )
110- }
111- }
112-
11384 return (
11485 < >
11586 < div className = { styles . header } >
0 commit comments