@@ -31,98 +31,9 @@ const useMediaQuery = (query: string) => {
3131
3232export const Overview = ( pr : PullRequest ) => {
3333 const isSingleColumnLayout = useMediaQuery ( '(max-width: 768px)' ) ;
34- const titleRef = React . useRef < HTMLDivElement > ( null ) ;
35- const stickyHeightRef = React . useRef ( 0 ) ;
36- const collapseDeltaRef = React . useRef ( 0 ) ;
37-
38- React . useEffect ( ( ) => {
39- const title = titleRef . current ;
40-
41- if ( ! title ) {
42- return ;
43- }
44-
45- // Small threshold to account for sub-pixel rendering
46- const STICKY_THRESHOLD = 1 ;
47-
48- const measureStickyMetrics = ( ) => {
49- const wasStuck = title . classList . contains ( 'stuck' ) ;
50- if ( ! wasStuck ) {
51- title . classList . remove ( 'stuck' ) ;
52- }
53-
54- const unstuckHeight = title . getBoundingClientRect ( ) . height ;
55- // title.classList.add('stuck');
56- const stuckHeight = title . getBoundingClientRect ( ) . height ;
57- stickyHeightRef . current = stuckHeight ;
58- collapseDeltaRef . current = Math . max ( 0 , unstuckHeight - stuckHeight ) ;
59-
60- if ( ! wasStuck ) {
61- title . classList . remove ( 'stuck' ) ;
62- }
63- } ;
64-
65- const hasEnoughScroll = ( ) => {
66- const doc = document . documentElement ;
67- const body = document . body ;
68- const scrollHeight = Math . max ( doc . scrollHeight , body . scrollHeight ) ;
69- const availableScroll = scrollHeight - window . innerHeight ;
70- const adjustment = title . classList . contains ( 'stuck' ) ? collapseDeltaRef . current : 0 ;
71- return availableScroll + adjustment >= stickyHeightRef . current ;
72- } ;
73-
74- // Use scroll event with requestAnimationFrame to detect when title becomes sticky
75- // Check if the title's top position is at the viewport top (sticky position)
76- let ticking = false ;
77- const handleScroll = ( ) => {
78- if ( ticking ) {
79- return ;
80- }
81-
82- ticking = true ;
83- window . requestAnimationFrame ( ( ) => {
84- if ( ! hasEnoughScroll ( ) ) {
85- title . classList . remove ( 'stuck' ) ;
86- ticking = false ;
87- return ;
88- }
89-
90- const rect = title . getBoundingClientRect ( ) ;
91- // Title is stuck when its top is at position 0 (sticky top: 0)
92- if ( rect . top <= STICKY_THRESHOLD ) {
93- // title.classList.add('stuck');
94- } else {
95- title . classList . remove ( 'stuck' ) ;
96- }
97- ticking = false ;
98- } ) ;
99- } ;
100-
101- const handleResize = ( ) => {
102- measureStickyMetrics ( ) ;
103- handleScroll ( ) ;
104- } ;
105-
106- measureStickyMetrics ( ) ;
107-
108- // Check initial state after a brief delay to ensure layout is settled
109- const timeoutId = setTimeout ( ( ) => {
110- measureStickyMetrics ( ) ;
111- handleScroll ( ) ;
112- } , 100 ) ;
113-
114- window . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
115- window . addEventListener ( 'resize' , handleResize ) ;
116-
117- return ( ) => {
118- clearTimeout ( timeoutId ) ;
119- window . removeEventListener ( 'scroll' , handleScroll ) ;
120- window . removeEventListener ( 'resize' , handleResize ) ;
121- } ;
122- } , [ ] ) ;
12334
12435 return < >
125- < div id = "title" className = "title" ref = { titleRef } >
36+ < div id = "title" className = "title" >
12637 < div className = "details" >
12738 < Header { ...pr } />
12839 </ div >
0 commit comments