Skip to content

Commit

Permalink
remove console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash committed Oct 11, 2024
1 parent 5801e62 commit c45cdd1
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions server/src/js/components/latest-levels-auto-refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class LatestLevelsAutoRefresh {
}

updateTimeAgo = () => {
console.log('--updateTimeAgo() started')

setTimeout(() => {
this.renderTimeAgo()
this.timeAgoInterval = setInterval(this.renderTimeAgo, 60000)
Expand All @@ -40,23 +38,17 @@ class LatestLevelsAutoRefresh {
renderTimeAgo = () => {
const elements = document.querySelectorAll('[data-item-time]')

elements.forEach((element, index) => {
console.log('element', index)
elements.forEach(element => {
const timeAgoText = element.textContent
const timeAgoValue = parseInt(timeAgoText, 10)

console.log('--currentTime', timeAgoText)

if (!timeAgoText.includes('hour')) {
element.textContent = `${timeAgoValue + 1} minutes ago`
console.log('--newTime', element.textContent)
}
})
}

fetchRiverLevels = (callback) => {
console.log('fetchRiverLevels...')

this.liveStatusMessages = []

fetch(window.location.href)
Expand All @@ -75,8 +67,7 @@ class LatestLevelsAutoRefresh {
}
})
.catch(error => {
console.error('Error updating levels:', error)

console.error(error)
this.liveStatusMessages.push('There was an error getting the latest level')
})
.finally(() => {
Expand All @@ -99,9 +90,6 @@ class LatestLevelsAutoRefresh {

// Check if any elements are missing in the fetched data
const isMissingElements = this.latestLevels.length !== fetchedElements.length
console.log('isMissingElements', isMissingElements, this.latestLevels.length, fetchedElements.length)
console.log('latestLevels', this.latestLevels)
console.log('fetchedElements', fetchedElements)

if (isMissingElements) {
return this.liveStatusMessages.push('Warnings have been removed, please refresh the page.')
Expand All @@ -118,29 +106,19 @@ class LatestLevelsAutoRefresh {

const currentItem = document.querySelector(`[data-item-id="${itemId}"]`)

console.log('fetchedElement', itemId, itemRiverName, itemRiverAgency)

if (currentItem) {
const currentTime = currentItem.querySelector('[data-item-time]')
const currentValue = currentItem.querySelector('[data-item-value]')
const currentStatus = currentItem.getAttribute('data-item-status')

console.log('--currentValue', currentValue?.textContent, currentStatus)
console.log('--fetchedValue', fetchedValue?.textContent, fetchedStatus)
console.log('--requires update?', fetchedValue?.textContent !== currentValue?.textContent)

if (fetchedStatus === currentStatus) {
if (fetchedValue?.textContent !== currentValue?.textContent) {
console.log('--new value fetched')
clearInterval(this.timeAgoInterval)
console.log('--interval cleared')
currentValue.textContent = fetchedValue.textContent

this.liveStatusMessages.push(`The ${itemRiverName} at ${itemRiverAgency} level was ${fetchedValue.textContent} metres ${fetchedTime.textContent}`)

this.updateTimeAgo()
} else {
console.log('--no change')
}

currentTime.textContent = fetchedTime.textContent
Expand All @@ -150,8 +128,6 @@ class LatestLevelsAutoRefresh {
} else {
this.liveStatusMessages.push('Please refresh the page')
}

console.log('-------------------\n')
})
}

Expand All @@ -164,9 +140,6 @@ class LatestLevelsAutoRefresh {
// Find the next target minute
const nextTargetMinute = this.targetMinutes.find(minute => minute > nowMinute) ?? this.targetMinutes[0]

console.log('--Current minute:', nowMinute)
console.log('--Next target minute:', nextTargetMinute)

// Create the next target date based on the next target minute
const nextTargetDate = new Date(now)
nextTargetDate.setMinutes(nextTargetMinute)
Expand All @@ -180,9 +153,6 @@ class LatestLevelsAutoRefresh {
// Calculate delay correctly from now
const delay = nextTargetDate.getTime() - now.getTime()

console.log('--delay (calc)', Math.round(delay / 1000 / 60))
console.log(`Next update scheduled in ${Math.round(delay / 1000 / 60)} minutes at ${nextTargetDate.toLocaleTimeString()}\n\n`)

// Schedule the next update
this.timeout = setTimeout(() => {
this.fetchRiverLevels()
Expand Down

0 comments on commit c45cdd1

Please sign in to comment.