From 81a861f3fce09b22d3daf6be9593ba86568d09a6 Mon Sep 17 00:00:00 2001 From: Josh Stock Date: Tue, 3 Oct 2023 11:19:45 -0500 Subject: [PATCH 1/3] Refactor reloadData function --- src/components/activitylog.js | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/components/activitylog.js b/src/components/activitylog.js index fc9a5a9fe6..131095262d 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -61,20 +61,13 @@ function renderList(elem, apiClient, result) { } function reloadData(instance, elem, apiClient, startIndex, limit) { - if (startIndex == null) { - startIndex = parseInt(elem.getAttribute('data-activitystartindex') || '0', 10); - } - - limit = limit || parseInt(elem.getAttribute('data-activitylimit') || '7', 10); + startIndex ??= parseInt(elem.getAttribute('data-activitystartindex') || '0', 10); + limit ||= parseInt(elem.getAttribute('data-activitylimit') || '7', 10); const minDate = new Date(); const hasUserId = toBoolean(elem.getAttribute('data-useractivity'), true); - + const dateOffset = hasUserId ? 1 : 7; // one day back if user id, otherwise one week // TODO: Use date-fns - if (hasUserId) { - minDate.setTime(minDate.getTime() - 24 * 60 * 60 * 1000); // one day back - } else { - minDate.setTime(minDate.getTime() - 7 * 24 * 60 * 60 * 1000); // one week back - } + minDate.setTime(minDate.getTime() - dateOffset * 24 * 60 * 60 * 1000); ApiClient.getJSON(ApiClient.getUrl('System/ActivityLog/Entries', { startIndex: startIndex, @@ -84,16 +77,9 @@ function reloadData(instance, elem, apiClient, startIndex, limit) { })).then(function (result) { elem.setAttribute('data-activitystartindex', startIndex); elem.setAttribute('data-activitylimit', limit); - if (!startIndex) { + if (startIndex === 0) { const activityContainer = dom.parentWithClass(elem, 'activityContainer'); - - if (activityContainer) { - if (result.Items.length) { - activityContainer.classList.remove('hide'); - } else { - activityContainer.classList.add('hide'); - } - } + activityContainer?.classList.toggle('hide', result.Items.length === 0); } instance.items = result.Items; From 9d9670bdd04eaf362e71db7361d13e2ecac21017 Mon Sep 17 00:00:00 2001 From: 1337Nerd <26494273+1337Nerd@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:25:08 -0500 Subject: [PATCH 2/3] Change date to days Co-authored-by: Bill Thornton --- src/components/activitylog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/activitylog.js b/src/components/activitylog.js index 131095262d..7a1a2d59f6 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -65,7 +65,7 @@ function reloadData(instance, elem, apiClient, startIndex, limit) { limit ||= parseInt(elem.getAttribute('data-activitylimit') || '7', 10); const minDate = new Date(); const hasUserId = toBoolean(elem.getAttribute('data-useractivity'), true); - const dateOffset = hasUserId ? 1 : 7; // one day back if user id, otherwise one week + const daysOffset = hasUserId ? 1 : 7; // one day back if user id, otherwise one week // TODO: Use date-fns minDate.setTime(minDate.getTime() - dateOffset * 24 * 60 * 60 * 1000); From 408a52961a2f41c2b4c535ecde1fea91ef34eb03 Mon Sep 17 00:00:00 2001 From: 1337_Nerd Date: Wed, 11 Oct 2023 17:34:32 -0500 Subject: [PATCH 3/3] Convert ??= to ||=, put startIndex check in class toggle --- src/components/activitylog.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/activitylog.js b/src/components/activitylog.js index 7a1a2d59f6..11ab7044a4 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -61,13 +61,13 @@ function renderList(elem, apiClient, result) { } function reloadData(instance, elem, apiClient, startIndex, limit) { - startIndex ??= parseInt(elem.getAttribute('data-activitystartindex') || '0', 10); + startIndex ||= parseInt(elem.getAttribute('data-activitystartindex') || '0', 10); limit ||= parseInt(elem.getAttribute('data-activitylimit') || '7', 10); const minDate = new Date(); const hasUserId = toBoolean(elem.getAttribute('data-useractivity'), true); const daysOffset = hasUserId ? 1 : 7; // one day back if user id, otherwise one week // TODO: Use date-fns - minDate.setTime(minDate.getTime() - dateOffset * 24 * 60 * 60 * 1000); + minDate.setTime(minDate.getTime() - daysOffset * 24 * 60 * 60 * 1000); ApiClient.getJSON(ApiClient.getUrl('System/ActivityLog/Entries', { startIndex: startIndex, @@ -77,10 +77,8 @@ function reloadData(instance, elem, apiClient, startIndex, limit) { })).then(function (result) { elem.setAttribute('data-activitystartindex', startIndex); elem.setAttribute('data-activitylimit', limit); - if (startIndex === 0) { - const activityContainer = dom.parentWithClass(elem, 'activityContainer'); - activityContainer?.classList.toggle('hide', result.Items.length === 0); - } + const activityContainer = dom.parentWithClass(elem, 'activityContainer'); + activityContainer?.classList.toggle('hide', result.Items.length === 0 && startIndex === 0); instance.items = result.Items; renderList(elem, apiClient, result);