Skip to content

Commit

Permalink
fix substat loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed May 30, 2024
1 parent 265804f commit ab08084
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions dashboard/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,42 @@ const avaliableStorages = computed(() => {
return s
})
const activeStorageIndex = ref(0)
const activeStats = ref<Stats | null>(null)
watch([data, activeStorageIndex], async ([data, newIndex]) => {
watch(activeStorageIndex, async (newIndex) => {
if (!data.value) {
activeStats.value = null
return
}
if (!newIndex) {
activeStats.value = data.value.stats
return
}
const storageId = data.value.storages[newIndex - 1]
if (!storageId) {
activeStorageIndex.value = 0
activeStats.value = null
return
}
const statClearTimerId = setTimeout(() => {
activeStats.value = null
}, 500)
const res = await getStat(storageId, token.value)
clearTimeout(statClearTimerId)
if (res === null) {
activeStats.value = JSON.parse(JSON.stringify(EMPTY_STAT))
return
}
activeStats.value = res
return
})
watch(data, async (data) => {
if (!data) {
activeStats.value = null
return
}
const newIndex = activeStorageIndex.value
if (!newIndex) {
activeStats.value = data.stats
return
Expand All @@ -93,11 +121,7 @@ watch([data, activeStorageIndex], async ([data, newIndex]) => {
activeStats.value = null
return
}
const clearTimerId = setTimeout(() => {
activeStats.value = null
}, 300)
const res = await getStat(storageId, token.value)
clearTimeout(clearTimerId)
if (res === null) {
activeStats.value = JSON.parse(JSON.stringify(EMPTY_STAT))
return
Expand Down

0 comments on commit ab08084

Please sign in to comment.