fix(ui): Update endpoints in-place instead of reloading every time (#1209)

* fix(ui): Update endpoints in-place instead of reloading every time

Fixes #1207

* Regenerate static assets
This commit is contained in:
TwiN
2025-08-18 12:36:16 -04:00
committed by GitHub
parent 12825a2b6f
commit 2c42aa8087
6 changed files with 39 additions and 10 deletions

View File

@@ -9,7 +9,7 @@
<!-- Header -->
<div
:class="[
'px-4 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors',
'announcement-header px-4 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors',
isCollapsed ? 'rounded-lg' : 'rounded-t-lg border-b border-gray-200 dark:border-gray-600'
]"
@click="toggleCollapsed"
@@ -34,7 +34,7 @@
<!-- Timeline Content -->
<div
v-if="!isCollapsed"
class="p-4 transition-all duration-200 rounded-b-lg"
class="announcement-content p-4 transition-all duration-200 rounded-b-lg"
>
<div class="relative">
<!-- Announcements -->

View File

@@ -1,5 +1,5 @@
<template>
<Card class="endpoint hover:shadow-lg transition-shadow cursor-pointer h-full flex flex-col">
<Card class="endpoint h-full flex flex-col transition hover:shadow-lg hover:scale-[1.01] dark:hover:border-gray-700">
<CardHeader class="endpoint-header px-3 sm:px-6 pt-3 sm:pt-6 pb-2 space-y-0">
<div class="flex items-start justify-between gap-2 sm:gap-3">
<div class="flex-1 min-w-0 overflow-hidden">

View File

@@ -280,26 +280,55 @@ const visiblePages = computed(() => {
})
const fetchData = async () => {
loading.value = true
// Don't show loading state on refresh to prevent UI flicker
const isInitialLoad = endpointStatuses.value.length === 0
if (isInitialLoad) {
loading.value = true
}
try {
const response = await fetch(`${SERVER_URL}/api/v1/endpoints/statuses?page=1&pageSize=100`, {
credentials: 'include'
})
if (response.status === 200) {
const data = await response.json()
endpointStatuses.value = data
// If this is the initial load, just set the data
if (isInitialLoad) {
endpointStatuses.value = data
} else {
// Check if endpoints have been added or removed
const currentKeys = new Set(endpointStatuses.value.map(ep => ep.key))
const newKeys = new Set(data.map(ep => ep.key))
const hasAdditions = data.some(ep => !currentKeys.has(ep.key))
const hasRemovals = endpointStatuses.value.some(ep => !newKeys.has(ep.key))
if (hasAdditions || hasRemovals) {
// Endpoints have changed, reset the array to maintain proper order
endpointStatuses.value = data
} else {
// Only statuses/results have changed, update in place to preserve scroll
const endpointMap = new Map(data.map(ep => [ep.key, ep]))
endpointStatuses.value.forEach((endpoint, index) => {
const updated = endpointMap.get(endpoint.key)
if (updated) {
// Update in place to preserve Vue's reactivity and scroll position
Object.assign(endpointStatuses.value[index], updated)
}
})
}
}
} else {
console.error('[Home][fetchData] Error:', await response.text())
}
} catch (error) {
console.error('[Home][fetchData] Error:', error)
} finally {
loading.value = false
if (isInitialLoad) {
loading.value = false
}
}
}
const refreshData = () => {
endpointStatuses.value = [];
fetchData()
}