ALL tab/table on bids page. + Fix bids export.

This commit is contained in:
gerlofvanek
2025-05-09 20:43:31 +02:00
parent b3c0ad7e9c
commit e7b47486f5
4 changed files with 720 additions and 397 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -4,17 +4,18 @@ const BidExporter = {
return 'No data to export';
}
const isSent = type === 'sent';
const isAllTab = type === 'all';
const headers = [
'Date/Time',
'Bid ID',
'Offer ID',
'From Address',
isSent ? 'You Send Amount' : 'You Receive Amount',
isSent ? 'You Send Coin' : 'You Receive Coin',
isSent ? 'You Receive Amount' : 'You Send Amount',
isSent ? 'You Receive Coin' : 'You Send Coin',
...(isAllTab ? ['Type'] : []),
'You Send Amount',
'You Send Coin',
'You Receive Amount',
'You Receive Coin',
'Status',
'Created At',
'Expires At'
@@ -23,11 +24,13 @@ const BidExporter = {
let csvContent = headers.join(',') + '\n';
bids.forEach(bid => {
const isSent = isAllTab ? (bid.source === 'sent') : (type === 'sent');
const row = [
`"${formatTime(bid.created_at)}"`,
`"${bid.bid_id}"`,
`"${bid.offer_id}"`,
`"${bid.addr_from}"`,
...(isAllTab ? [`"${bid.source}"`] : []),
isSent ? bid.amount_from : bid.amount_to,
`"${isSent ? bid.coin_from : bid.coin_to}"`,
isSent ? bid.amount_to : bid.amount_from,
@@ -103,6 +106,15 @@ const BidExporter = {
document.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {
if (typeof state !== 'undefined' && typeof EventManager !== 'undefined') {
const exportAllButton = document.getElementById('exportAllBids');
if (exportAllButton) {
EventManager.add(exportAllButton, 'click', (e) => {
e.preventDefault();
state.currentTab = 'all';
BidExporter.exportCurrentView();
});
}
const exportSentButton = document.getElementById('exportSentBids');
if (exportSentButton) {
EventManager.add(exportSentButton, 'click', (e) => {
@@ -128,9 +140,14 @@ const originalCleanup = window.cleanup || function(){};
window.cleanup = function() {
originalCleanup();
const exportAllButton = document.getElementById('exportAllBids');
const exportSentButton = document.getElementById('exportSentBids');
const exportReceivedButton = document.getElementById('exportReceivedBids');
if (exportAllButton && typeof EventManager !== 'undefined') {
EventManager.remove(exportAllButton, 'click');
}
if (exportSentButton && typeof EventManager !== 'undefined') {
EventManager.remove(exportSentButton, 'click');
}

View File

@@ -1,36 +1,39 @@
(function() {
'use strict';
const originalOnload = window.onload;
document.addEventListener('DOMContentLoaded', initBidsTabNavigation);
window.addEventListener('load', handleHashChange);
window.addEventListener('hashchange', preventScrollOnHashChange);
window.onload = function() {
if (typeof originalOnload === 'function') {
originalOnload();
}
setTimeout(function() {
initBidsTabNavigation();
handleInitialNavigation();
}, 100);
};
document.addEventListener('DOMContentLoaded', function() {
initBidsTabNavigation();
});
window.addEventListener('hashchange', handleHashChange);
window.bidsTabNavigationInitialized = false;
function initBidsTabNavigation() {
const sentTabButton = document.getElementById('sent-tab');
const receivedTabButton = document.getElementById('received-tab');
if (!sentTabButton || !receivedTabButton) {
if (window.bidsTabNavigationInitialized) {
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);
navigateToTabDirectly(targetTabId);
} else {
localStorage.setItem('bidsTabToActivate', targetTabId.replace('#', ''));
window.location.href = '/bids';
@@ -39,35 +42,28 @@
});
});
const tabToActivate = localStorage.getItem('bidsTabToActivate');
if (tabToActivate) {
localStorage.removeItem('bidsTabToActivate');
activateTab('#' + tabToActivate);
} else if (window.location.pathname === '/bids' && !window.location.hash) {
activateTab('#sent');
}
window.bidsTabNavigationInitialized = true;
console.log('Bids tab navigation initialized');
}
function preventScrollOnHashChange(e) {
function handleInitialNavigation() {
if (window.location.pathname !== '/bids') {
return;
}
const tabToActivate = localStorage.getItem('bidsTabToActivate');
e.preventDefault();
const oldScrollPosition = window.scrollY;
const hash = window.location.hash;
if (hash) {
const tabId = `#${hash.replace('#', '')}`;
activateTab(tabId);
if (tabToActivate) {
//console.log('Activating tab from localStorage:', tabToActivate);
localStorage.removeItem('bidsTabToActivate');
activateTabWithRetry('#' + tabToActivate);
} else if (window.location.hash) {
//console.log('Activating tab from hash:', window.location.hash);
activateTabWithRetry(window.location.hash);
} else {
activateTab('#sent');
//console.log('Activating default tab: #all');
activateTabWithRetry('#all');
}
setTimeout(function() {
window.scrollTo(0, oldScrollPosition);
}, 0);
}
function handleHashChange() {
@@ -75,50 +71,141 @@
return;
}
const oldScrollPosition = window.scrollY;
const hash = window.location.hash;
if (hash) {
const tabId = `#${hash.replace('#', '')}`;
activateTab(tabId);
//console.log('Hash changed, activating tab:', hash);
activateTabWithRetry(hash);
} else {
activateTab('#sent');
//console.log('Hash cleared, activating default tab: #all');
activateTabWithRetry('#all');
}
}
function activateTabWithRetry(tabId, retryCount = 0) {
const normalizedTabId = tabId.startsWith('#') ? tabId : '#' + tabId;
if (normalizedTabId !== '#all' && normalizedTabId !== '#sent' && normalizedTabId !== '#received') {
//console.log('Invalid tab ID, defaulting to #all');
activateTabWithRetry('#all');
return;
}
const tabButtonId = normalizedTabId === '#all' ? 'all-tab' :
(normalizedTabId === '#sent' ? 'sent-tab' : 'received-tab');
const tabButton = document.getElementById(tabButtonId);
if (!tabButton) {
if (retryCount < 5) {
//console.log('Tab button not found, retrying...', retryCount + 1);
setTimeout(() => {
activateTabWithRetry(normalizedTabId, retryCount + 1);
}, 100);
} else {
//console.error('Failed to find tab button after retries');
}
return;
}
//console.log('Activating tab:', normalizedTabId);
tabButton.click();
if (window.Tabs) {
const tabsEl = document.querySelector('[data-tabs-toggle="#bidstab"]');
if (tabsEl) {
const allTabs = Array.from(tabsEl.querySelectorAll('[role="tab"]'));
const targetTab = allTabs.find(tab => tab.getAttribute('data-tabs-target') === normalizedTabId);
if (targetTab) {
allTabs.forEach(tab => {
tab.setAttribute('aria-selected', tab === targetTab ? 'true' : 'false');
if (tab === targetTab) {
tab.classList.add('bg-gray-100', 'dark:bg-gray-600', 'text-gray-900', 'dark:text-white');
tab.classList.remove('hover:text-gray-600', 'hover:bg-gray-50', 'dark:hover:bg-gray-500');
} else {
tab.classList.remove('bg-gray-100', 'dark:bg-gray-600', 'text-gray-900', 'dark:text-white');
tab.classList.add('hover:text-gray-600', 'hover:bg-gray-50', 'dark:hover:bg-gray-500');
}
});
const allContent = document.getElementById('all');
const sentContent = document.getElementById('sent');
const receivedContent = document.getElementById('received');
if (allContent && sentContent && receivedContent) {
allContent.classList.toggle('hidden', normalizedTabId !== '#all');
sentContent.classList.toggle('hidden', normalizedTabId !== '#sent');
receivedContent.classList.toggle('hidden', normalizedTabId !== '#received');
}
}
}
}
const allPanel = document.getElementById('all');
const sentPanel = document.getElementById('sent');
const receivedPanel = document.getElementById('received');
if (allPanel && sentPanel && receivedPanel) {
allPanel.classList.toggle('hidden', normalizedTabId !== '#all');
sentPanel.classList.toggle('hidden', normalizedTabId !== '#sent');
receivedPanel.classList.toggle('hidden', normalizedTabId !== '#received');
}
const newHash = normalizedTabId.replace('#', '');
if (window.location.hash !== '#' + newHash) {
history.replaceState(null, null, '#' + newHash);
}
triggerDataLoad(normalizedTabId);
}
function triggerDataLoad(tabId) {
setTimeout(() => {
if (window.state) {
window.state.currentTab = tabId === '#all' ? 'all' :
(tabId === '#sent' ? 'sent' : 'received');
if (typeof window.updateBidsTable === 'function') {
//console.log('Triggering data load for', tabId);
window.updateBidsTable();
}
}
const event = new CustomEvent('tabactivated', {
detail: {
tabId: tabId,
type: tabId === '#all' ? 'all' :
(tabId === '#sent' ? 'sent' : 'received')
}
});
document.dispatchEvent(event);
if (window.TooltipManager && typeof window.TooltipManager.cleanup === 'function') {
setTimeout(() => {
window.TooltipManager.cleanup();
if (typeof window.initializeTooltips === 'function') {
window.initializeTooltips();
}
}, 200);
}
}, 100);
}
function navigateToTabDirectly(tabId) {
const oldScrollPosition = window.scrollY;
activateTabWithRetry(tabId);
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);
navigateToTabDirectly('#' + tabId);
} else {
localStorage.setItem('bidsTabToActivate', tabId);
window.location.href = '/bids';