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