diff --git a/www/index.html b/www/index.html index 52d1e691..6c4c0d4b 100644 --- a/www/index.html +++ b/www/index.html @@ -288,8 +288,9 @@

- + +

Login to show recent activity

@@ -306,6 +307,29 @@

+ + diff --git a/www/js/index.js b/www/js/index.js index db1f95d2..badc1443 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -4,11 +4,21 @@ document.addEventListener('DOMContentLoaded', () => { const populateUserHistoryTable = async () => { const numEntries = 5; - if (CURRENT_USER) { - try { - const data = await apiCallsMixin.fetchUserHistoryEntries(numEntries); - const template = document.querySelector('#user-history-row'); + // Load the spinner template + const spinnerTemplate = document.querySelector('#user-history-loading'); + document.querySelector('#user-history-table-tbody').innerHTML = ''; + document.querySelector('#user-history-table-tbody').appendChild(spinnerTemplate.content.cloneNode(true)); + + try { + const data = await apiCallsMixin.fetchUserHistoryEntries(numEntries); + const template = document.querySelector('#user-history-row'); + document.querySelector('#user-history-table-tbody').innerHTML = ''; + + if (data.length === 0) { + const noHistoryTemplate = document.querySelector('#user-history-no-entries'); + document.querySelector('#user-history-table-tbody').appendChild(noHistoryTemplate.content.cloneNode(true)); + } else { for (const entry of data) { const row = template.content.cloneNode(true); @@ -21,16 +31,15 @@ const populateUserHistoryTable = async () => { row.querySelector('.url').setAttribute('href', entry.url); document.querySelector('#user-history-table-tbody').appendChild(row); - }; - } catch (error) { - console.error(error); + } } - } else { - console.log('No user logged in. Clearing user history table.'); - document.querySelector('#user-history-table-tbody').innerHTML = ''; + } catch (error) { + console.error(error); } } const handlePageSpecificLoginUIUpdates = async (event) => { - populateUserHistoryTable(); + if (CURRENT_USER.session_id) { + populateUserHistoryTable(); + } }