Add clickable bid counters in the header that navigate to the sent/received tabs + small fix.

This commit is contained in:
gerlofvanek
2025-05-08 22:31:39 +02:00
parent ece9d7fb4b
commit b3c0ad7e9c
4 changed files with 248 additions and 59 deletions

View File

@@ -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();
}
})();

View File

@@ -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);

View File

@@ -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';
}
};
})();