Fix: Chart JS

This commit is contained in:
gerlofvanek
2024-10-11 22:35:12 +02:00
parent c6f3c684a8
commit 54983913e1

View File

@@ -866,30 +866,31 @@ const app = {
}, },
init: () => { init: () => {
window.addEventListener('load', async () => { window.addEventListener('load', app.onLoad);
app.loadLastRefreshedTime();
},
onLoad: async () => {
ui.showLoader(); ui.showLoader();
try { try {
volumeToggle.init(); volumeToggle.init();
await app.updateBTCPrice(); await app.updateBTCPrice();
const chartContainer = document.getElementById('coin-chart');
if (chartContainer) {
chartModule.initChart(); chartModule.initChart();
chartModule.showChartLoader(); chartModule.showChartLoader();
} else { } else {
console.warn('Chart container not found, skipping chart initialization'); console.warn('Chart container not found, skipping chart initialization');
} }
for (const coin of config.coins) {
const coinDataPromises = config.coins.map(coin => app.loadCoinData(coin)); await app.loadCoinData(coin);
await Promise.all(coinDataPromises); }
if (chartModule.chart) { if (chartModule.chart) {
config.currentResolution = 'month'; config.currentResolution = 'month';
await chartModule.updateChart('BTC'); await chartModule.updateChart('BTC');
app.updateResolutionButtons('BTC'); app.updateResolutionButtons('BTC');
} }
ui.setActiveContainer('btc-container'); ui.setActiveContainer('btc-container');
// Set up event listeners for coin containers
config.coins.forEach(coin => { config.coins.forEach(coin => {
const container = document.getElementById(`${coin.symbol.toLowerCase()}-container`); const container = document.getElementById(`${coin.symbol.toLowerCase()}-container`);
if (container) { if (container) {
@@ -905,25 +906,20 @@ const app = {
}); });
} }
}); });
app.initializeSelectImages();
app.initAutoRefresh();
const refreshAllButton = document.getElementById('refresh-all'); const refreshAllButton = document.getElementById('refresh-all');
if (refreshAllButton) { if (refreshAllButton) {
refreshAllButton.addEventListener('click', app.refreshAllData); refreshAllButton.addEventListener('click', app.refreshAllData);
} }
app.initializeSelectImages();
const headers = document.querySelectorAll('th'); const headers = document.querySelectorAll('th');
headers.forEach((header, index) => { headers.forEach((header, index) => {
header.addEventListener('click', () => app.sortTable(index, header.classList.contains('disabled'))); header.addEventListener('click', () => app.sortTable(index, header.classList.contains('disabled')));
}); });
const closeErrorButton = document.getElementById('close-error'); const closeErrorButton = document.getElementById('close-error');
if (closeErrorButton) { if (closeErrorButton) {
closeErrorButton.addEventListener('click', ui.hideErrorMessage); closeErrorButton.addEventListener('click', ui.hideErrorMessage);
} }
app.initAutoRefresh();
} catch (error) { } catch (error) {
console.error('Error during initialization:', error); console.error('Error during initialization:', error);
ui.displayErrorMessage('Failed to initialize the dashboard. Please try refreshing the page.'); ui.displayErrorMessage('Failed to initialize the dashboard. Please try refreshing the page.');
@@ -933,8 +929,6 @@ const app = {
chartModule.hideChartLoader(); chartModule.hideChartLoader();
} }
} }
});
app.loadLastRefreshedTime();
}, },
loadCoinData: async (coin) => { loadCoinData: async (coin) => {
@@ -1033,7 +1027,6 @@ const app = {
app.stopAutoRefresh(); app.stopAutoRefresh();
} else { } else {
app.startAutoRefresh(); app.startAutoRefresh();
app.startSpinAnimation();
} }
app.updateAutoRefreshButton(); app.updateAutoRefreshButton();
}, },