@@ -181,35 +181,25 @@ export function initContractsPage(contracts) {
181181 }
182182 } )
183183
184- // Download button
185- const downloadBtn = document . getElementById ( 'contracts-download' )
186- if ( downloadBtn ) {
187- downloadBtn . addEventListener ( 'click' , ( ) => downloadContracts ( contracts ) )
188- }
189-
190- // Copy to clipboard button
191- const copyBtn = document . getElementById ( 'contracts-copy' )
192- if ( copyBtn ) {
193- copyBtn . addEventListener ( 'click' , ( ) => copyContracts ( contracts ) )
184+ // Replace buttons via clone to remove stale listeners from previous init
185+ function rebindButton ( id , handler ) {
186+ const old = document . getElementById ( id )
187+ if ( ! old ) return
188+ const fresh = old . cloneNode ( true )
189+ old . replaceWith ( fresh )
190+ fresh . addEventListener ( 'click' , handler )
194191 }
195192
196- // Select all
197- const selectAllBtn = document . getElementById ( 'contracts-select-all' )
198- if ( selectAllBtn ) {
199- selectAllBtn . addEventListener ( 'click' , ( ) => {
200- setSelectedContracts ( contracts . map ( ( c ) => c . id ) )
201- initContractsPage ( contracts )
202- } )
203- }
204-
205- // Deselect all
206- const deselectAllBtn = document . getElementById ( 'contracts-deselect-all' )
207- if ( deselectAllBtn ) {
208- deselectAllBtn . addEventListener ( 'click' , ( ) => {
209- setSelectedContracts ( [ ] )
210- initContractsPage ( contracts )
211- } )
212- }
193+ rebindButton ( 'contracts-download' , ( ) => downloadContracts ( contracts ) )
194+ rebindButton ( 'contracts-copy' , ( ) => copyContracts ( contracts ) )
195+ rebindButton ( 'contracts-select-all' , ( ) => {
196+ setSelectedContracts ( contracts . map ( ( c ) => c . id ) )
197+ initContractsPage ( contracts )
198+ } )
199+ rebindButton ( 'contracts-deselect-all' , ( ) => {
200+ setSelectedContracts ( [ ] )
201+ initContractsPage ( contracts )
202+ } )
213203
214204 updateUI ( contracts )
215205}
0 commit comments