@@ -112,6 +112,12 @@ const StatementItem: React.FC<StatementItemProps> = ({
112112 originalCategory : externalOriginalCategory , // Get original category from parent
113113} ) => {
114114 const [ isActionsExpanded , setIsActionsExpanded ] = React . useState ( false ) ;
115+
116+ // Create a ref for the component root element
117+ const itemRef = React . useRef < HTMLDivElement > ( null ) ;
118+
119+ // Create refs to track category changes for animations
120+ const prevCategoryRef = React . useRef < string | null > ( null ) ;
115121
116122 // Use simple primitive values to store original state
117123 // This way we avoid object reference issues
@@ -169,6 +175,34 @@ const StatementItem: React.FC<StatementItemProps> = ({
169175 }
170176 // eslint-disable-next-line react-hooks/exhaustive-deps
171177 } , [ statement , isEditing ] ) ;
178+
179+ // Dedicated effect for scrolling when needed
180+ useEffect ( ( ) => {
181+ // Check if this statement was updated with a category change (flagged by EditStatementModal)
182+ if ( isEditing && ( statement as any ) . _needsScroll ) {
183+ console . log ( 'Statement flagged for scrolling:' , statement . id ) ;
184+
185+ // Use a longer delay to ensure the DOM has fully updated
186+ const timer = setTimeout ( ( ) => {
187+ if ( itemRef . current ) {
188+ console . log ( 'Executing scroll to element' ) ;
189+ // Force scroll to this element
190+ itemRef . current . scrollIntoView ( {
191+ behavior : 'smooth' ,
192+ block : 'center'
193+ } ) ;
194+ console . log ( 'Scroll instruction sent' ) ;
195+ }
196+ } , 500 ) ;
197+
198+ return ( ) => clearTimeout ( timer ) ;
199+ }
200+
201+ // Keep reference updated for category change tracking
202+ prevCategoryRef . current = statement . category ;
203+ // Check this effect whenever the statement reference changes
204+ // eslint-disable-next-line react-hooks/exhaustive-deps
205+ } , [ statement , isEditing ] ) ;
172206
173207 // Helper function to normalize category values for comparison
174208 const normalizeCategoryForComparison = (
@@ -226,7 +260,10 @@ const StatementItem: React.FC<StatementItemProps> = ({
226260
227261 if ( isEditing ) {
228262 return (
229- < div className = 'bg-gray-100 p-3 rounded-lg shadow' >
263+ < div
264+ ref = { itemRef }
265+ id = { `statement-${ statement . id } ` }
266+ className = 'bg-gray-100 p-3 rounded-lg shadow' >
230267 { /* Desktop layout - horizontal row */ }
231268 < div className = 'hidden md:flex md:items-center md:space-x-2' >
232269 { /* Privacy toggle button */ }
@@ -614,6 +651,8 @@ const StatementItem: React.FC<StatementItemProps> = ({
614651 // Static view when not in editing mode.
615652 return (
616653 < div
654+ ref = { itemRef }
655+ id = { `statement-${ statement . id } ` }
617656 className = { `border rounded-md p-3 space-y-2 relative ${
618657 statement . isResolved
619658 ? 'bg-gray-100 border-gray-300 opacity-80'
0 commit comments