diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 7b55da2..20f0653 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -731,6 +731,17 @@ function slideDetails(d) { var opening = d.__closing || !d.open; + // An exclusive group (details[name]): the browser would shut the open sibling at once while this + // one slides, so the page jumps. This one leaves the group for the slide, the sibling slides shut + // alongside, and the name comes back once both have finished. + var group = opening ? d.getAttribute('name') : null; + var others = []; + if (group) { + document.querySelectorAll('details[name]').forEach(function (o) { + if (o !== d && o.getAttribute('name') === group && o.open && !o.__closing) { others.push(o); } + }); + if (others.length) { d.removeAttribute('name'); } else { group = null; } + } var from = d.getBoundingClientRect().height; if (d.__slide) { d.__slide.cancel(); } d.open = false; @@ -746,6 +757,19 @@ d.style.overflow = ''; if (d.__closing) { d.__closing = false; d.open = false; } }; + if (group) { + others.forEach(slideDetails); + var slides = others.map(function (o) { return o.__slide.finished; }).concat(slide.finished); + // `finished` settles before onfinish shuts a closing sibling, and the name must come back only + // once they are shut, or the browser would shut this one instead. A sibling the reader opened + // again meanwhile keeps this one out of the group. + Promise.allSettled(slides).then(function () { + others.forEach(function (o) { + if (o.__closing) { o.__closing = false; o.open = false; } + }); + if (others.every(function (o) { return !o.open; })) { d.setAttribute('name', group); } + }); + } } document.addEventListener('click', function (e) { @@ -1289,7 +1313,7 @@ refreshActivity(); } - // The live activity: the profile corner (heat ring, chips, waiting list) and the live strip after + // The live activity: the profile corner (heat ring, chips) and the live strip after // the path bar. The server's activity JSON (GET /-/activity) is the source. An `activity` event of // the shell stream, and every `unread` event, fetches it again and redraws whatever is on the page. // Nothing changes before the JSON says so. A finished run leaves the strip when the server's window @@ -1422,7 +1446,7 @@ }); } - // The heat ring: a full ember ring while any of the viewer's runs is going, a plain ring otherwise. + // The heat ring: an accent ring while any of the viewer's runs is going, none otherwise. function drawRing(ring, running) { if (running.length) { ring.classList.add('hot'); } else { ring.classList.remove('hot'); } } @@ -1430,18 +1454,24 @@ // The chips: one per non-zero count. The titles come from the chip box's templates, with `{n}` // standing for the count; the singular template is used for one. function drawChips(box, json) { + // Each chip links to the newest thing it counts, or to the inbox when that is not listed. + var newest = function (kind) { + var item = (json.waiting || []).filter(function (w) { return w.kind === kind; })[0]; + return item ? item.href : '/notifications'; + }; var chips = [ - { kind: 'review', cls: 'chip chip-review', n: json.reviews, tpl: 'data-review' }, - { kind: 'mention', cls: 'chip chip-mention', n: json.mentions, tpl: 'data-mention' }, - { kind: 'failing', cls: 'chip chip-failing', n: json.failing, tpl: 'data-failing' } + { kind: 'review', cls: 'chip chip-review', n: json.reviews, tpl: 'data-review', href: newest('review') }, + { kind: 'mention', cls: 'chip chip-mention', n: json.mentions, tpl: 'data-mention', href: newest('mention') }, + { kind: 'failing', cls: 'chip chip-failing', n: json.failing, tpl: 'data-failing', href: json.failing_href || '/notifications' } ]; box.textContent = ''; chips.forEach(function (c) { var n = Number(c.n) || 0; if (n <= 0) { return; } var tpl = box.getAttribute(c.tpl + (n === 1 ? '-one' : '')) || ''; - var chip = document.createElement('span'); + var chip = document.createElement('a'); chip.className = c.cls; + chip.setAttribute('href', c.href); chip.setAttribute('title', tpl.split('{n}').join(String(n))); chip.appendChild(chipIcon(c.kind)); chip.appendChild(document.createTextNode(String(n))); @@ -1449,51 +1479,7 @@ }); } - // The waiting list and its caption: built from the server's items, and removed when there are none. - // They sit before the menu's first link (All notifications). - function drawWaiting(menu, waiting) { - var cap = menu.querySelector('.corner-cap'); - var list = menu.querySelector('.corner-waiting'); - if (!waiting.length) { - if (cap) { cap.remove(); } - if (list) { list.remove(); } - return; - } - var anchor = menu.querySelector('.corner-link'); - if (!cap) { - cap = document.createElement('p'); - cap.className = 'corner-cap'; - cap.textContent = menu.getAttribute('data-cap') || ''; - menu.insertBefore(cap, anchor); - } - if (!list) { - list = document.createElement('ul'); - list.className = 'corner-waiting'; - menu.insertBefore(list, anchor); - } - list.textContent = ''; - waiting.forEach(function (item) { - var li = document.createElement('li'); - var a = document.createElement('a'); - a.setAttribute('href', localHref(item.href)); - var dot = document.createElement('span'); - dot.className = 'corner-dot ' + (item.kind === 'review' ? 'review' : 'mention'); - var text = document.createElement('span'); - text.className = 'corner-item'; - var title = document.createElement('span'); - title.textContent = String(item.title || ''); - var where = document.createElement('small'); - where.textContent = String(item.where || ''); - text.appendChild(title); - text.appendChild(where); - a.appendChild(dot); - a.appendChild(text); - li.appendChild(a); - list.appendChild(li); - }); - } - - // Redraws every strip, ring, chip box and waiting menu on the page from one activity JSON. The + // Redraws every strip, ring and chip box on the page from one activity JSON. The // elements are looked up here each time, since a swap may have replaced them. function drawActivity(json) { var strips = document.querySelectorAll('.live-strip[data-activity]'); @@ -1503,8 +1489,6 @@ for (var r = 0; r < rings.length; r++) { drawRing(rings[r], running); } var boxes = document.querySelectorAll('.corner-chips'); for (var b = 0; b < boxes.length; b++) { drawChips(boxes[b], json); } - var menus = document.querySelectorAll('.corner-menu'); - for (var m = 0; m < menus.length; m++) { drawWaiting(menus[m], json.waiting || []); } // Finished runs leave the strip when the server's window ends, so the JSON is asked for again. clearTimeout(activityTimer); activityTimer = null;