Skip to content

Commit

Permalink
sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash committed Sep 23, 2024
1 parent 961efe6 commit 135eee6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions server/views/partials/latest-levels.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ <h2 class="defra-live__title">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)
Expand Down Expand Up @@ -69,7 +72,9 @@ <h2 class="defra-live__title">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 = ''
Expand All @@ -86,7 +91,10 @@ <h2 class="defra-live__title">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 => {
Expand Down Expand Up @@ -116,11 +124,11 @@ <h2 class="defra-live__title">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')

Expand Down

0 comments on commit 135eee6

Please sign in to comment.