@@ -204,6 +204,7 @@ <h2 id="stats-month-year" class="text-lg font-bold text-white capitalize"></h2>
204204 currentList : null ,
205205 shoppingList : [ ] ,
206206 statDate : new Date ( ) ,
207+ deleteTimeout : null ,
207208
208209 init : async ( ) => {
209210 await app . renderDashboard ( ) ;
@@ -322,20 +323,24 @@ <h2 id="stats-month-year" class="text-lg font-bold text-white capitalize"></h2>
322323 nameInput . oninput = ( e ) => app . currentList . name = e . target . value ;
323324
324325 const ul = tpl . getElementById ( 'editor-items' ) ;
325- app . currentList . items . forEach ( ( item , idx ) => {
326+ // Filter out null/undefined items and ensure they have required properties
327+ const validItems = app . currentList . items . filter ( item => item && typeof item . name === 'string' ) ;
328+ validItems . forEach ( ( item , idx ) => {
326329 const li = document . createElement ( 'li' ) ;
327330 li . className = "bg-dark-800 p-3 rounded-xl flex justify-between items-center border border-gray-700" ;
328331 const button = document . createElement ( 'button' ) ;
329332 button . className = "text-gray-500 hover:text-red-400 touch-manipulation" ;
330333 button . innerHTML = '<i class="fa-solid fa-xmark"></i>' ;
331- button . onclick = ( e ) => {
334+ button . addEventListener ( 'click' , ( e ) => {
332335 e . stopPropagation ( ) ;
336+ e . preventDefault ( ) ;
333337 app . removeItem ( idx ) ;
334- } ;
335- button . ontouchstart = ( e ) => {
338+ } ) ;
339+ button . addEventListener ( 'touchstart' , ( e ) => {
336340 e . stopPropagation ( ) ;
341+ e . preventDefault ( ) ;
337342 app . removeItem ( idx ) ;
338- } ;
343+ } , { passive : false } ) ;
339344 li . innerHTML = `<span>${ item . name } </span>` ;
340345 li . appendChild ( button ) ;
341346 ul . appendChild ( li ) ;
@@ -368,9 +373,27 @@ <h2 id="stats-month-year" class="text-lg font-bold text-white capitalize"></h2>
368373 app . renderEditor ( ) ;
369374 } ,
370375
371- removeItem : ( index ) => {
372- app . currentList . items . splice ( index , 1 ) ;
376+ removeItem : ( filteredIndex ) => {
377+ // Prevent multiple rapid deletions
378+ if ( app . deleteTimeout ) return ;
379+
380+ // Find the actual item in the original array
381+ const validItems = app . currentList . items . filter ( item => item && typeof item . name === 'string' ) ;
382+ const itemToRemove = validItems [ filteredIndex ] ;
383+
384+ if ( itemToRemove ) {
385+ const originalIndex = app . currentList . items . indexOf ( itemToRemove ) ;
386+ if ( originalIndex !== - 1 ) {
387+ app . currentList . items . splice ( originalIndex , 1 ) ;
388+ }
389+ }
390+
373391 app . renderEditor ( ) ;
392+
393+ // Add small delay to prevent accidental multiple deletions
394+ app . deleteTimeout = setTimeout ( ( ) => {
395+ app . deleteTimeout = null ;
396+ } , 300 ) ;
374397 } ,
375398
376399 saveOnly : async ( ) => {
0 commit comments