From 135eee667f56fc8ce26d7650c94e70e24c1f9db7 Mon Sep 17 00:00:00 2001 From: Ash Date: Mon, 23 Sep 2024 09:58:06 +0100 Subject: [PATCH] sonar fixes --- server/views/partials/latest-levels.html | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/views/partials/latest-levels.html b/server/views/partials/latest-levels.html index b072d0f48..e3649af4a 100644 --- a/server/views/partials/latest-levels.html +++ b/server/views/partials/latest-levels.html @@ -36,12 +36,15 @@

Latest level{% if model.latestLevels.length > 1 %} let timeAgoInterval let liveStatusMessages = [] + const dataItemTimeAttr = '[data-item-time]' const latestLevels = document.querySelectorAll('.defra-live__item') - if (latestLevels.length === 0) return + if (latestLevels.length === 0) { + return + } function renderTimeAgo () { - const elements = document.querySelectorAll('[data-item-time]') + const elements = document.querySelectorAll(dataItemTimeAttr) elements.forEach((element, index) => { console.log('element', index) @@ -69,7 +72,9 @@

Latest level{% if model.latestLevels.length > 1 %} } function updateLiveStatus () { - if (liveStatusMessages.length === 0) return + if (liveStatusMessages.length === 0) { + return + } const element = document.querySelector('[data-live-status]') element.innerHTML = '' @@ -86,7 +91,10 @@

Latest level{% if model.latestLevels.length > 1 %} fetch(window.location.href) .then(res => { - if (!res.ok) throw new Error('Failed to fetch data') + if (!res.ok) { + throw new Error('Failed to fetch data') + } + return res.text() }) .then(html => { @@ -116,11 +124,11 @@

Latest level{% if model.latestLevels.length > 1 %} console.log('fetchedElement', itemId, itemRiverName, itemRiverAgency) if (currentItem) { - const fetchedTime = fetchedElement.querySelector('[data-item-time]') + const fetchedTime = fetchedElement.querySelector(dataItemTimeAttr) const fetchedValue = fetchedElement.querySelector('[data-item-value]') const fetchedStatus = fetchedElement.getAttribute('data-item-status') - const currentTime = currentItem.querySelector('[data-item-time]') + const currentTime = currentItem.querySelector(dataItemTimeAttr) const currentValue = currentItem.querySelector('[data-item-value]') const currentStatus = currentItem.getAttribute('data-item-status')