From 8fd09d5cc5b24a5ba72c7a5cf0a28b559e177576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dvo=C5=99=C3=A1k?= <150935816+Dvorinka@users.noreply.github.com> Date: Fri, 23 May 2025 10:09:18 +0200 Subject: [PATCH] Add files via upload --- kontakt/index.html | 66 ++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/kontakt/index.html b/kontakt/index.html index dd68e05..4592d48 100644 --- a/kontakt/index.html +++ b/kontakt/index.html @@ -61,13 +61,13 @@ @@ -174,6 +174,25 @@ function showContactsList() { document.getElementById('contactsList').classList.remove('hidden'); document.getElementById('error').classList.add('hidden'); + + // Show default tab (main contacts) if none active + const activeBtn = document.querySelector('.switcher-btn.active'); + if (!activeBtn) { + document.querySelector('.switcher-btn[data-type="main"]').classList.add('active'); + } + + filterContacts(); + } + + function switchTab(btn) { + // Remove active class from all buttons + document.querySelectorAll('.switcher-btn').forEach(b => b.classList.remove('active')); + + // Add active class to clicked button + btn.classList.add('active'); + + // Filter and display contacts + filterContacts(); } function showError(message) { @@ -202,25 +221,15 @@ function filterContacts() { const query = document.getElementById('searchInput').value.toLowerCase().trim(); - const activeBtn = document.querySelector('.switcher-btn.active'); + const activeTab = document.querySelector('.switcher-btn.active')?.dataset.type || 'main'; - if (!activeBtn) { - // Default to main contacts if no active button found - return displayContacts(currentData.Contacts, query); - } + // Combine all contacts for searching + let allContacts = [...currentData.Contacts, ...currentData.InternalContacts]; + let filteredContacts = allContacts; - const activeTab = activeBtn.dataset.type; - let contacts = []; - - if (activeTab === 'main') { - contacts = [...currentData.Contacts]; - } else if (activeTab === 'internal') { - contacts = [...currentData.InternalContacts]; - } - - // Apply search filter + // Apply search filter if query exists if (query) { - contacts = contacts.filter(contact => + filteredContacts = allContacts.filter(contact => (contact.name && contact.name.toLowerCase().includes(query)) || (contact.position && contact.position.toLowerCase().includes(query)) || (contact.phone && contact.phone.replace(/\s/g, '').includes(query.replace(/\s/g, ''))) || @@ -228,7 +237,11 @@ ); } - displayContacts(contacts, query); + // Then filter by active tab if not searching + let contactsToShow = query ? filteredContacts : + (activeTab === 'main' ? currentData.Contacts : currentData.InternalContacts); + + displayContacts(contactsToShow, query); } function highlightText(text, query) { @@ -315,21 +328,6 @@ `; } - function showContacts(type) { - // Update switcher buttons - document.querySelectorAll('.switcher-btn').forEach(btn => { - btn.classList.remove('active', 'bg-blue-600', 'text-white'); - btn.classList.add('bg-gray-100', 'text-gray-700'); - if (btn.dataset.type === type) { - btn.classList.add('active', 'bg-blue-600', 'text-white'); - btn.classList.remove('bg-gray-100', 'text-gray-700'); - } - }); - - // Filter contacts for the selected type - filterContacts(); - } - async function reloadContacts() { const btn = document.getElementById('reloadBtn'); const originalText = btn.innerHTML;