@@ -112,20 +112,28 @@ const StatementItem: React.FC<StatementItemProps> = ({
112112 originalCategory : externalOriginalCategory , // Get original category from parent
113113} ) => {
114114 const [ isActionsExpanded , setIsActionsExpanded ] = React . useState ( false ) ;
115-
115+
116116 // Create a ref for the component root element
117117 const itemRef = React . useRef < HTMLDivElement > ( null ) ;
118-
118+
119119 // Create refs to track category changes for animations
120120 const prevCategoryRef = React . useRef < string | null > ( null ) ;
121121
122122 // Use simple primitive values to store original state
123123 // This way we avoid object reference issues
124- const [ originalCategory , setOriginalCategory ] = React . useState < string | null > ( null ) ;
125- const [ originalSubject , setOriginalSubject ] = React . useState < string | null > ( null ) ;
124+ const [ originalCategory , setOriginalCategory ] = React . useState < string | null > (
125+ null
126+ ) ;
127+ const [ originalSubject , setOriginalSubject ] = React . useState < string | null > (
128+ null
129+ ) ;
126130 const [ originalVerb , setOriginalVerb ] = React . useState < string | null > ( null ) ;
127- const [ originalObject , setOriginalObject ] = React . useState < string | null > ( null ) ;
128- const [ originalPrivacy , setOriginalPrivacy ] = React . useState < boolean | null > ( null ) ;
131+ const [ originalObject , setOriginalObject ] = React . useState < string | null > (
132+ null
133+ ) ;
134+ const [ originalPrivacy , setOriginalPrivacy ] = React . useState < boolean | null > (
135+ null
136+ ) ;
129137
130138 // Local "draft" state to track current modifications
131139 const [ draft , setDraft ] = React . useState < Entry > ( statement ) ;
@@ -141,7 +149,7 @@ const StatementItem: React.FC<StatementItemProps> = ({
141149 // Use the external original category from parent if available, otherwise use the current category
142150 const originalCategoryValue =
143151 externalOriginalCategory ||
144- ( statement . category ? String ( statement . category ) : "" ) ;
152+ ( statement . category ? String ( statement . category ) : '' ) ;
145153
146154 // Set it in the local state for immediate use in comparison
147155 setOriginalCategory ( originalCategoryValue ) ;
@@ -173,35 +181,33 @@ const StatementItem: React.FC<StatementItemProps> = ({
173181 // Keep draft updated with latest changes from the statement
174182 setDraft ( JSON . parse ( JSON . stringify ( statement ) ) ) ;
175183 }
176- // eslint-disable-next-line react-hooks/exhaustive-deps
177184 } , [ statement , isEditing ] ) ;
178-
185+
179186 // Dedicated effect for scrolling when needed
180187 useEffect ( ( ) => {
181188 // Check if this statement was updated with a category change (flagged by EditStatementModal)
182189 if ( isEditing && statement . _needsScroll ) {
183190 console . log ( 'Statement flagged for scrolling:' , statement . id ) ;
184-
191+
185192 // Use a longer delay to ensure the DOM has fully updated
186193 const timer = setTimeout ( ( ) => {
187194 if ( itemRef . current ) {
188195 console . log ( 'Executing scroll to element' ) ;
189196 // Force scroll to this element
190- itemRef . current . scrollIntoView ( {
191- behavior : 'smooth' ,
192- block : 'center'
197+ itemRef . current . scrollIntoView ( {
198+ behavior : 'smooth' ,
199+ block : 'center' ,
193200 } ) ;
194201 console . log ( 'Scroll instruction sent' ) ;
195202 }
196203 } , 500 ) ;
197-
204+
198205 return ( ) => clearTimeout ( timer ) ;
199206 }
200-
207+
201208 // Keep reference updated for category change tracking
202209 prevCategoryRef . current = statement . category ;
203- // Check this effect whenever the statement reference changes
204- // eslint-disable-next-line react-hooks/exhaustive-deps
210+ // Check this effect whenever the statement reference changes
205211 } , [ statement , isEditing ] ) ;
206212
207213 // Helper function to normalize category values for comparison
@@ -232,8 +238,9 @@ const StatementItem: React.FC<StatementItemProps> = ({
232238 if ( isEditing ) {
233239 // Use the external original category if available, otherwise use local state
234240 // This ensures consistent comparison even after component remounts
235- const effectiveOriginalCategory = externalOriginalCategory || originalCategory ;
236-
241+ const effectiveOriginalCategory =
242+ externalOriginalCategory || originalCategory ;
243+
237244 if ( effectiveOriginalCategory !== null || originalCategory !== null ) {
238245 // Compare current draft with original primitive values
239246 hasSubjectChanged = draft . atoms . subject !== originalSubject ;
@@ -243,7 +250,9 @@ const StatementItem: React.FC<StatementItemProps> = ({
243250
244251 // Normalize categories for comparison
245252 const draftCategory = normalizeCategoryForComparison ( draft . category ) ;
246- const originalCategoryNormalized = normalizeCategoryForComparison ( effectiveOriginalCategory ) ;
253+ const originalCategoryNormalized = normalizeCategoryForComparison (
254+ effectiveOriginalCategory
255+ ) ;
247256
248257 // Compare normalized categories
249258 hasCategoryChanged = draftCategory !== originalCategoryNormalized ;
@@ -260,10 +269,11 @@ const StatementItem: React.FC<StatementItemProps> = ({
260269
261270 if ( isEditing ) {
262271 return (
263- < div
264- ref = { itemRef }
272+ < div
273+ ref = { itemRef }
265274 id = { `statement-${ statement . id } ` }
266- className = 'bg-gray-100 p-3 rounded-lg shadow' >
275+ className = 'bg-gray-100 p-3 rounded-lg shadow'
276+ >
267277 { /* Desktop layout - horizontal row */ }
268278 < div className = 'hidden md:flex md:items-center md:space-x-2' >
269279 { /* Privacy toggle button */ }
@@ -789,4 +799,4 @@ const StatementItem: React.FC<StatementItemProps> = ({
789799 ) ;
790800} ;
791801
792- export default StatementItem ;
802+ export default StatementItem ;
0 commit comments