Refactor last updated handling and add tooltips for timestamps
Moved `lastUpdated` assignment to appropriate API call logic and replaced `lastUpdatedSeconds` with a computed property driven by a reactive `now` value. Added tooltips to display localized date formats for "Last updated" and "Last Mirror sync" timestamps, enhancing UX.
This commit is contained in:
@@ -51,10 +51,24 @@
|
|||||||
<span>
|
<span>
|
||||||
Last updated
|
Last updated
|
||||||
{{ formatTimeAgo(lastUpdatedSeconds) }}
|
{{ formatTimeAgo(lastUpdatedSeconds) }}
|
||||||
|
<v-tooltip activator="parent" location="start">
|
||||||
|
{{
|
||||||
|
unixTimestampToLocalizedDate(
|
||||||
|
Math.floor((packagesStore.state.lastUpdated || Date.now()) / 1000)
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</v-tooltip>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
Last Mirror sync
|
Last Mirror sync
|
||||||
{{ formatTimeAgo(lastMirrorSync) }}
|
{{ formatTimeAgo(lastMirrorSync) }}
|
||||||
|
<v-tooltip activator="parent" location="start">
|
||||||
|
{{
|
||||||
|
unixTimestampToLocalizedDate(
|
||||||
|
statsStore.state.stats?.last_mirror_timestamp || Math.floor(Date.now() / 1000)
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</v-tooltip>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -96,19 +110,22 @@ const statsStore = useStatsStore()
|
|||||||
const packagesStore = usePackagesStore()
|
const packagesStore = usePackagesStore()
|
||||||
|
|
||||||
const { mobile } = useDisplay()
|
const { mobile } = useDisplay()
|
||||||
const lastUpdatedSeconds = ref(0)
|
|
||||||
const rtf = new Intl.RelativeTimeFormat('en', {
|
const rtf = new Intl.RelativeTimeFormat('en', {
|
||||||
localeMatcher: 'best fit',
|
localeMatcher: 'best fit',
|
||||||
numeric: 'always',
|
numeric: 'always',
|
||||||
style: 'long'
|
style: 'long'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const now = ref(Math.floor(Date.now() / 1000))
|
||||||
|
|
||||||
const updateFailed = computed(
|
const updateFailed = computed(
|
||||||
() => !!packagesStore.state.errorCurrentlyBuilding || !!statsStore.state.error
|
() => !!packagesStore.state.errorCurrentlyBuilding || !!statsStore.state.error
|
||||||
)
|
)
|
||||||
|
const lastUpdatedSeconds = computed(
|
||||||
|
() => now.value - Math.floor((packagesStore.state.lastUpdated || Date.now()) / 1000)
|
||||||
|
)
|
||||||
const lastMirrorSync = computed(
|
const lastMirrorSync = computed(
|
||||||
() =>
|
() => now.value - (statsStore.state.stats?.last_mirror_timestamp || Math.floor(Date.now() / 1000))
|
||||||
Math.floor(Date.now() / 1000) - (statsStore.state.stats?.last_mirror_timestamp || Date.now())
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const packageArrays = reactive({
|
const packageArrays = reactive({
|
||||||
@@ -129,7 +146,7 @@ const packageArrays = reactive({
|
|||||||
let updateTimer: number | undefined
|
let updateTimer: number | undefined
|
||||||
const startLastUpdatedTimer = () => {
|
const startLastUpdatedTimer = () => {
|
||||||
updateTimer = window.setInterval(() => {
|
updateTimer = window.setInterval(() => {
|
||||||
lastUpdatedSeconds.value++
|
now.value = Math.floor(Date.now() / 1000)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +160,11 @@ const formatTimeAgo = (seconds: number): string => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unixTimestampToLocalizedDate(timestamp: number): string {
|
||||||
|
const date = new Date(timestamp * 1000) // convert to milliseconds
|
||||||
|
return date.toLocaleString(navigator.language)
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
startLastUpdatedTimer()
|
startLastUpdatedTimer()
|
||||||
})
|
})
|
||||||
|
@@ -80,7 +80,6 @@ export const usePackagesStore = defineStore('packages', () => {
|
|||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
state.loading = false
|
state.loading = false
|
||||||
state.lastUpdated = Date.now()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +107,7 @@ export const usePackagesStore = defineStore('packages', () => {
|
|||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
state.loadingCurrentlyBuilding = false
|
state.loadingCurrentlyBuilding = false
|
||||||
|
state.lastUpdated = Date.now()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user