@@ -54,8 +54,11 @@ function AllRollingContent() {
5454 const { setHeaderData } = useDispatch ( WIZARD_STORE_NAMESPACE ) ;
5555 const [ data , setData ] = useState < RollingContent [ ] > ( ROLLING_CONTENTS ) ;
5656 const [ view , setView ] = useState < View > ( DEFAULT_VIEW ) ;
57- const [ managingEntriesFor , setManagingEntriesFor ] = useState < RollingContent | null > ( null ) ;
58- const [ addingEntryFor , setAddingEntryFor ] = useState < RollingContent | null > ( null ) ;
57+ const [ managingEntriesForId , setManagingEntriesForId ] = useState < number | null > ( null ) ;
58+ const [ addingEntryForId , setAddingEntryForId ] = useState < number | null > ( null ) ;
59+
60+ const managingEntriesFor = managingEntriesForId === null ? null : data . find ( r => r . id === managingEntriesForId ) ?? null ;
61+ const addingEntryFor = addingEntryForId === null ? null : data . find ( r => r . id === addingEntryForId ) ?? null ;
5962
6063 useEffect ( ( ) => {
6164 setHeaderData ( {
@@ -104,10 +107,10 @@ function AllRollingContent() {
104107 render : ( { item } ) => (
105108 < div style = { { display : 'flex' , alignItems : 'center' , gap : 8 } } >
106109 < span > { item . entries . length } </ span >
107- < Button variant = "secondary" size = "small" onClick = { ( ) => setManagingEntriesFor ( item ) } >
110+ < Button variant = "secondary" size = "small" onClick = { ( ) => setManagingEntriesForId ( item . id ) } >
108111 { __ ( 'Manage' , 'newspack-plugin' ) }
109112 </ Button >
110- < Button variant = "secondary" size = "small" onClick = { ( ) => setAddingEntryFor ( item ) } >
113+ < Button variant = "secondary" size = "small" onClick = { ( ) => setAddingEntryForId ( item . id ) } >
111114 { __ ( 'Add' , 'newspack-plugin' ) }
112115 </ Button >
113116 </ div >
@@ -118,7 +121,7 @@ function AllRollingContent() {
118121 label : __ ( 'Last updated' , 'newspack-plugin' ) ,
119122 getValue : ( { item } ) => {
120123 if ( item . entries . length === 0 ) {
121- return '' ;
124+ return 0 ;
122125 }
123126 return Math . max ( ...item . entries . map ( e => new Date ( e . date ) . getTime ( ) ) ) ;
124127 } ,
@@ -199,10 +202,10 @@ function AllRollingContent() {
199202 onEntriesChange = { nextEntries =>
200203 setData ( prev => prev . map ( r => ( r . id === managingEntriesFor . id ? { ...r , entries : nextEntries } : r ) ) )
201204 }
202- onClose = { ( ) => setManagingEntriesFor ( null ) }
205+ onClose = { ( ) => setManagingEntriesForId ( null ) }
203206 />
204207 ) }
205- { addingEntryFor && < AddEntryInfoModal parentTitle = { addingEntryFor . title } onClose = { ( ) => setAddingEntryFor ( null ) } /> }
208+ { addingEntryFor && < AddEntryInfoModal parentTitle = { addingEntryFor . title } onClose = { ( ) => setAddingEntryForId ( null ) } /> }
206209 </ >
207210 ) ;
208211}
0 commit comments