Skip to content

Commit 76e6226

Browse files
committed
fix: preserve nav indicator element by not calling renderSidebarNav in toggle handler
Extract buildServerSubList() helper so the toggle handler only updates the sub-list innerHTML instead of destroying/recreating the entire nav. Bump cache buster to v=4.
1 parent 2a347b5 commit 76e6226

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<div id="app"></div>
1919

20-
<script src="/js/app.js?v=3"></script>
21-
<script src="/js/admin.js?v=3"></script>
20+
<script src="/js/app.js?v=4"></script>
21+
<script src="/js/admin.js?v=4"></script>
2222
</body>
2323
</html>

public/js/app.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,23 @@ function initSidebarTooltip() {
11891189
});
11901190
}
11911191

1192+
function buildServerSubList() {
1193+
if (state.sidebarServersLoading) return html`<div class="nav-sub-empty"><span class="spinner"></span> Loading...</div>`;
1194+
if (state.servers.length === 0) return html`<div class="nav-sub-empty">No servers</div>`;
1195+
return state.servers.map(s => {
1196+
const isInstalling = s.status === 'installing' || s.installed === 0 || s.installed === '0' || s.installed === false;
1197+
const isSuspended = s.status === 'suspended';
1198+
const dotClass = isSuspended ? 'dot-suspended' : (isInstalling ? 'dot-installing' : 'dot-active');
1199+
const isActive = state.currentPage === 'server' && state.serverId === s.id;
1200+
return html`
1201+
<a class="nav-sub-item ${isActive ? 'active' : ''}" data-server-nav="${s.id}" href="/server/${s.id}">
1202+
<span class="nav-sub-dot ${dotClass}"></span>
1203+
${escapeHtml(s.name)}
1204+
</a>
1205+
`;
1206+
}).join('');
1207+
}
1208+
11921209
function renderSidebarNav() {
11931210
const nav = $('#sidebar-nav');
11941211
if (!nav) return;
@@ -1239,20 +1256,7 @@ function renderSidebarNav() {
12391256
<svg class="nav-parent-chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
12401257
</div>
12411258
<div class="nav-sub-list ${state.sidebarServersOpen ? 'open' : ''}" id="nav-servers-list">
1242-
${state.sidebarServersLoading ? html`<div class="nav-sub-empty"><span class="spinner"></span> Loading...</div>` :
1243-
state.servers.length === 0 ? html`<div class="nav-sub-empty">No servers</div>` :
1244-
state.servers.map(s => {
1245-
const isInstalling = s.status === 'installing' || s.installed === 0 || s.installed === '0' || s.installed === false;
1246-
const isSuspended = s.status === 'suspended';
1247-
const dotClass = isSuspended ? 'dot-suspended' : (isInstalling ? 'dot-installing' : 'dot-active');
1248-
const isActive = state.currentPage === 'server' && state.serverId === s.id;
1249-
return html`
1250-
<a class="nav-sub-item ${isActive ? 'active' : ''}" data-server-nav="${s.id}" href="/server/${s.id}">
1251-
<span class="nav-sub-dot ${dotClass}"></span>
1252-
${escapeHtml(s.name)}
1253-
</a>
1254-
`;
1255-
}).join('')}
1259+
${buildServerSubList()}
12561260
</div>
12571261
<a class="nav-item" id="nav-notifications" href="#">
12581262
<span style="position:relative;display:inline-flex">
@@ -1327,7 +1331,11 @@ function renderSidebarNav() {
13271331
state.sidebarServersLoading = false;
13281332
}
13291333
navigateTo('servers');
1330-
renderSidebarNav();
1334+
const subList = document.querySelector('#nav-servers-list');
1335+
if (subList) {
1336+
subList.innerHTML = buildServerSubList();
1337+
initIcons();
1338+
}
13311339
});
13321340
}
13331341

0 commit comments

Comments
 (0)