From 6cb777e90cd725ea3e963eb0854936ad6179df0b Mon Sep 17 00:00:00 2001 From: MarekWo Date: Fri, 16 Jan 2026 07:51:00 +0100 Subject: [PATCH] fix: Map buttons not working in contacts page and message bubbles - Add Leaflet CSS/JS and map modal to contacts_base.html - Add showContactOnMap function to contacts.js (contacts page has separate template) - Load contactsGeoCache before messages to ensure Map buttons appear on bubbles Co-Authored-By: Claude Opus 4.5 --- app/static/js/app.js | 6 ++-- app/static/js/contacts.js | 53 ++++++++++++++++++++++++++++++++ app/templates/contacts_base.html | 25 +++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/app/static/js/app.js b/app/static/js/app.js index 55bd495..c6872e7 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -204,6 +204,9 @@ document.addEventListener('DOMContentLoaded', async function() { // This ensures channels are available for checkForUpdates() await loadChannels(); + // Load contacts geo cache BEFORE messages (needed for Map buttons on bubbles) + await loadContactsGeoCache(); + // Now load other data (can run in parallel) loadArchiveList(); loadMessages(); @@ -212,9 +215,6 @@ document.addEventListener('DOMContentLoaded', async function() { updatePendingContactsBadge(); loadStatus(); - // Load contacts geo cache for map buttons on messages - loadContactsGeoCache(); - // Map button in menu const mapBtn = document.getElementById('mapBtn'); if (mapBtn) { diff --git a/app/static/js/contacts.js b/app/static/js/contacts.js index 0d010b4..b72a27f 100644 --- a/app/static/js/contacts.js +++ b/app/static/js/contacts.js @@ -50,6 +50,59 @@ let contactToDelete = null; let sortBy = 'last_advert'; // 'name' or 'last_advert' let sortOrder = 'desc'; // 'asc' or 'desc' +// Map state (Leaflet) +let leafletMap = null; +let markersGroup = null; + +// ============================================================================= +// Leaflet Map Functions +// ============================================================================= + +/** + * Initialize Leaflet map (called once on first modal open) + */ +function initLeafletMap() { + if (leafletMap) return; + + leafletMap = L.map('leafletMap').setView([52.0, 19.0], 6); + + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap' + }).addTo(leafletMap); + + markersGroup = L.layerGroup().addTo(leafletMap); +} + +/** + * Show single contact on map + */ +function showContactOnMap(name, lat, lon) { + const modalEl = document.getElementById('mapModal'); + const modal = new bootstrap.Modal(modalEl); + document.getElementById('mapModalTitle').textContent = name; + + const onShown = function() { + initLeafletMap(); + markersGroup.clearLayers(); + + L.marker([lat, lon]) + .addTo(markersGroup) + .bindPopup(`${name}`) + .openPopup(); + + leafletMap.setView([lat, lon], 13); + leafletMap.invalidateSize(); + + modalEl.removeEventListener('shown.bs.modal', onShown); + }; + + modalEl.addEventListener('shown.bs.modal', onShown); + modal.show(); +} + +// Make showContactOnMap available globally +window.showContactOnMap = showContactOnMap; + // ============================================================================= // Initialization // ============================================================================= diff --git a/app/templates/contacts_base.html b/app/templates/contacts_base.html index 3514668..38a81eb 100644 --- a/app/templates/contacts_base.html +++ b/app/templates/contacts_base.html @@ -17,6 +17,11 @@ + + + @@ -410,9 +415,29 @@ + + + + + +