diff --git a/public/index.html b/public/index.html index 8b3bcd5b..d1354785 100644 --- a/public/index.html +++ b/public/index.html @@ -84,7 +84,7 @@ - + diff --git a/public/packets.js b/public/packets.js index e11c0d13..0a4527e6 100644 --- a/public/packets.js +++ b/public/packets.js @@ -472,12 +472,25 @@ // Observation sort dropdown const obsSortSel = document.getElementById('fObsSort'); obsSortSel.value = obsSortMode; - obsSortSel.addEventListener('change', function () { + obsSortSel.addEventListener('change', async function () { obsSortMode = this.value; localStorage.setItem('meshcore-obs-sort', obsSortMode); - // Re-sort all expanded groups + // For non-observer sorts, fetch children for visible groups that don't have them yet + if (obsSortMode !== SORT_OBSERVER && groupByHash) { + const toFetch = packets.filter(p => p.hash && !p._children && (p.observation_count || 0) > 1); + await Promise.all(toFetch.map(async (p) => { + try { + const data = await api(`/packets/${p.hash}`); + if (data?.packet && data.observations) { + p._children = data.observations.map(o => ({...data.packet, ...o, _isObservation: true})); + p._fetchedData = data; + } + } catch {} + })); + } + // Re-sort all groups with children for (const p of packets) { - if (expandedHashes.has(p.hash) && p._children) sortGroupChildren(p); + if (p._children) sortGroupChildren(p); } renderTableRows(); });