diff --git a/frontend/src/components/CurrentlyBuilding.vue b/frontend/src/components/CurrentlyBuilding.vue
index 0aed13d..9398773 100644
--- a/frontend/src/components/CurrentlyBuilding.vue
+++ b/frontend/src/components/CurrentlyBuilding.vue
@@ -11,11 +11,21 @@
- {{ packageCount.building > 0 ? 'Building' : 'Idle' }}
+ {{
+ updateFailed
+ ? 'Could not fetch data.'
+ : packageCount.building > 0
+ ? 'Building'
+ : 'Idle'
+ }}
@@ -33,19 +43,23 @@
class="text-grey v-col-12 v-col-lg-2 mb-3"
cols="auto"
style="font-size: 13px">
- Last updated
- {{
- lastUpdatedSeconds > 59
- ? rtf.format(-Math.floor(lastUpdatedSeconds / 60), 'minutes')
- : rtf.format(-lastUpdatedSeconds, 'seconds')
- }}
+
+ Last updated
+ {{
+ lastUpdatedSeconds > 59
+ ? rtf.format(-Math.floor(lastUpdatedSeconds / 60), 'minutes')
+ : rtf.format(-lastUpdatedSeconds, 'seconds')
+ }}
+
+
+ Please try again later.
-
+
Building
@@ -58,7 +72,7 @@
{{ pkg.arch_version }}
-
+
Queued
@@ -79,6 +93,7 @@ const UPDATE_INTERVAL_MINUTES = 5
const { mobile } = useDisplay()
const lastUpdatedTime = ref(0)
const lastUpdatedSeconds = ref(0)
+const updateFailed = ref(false)
const rtf = new Intl.RelativeTimeFormat('en', {
localeMatcher: 'best fit',
numeric: 'always',
@@ -102,8 +117,10 @@ const packages = ref<{
queued: []
})
-const fetchPackages = async (endpoint: string, status?: string) => {
- let url = `${BASE_URL}?limit=0&offset=0`
+let timerInterval: NodeJS.Timeout // Declare timerInterval outside the function
+
+const fetchPackages = async (offset: string, status?: string) => {
+ let url = `${BASE_URL}?limit=0&offset=${offset}`
if (status) {
url += `&status=${status}`
}
@@ -114,22 +131,28 @@ const fetchPackages = async (endpoint: string, status?: string) => {
throw new Error(`HTTP error! status: ${response.status}`)
}
const json: Packages = await response.json()
+
+ lastUpdatedTime.value = Date.now()
+ lastUpdatedSeconds.value = 0 // Reset seconds counter
+ updateFailed.value = false
+
return json
} catch (error) {
console.error('Error fetching packages:', error)
+ updateFailed.value = true
return null
}
}
const getTotalPackages = async () => {
- const json = await fetchPackages(`${BASE_URL}?limit=1&offset=0`)
+ const json = await fetchPackages('1')
if (json) {
packageCount.value.total = json.total
}
}
const getBuiltPackages = async () => {
- const json = await fetchPackages(`${BASE_URL}?limit=0&offset=0`, 'built')
+ const json = await fetchPackages('0', 'built')
if (json) {
packageCount.value.built = json.total
packages.value.built = json.packages
@@ -137,7 +160,7 @@ const getBuiltPackages = async () => {
}
const getBuildingPackages = async () => {
- const json = await fetchPackages(`${BASE_URL}?limit=0&offset=0`, 'building')
+ const json = await fetchPackages('0', 'building')
if (json) {
packageCount.value.building = json.total
packages.value.building = json.packages
@@ -145,38 +168,44 @@ const getBuildingPackages = async () => {
}
const getQueuedPackages = async () => {
- const json = await fetchPackages(`${BASE_URL}?limit=0&offset=0`, 'queued')
+ const json = await fetchPackages('0', 'queued')
if (json) {
packageCount.value.queued = json.total
packages.value.queued = json.packages
}
}
-onMounted(() => {
+// Function to start the timer
+const startTimer = () => {
+ stopTimer() // Clear any existing timer
getTotalPackages()
getBuiltPackages()
getBuildingPackages()
getQueuedPackages()
-
- lastUpdatedTime.value = Date.now()
- lastUpdatedSeconds.value = Math.floor((Date.now() - lastUpdatedTime.value) / 1000)
-
- setInterval(() => {
- lastUpdatedSeconds.value = Math.floor((Date.now() - lastUpdatedTime.value) / 1000)
- }, 1000)
-
- setInterval(
+ timerInterval = setInterval(
() => {
getTotalPackages()
getBuiltPackages()
getBuildingPackages()
getQueuedPackages()
- lastUpdatedTime.value = Date.now()
- lastUpdatedSeconds.value = Math.floor((Date.now() - lastUpdatedTime.value) / 1000)
},
UPDATE_INTERVAL_MINUTES * 60 * 1000
)
+}
+
+// Function to stop the timer
+const stopTimer = () => {
+ clearInterval(timerInterval)
+}
+
+onMounted(() => {
+ startTimer() // Start the timer when the component is mounted
})
+
+// Update seconds counter every second
+setInterval(() => {
+ lastUpdatedSeconds.value++
+}, 1000)