diff --git a/basicswap/static/js/bids_sentreceived.js b/basicswap/static/js/bids_sentreceived.js index 52b91e5..3ad6af4 100644 --- a/basicswap/static/js/bids_sentreceived.js +++ b/basicswap/static/js/bids_sentreceived.js @@ -1925,3 +1925,74 @@ if (document.readyState === 'loading') { } else { initialize(); } + +(function() { + function handleBidsTabFromHash() { + if (window.location.pathname !== '/bids') { + return; + } + + const hash = window.location.hash; + + if (hash) { + const tabName = hash.substring(1); + let tabId; + switch (tabName.toLowerCase()) { + case 'sent': + tabId = '#sent'; + break; + case 'received': + tabId = '#received'; + break; + default: + tabId = '#sent'; + } + switchTab(tabId); + } else { + switchTab('#sent'); + } + } + + function switchTab(tabId) { + const targetTabBtn = document.querySelector(`[data-tabs-target="${tabId}"]`); + if (targetTabBtn) { + targetTabBtn.click(); + } + } + + function setupBidsTabNavigation() { + handleBidsTabFromHash(); + window.addEventListener('hashchange', handleBidsTabFromHash); + const originalSwitchTab = window.switchTab || null; + + window.switchTab = function(tabId) { + const newTabName = tabId.replace('#', ''); + if (window.location.hash !== `#${newTabName}`) { + history.replaceState(null, null, `#${newTabName}`); + } + if (originalSwitchTab && typeof originalSwitchTab === 'function') { + originalSwitchTab(tabId); + } else { + const targetTabBtn = document.querySelector(`[data-tabs-target="${tabId}"]`); + if (targetTabBtn) { + targetTabBtn.click(); + } + } + }; + + const tabButtons = document.querySelectorAll('[data-tabs-target]'); + tabButtons.forEach(btn => { + btn.addEventListener('click', function() { + const tabId = this.getAttribute('data-tabs-target'); + const tabName = tabId.replace('#', ''); + history.replaceState(null, null, `#${tabName}`); + }); + }); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', setupBidsTabNavigation); + } else { + setupBidsTabNavigation(); + } +})(); diff --git a/basicswap/static/js/pricechart.js b/basicswap/static/js/pricechart.js index 015f579..4c0906c 100644 --- a/basicswap/static/js/pricechart.js +++ b/basicswap/static/js/pricechart.js @@ -1518,7 +1518,7 @@ refreshAllData: async function() { } }, 1000); } - console.log(`Price refresh completed at ${new Date().toLocaleTimeString()}. Updated ${window.config.coins.length - failedCoins.length}/${window.config.coins.length} coins.`); + //console.log(`Price refresh completed at ${new Date().toLocaleTimeString()}. Updated ${window.config.coins.length - failedCoins.length}/${window.config.coins.length} coins.`); } catch (error) { console.error('Critical error during refresh:', error); diff --git a/basicswap/static/js/ui/bids-tab-navigation.js b/basicswap/static/js/ui/bids-tab-navigation.js new file mode 100644 index 0000000..d1acb93 --- /dev/null +++ b/basicswap/static/js/ui/bids-tab-navigation.js @@ -0,0 +1,127 @@ +(function() { + 'use strict'; + + document.addEventListener('DOMContentLoaded', initBidsTabNavigation); + window.addEventListener('load', handleHashChange); + window.addEventListener('hashchange', preventScrollOnHashChange); + + function initBidsTabNavigation() { + const sentTabButton = document.getElementById('sent-tab'); + const receivedTabButton = document.getElementById('received-tab'); + + if (!sentTabButton || !receivedTabButton) { + return; + } + + document.querySelectorAll('.bids-tab-link').forEach(link => { + link.addEventListener('click', function(e) { + e.preventDefault(); + e.stopPropagation(); + + const targetTabId = this.getAttribute('data-tab-target'); + + if (targetTabId) { + if (window.location.pathname === '/bids') { + const oldScrollPosition = window.scrollY; + + activateTab(targetTabId); + + setTimeout(function() { + window.scrollTo(0, oldScrollPosition); + + history.replaceState(null, null, '#' + targetTabId.replace('#', '')); + }, 0); + } else { + localStorage.setItem('bidsTabToActivate', targetTabId.replace('#', '')); + window.location.href = '/bids'; + } + } + }); + }); + + const tabToActivate = localStorage.getItem('bidsTabToActivate'); + if (tabToActivate) { + localStorage.removeItem('bidsTabToActivate'); + activateTab('#' + tabToActivate); + } else if (window.location.pathname === '/bids' && !window.location.hash) { + activateTab('#sent'); + } + } + + function preventScrollOnHashChange(e) { + if (window.location.pathname !== '/bids') { + return; + } + + e.preventDefault(); + + const oldScrollPosition = window.scrollY; + const hash = window.location.hash; + + if (hash) { + const tabId = `#${hash.replace('#', '')}`; + activateTab(tabId); + } else { + activateTab('#sent'); + } + + setTimeout(function() { + window.scrollTo(0, oldScrollPosition); + }, 0); + } + + function handleHashChange() { + if (window.location.pathname !== '/bids') { + return; + } + + const oldScrollPosition = window.scrollY; + const hash = window.location.hash; + + if (hash) { + const tabId = `#${hash.replace('#', '')}`; + activateTab(tabId); + } else { + activateTab('#sent'); + } + + setTimeout(function() { + window.scrollTo(0, oldScrollPosition); + }, 0); + } + + function activateTab(tabId) { + if (tabId !== '#sent' && tabId !== '#received') { + tabId = '#sent'; + } + + const tabButtonId = tabId === '#sent' ? 'sent-tab' : 'received-tab'; + const tabButton = document.getElementById(tabButtonId); + + if (tabButton) { + const oldScrollPosition = window.scrollY; + + tabButton.click(); + + setTimeout(function() { + window.scrollTo(0, oldScrollPosition); + }, 0); + } + } + + window.navigateToBidsTab = function(tabId) { + if (window.location.pathname === '/bids') { + const oldScrollPosition = window.scrollY; + + activateTab('#' + (tabId === 'sent' || tabId === 'received' ? tabId : 'sent')); + + setTimeout(function() { + window.scrollTo(0, oldScrollPosition); + history.replaceState(null, null, '#' + tabId); + }, 0); + } else { + localStorage.setItem('bidsTabToActivate', tabId); + window.location.href = '/bids'; + } + }; +})(); diff --git a/basicswap/templates/header.html b/basicswap/templates/header.html index 5b811c5..0f84a8d 100644 --- a/basicswap/templates/header.html +++ b/basicswap/templates/header.html @@ -63,6 +63,7 @@ + @@ -84,6 +85,7 @@ +
Sent bids: {{ sent_bids_count }} ({{ summary.num_sent_active_bids }} active)
-Received bids: {{ received_bids_count }} ({{ summary.num_recv_active_bids }} active)
-Sent bids: {{ sent_bids_count }} ({{ summary.num_sent_active_bids }} active)
+Received bids: {{ received_bids_count }} ({{ summary.num_recv_active_bids }} active)
+