/** * @fileoverview Manages the conversations list functionality. * This file handles: * - Conversation search with debounced input * - Search form submission * - Clear filter functionality */ /** * Creates a debounced version of a function that delays its execution * until after a specified wait time has elapsed since the last time it was invoked. * This helps prevent excessive form submissions during rapid user input. * @function * @param {Function} func - The function to debounce * @param {number} wait - The number of milliseconds to delay (300ms default for search) * @returns {Function} A debounced version of the provided function */ function debounce(func, wait) { let timeout; return function(...args) { clearTimeout(timeout); timeout = setTimeout(() => func.apply(this, args), wait); }; } /** * Initializes the conversations list functionality when the DOM is loaded. * Sets up: * - Search input with debounced form submission (300ms delay) * - Clear filter button to reset search and refresh results * @function */ document.addEventListener('DOMContentLoaded', function() { const searchInput = document.getElementById('conversationSearchInput'); const form = document.getElementById('conversationFilterForm'); if (searchInput && form) { searchInput.addEventListener('input', debounce(function() { form.submit(); }, 300)); } // Clear button logic const clearBtn = document.getElementById('clearConversationsFilter'); if (clearBtn && searchInput) { clearBtn.addEventListener('click', function() { searchInput.value = ''; form.submit(); }); } });