Skip to content

Commit 583b11c

Browse files
committed
fix: sliding tab indicator - use switchTab instead of full re-render
1 parent 5a8aa73 commit 583b11c

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

public/js/app.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@ async function renderServerDetail(serverId) {
17131713
try {
17141714
const data = await api(`/servers/details/${serverId}`);
17151715
const s = data.server;
1716+
state.serverIdentifier = s.identifier;
17161717
const meta = s.serverMeta;
17171718
const eggName = s.eggDetails?.name || `Egg #${s.egg}`;
17181719
const alloc = s.allocationDetails;
@@ -1879,14 +1880,18 @@ async function renderServerDetail(serverId) {
18791880
fetchLiveResources(s.identifier);
18801881
}
18811882

1882-
requestAnimationFrame(() => {
1883-
const indicator = $('#tab-indicator');
1884-
const activeTabEl = $('#server-detail-tabs .tab.active');
1885-
if (indicator && activeTabEl) {
1886-
indicator.style.left = activeTabEl.offsetLeft + 'px';
1887-
indicator.style.width = activeTabEl.offsetWidth + 'px';
1888-
}
1889-
});
1883+
// Disable transition for initial position to prevent sliding from 0
1884+
const indicator = $('#tab-indicator');
1885+
const activeTabEl = $('#server-detail-tabs .tab.active');
1886+
if (indicator && activeTabEl) {
1887+
const pos = activeTabEl.offsetLeft;
1888+
const w = activeTabEl.offsetWidth;
1889+
indicator.style.transition = 'none';
1890+
indicator.style.left = pos + 'px';
1891+
indicator.style.width = w + 'px';
1892+
void indicator.offsetWidth;
1893+
indicator.style.transition = '';
1894+
}
18901895

18911896
} catch (err) {
18921897
el.innerHTML = html`
@@ -1983,13 +1988,39 @@ async function fetchLiveResources(identifier) {
19831988
}
19841989
}
19851990

1991+
// ===== TAB SWITCHING =====
1992+
function switchTab(tabBtn) {
1993+
if (!$('#tab-indicator')) return;
1994+
const tabName = tabBtn.dataset.tab;
1995+
state.serverDetailTab = tabName;
1996+
1997+
document.querySelectorAll('#server-detail-tabs .tab').forEach(t => t.classList.remove('active'));
1998+
tabBtn.classList.add('active');
1999+
2000+
document.querySelectorAll('#page-server-detail .tab-content').forEach(c => c.style.display = 'none');
2001+
const target = $('#server-tab-' + tabName);
2002+
if (target) target.style.display = 'block';
2003+
2004+
const indicator = $('#tab-indicator');
2005+
if (indicator) {
2006+
indicator.style.left = tabBtn.offsetLeft + 'px';
2007+
indicator.style.width = tabBtn.offsetWidth + 'px';
2008+
}
2009+
2010+
if (tabName === 'resources') {
2011+
const container = $('#live-resources-container');
2012+
if (container && container.querySelector('.resource-gauge') === null) {
2013+
fetchLiveResources(state.serverIdentifier);
2014+
}
2015+
}
2016+
}
2017+
19862018
// ===== DELETE SERVER =====
19872019
document.addEventListener('click', function(e) {
19882020
const tabBtn = e.target.closest('.tab');
19892021
if (tabBtn && !tabBtn.classList.contains('active')) {
19902022
e.preventDefault();
1991-
state.serverDetailTab = tabBtn.dataset.tab;
1992-
renderServerDetail(state.serverId);
2023+
switchTab(tabBtn);
19932024
return;
19942025
}
19952026

0 commit comments

Comments
 (0)