Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(view): the shouts tab counts shouts you have not seen [N26]

Corey Olson96aa8a605377
diff --git a/src/cockpit.js b/src/cockpit.js
index b8b5d6ce..0dcdc219 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -324,7 +324,7 @@ input, select, textarea { border: 1px solid var(--line-strong); background: var(
<script>
const key = new URLSearchParams(location.search).get('k') || '';
const keep = (name, value) => { try { if (value === undefined) return localStorage.getItem(name); localStorage.setItem(name, value); } catch { return null; } return value; };
-const view = { root: keep('pb.project'), tab: keep('pb.tab') || 'items', item: null, adding: false, state: 'active', rows: { spec: 'decide', doctrine: 'all' }, row: { spec: null, doctrine: null } };
+const view = { root: keep('pb.project'), tab: keep('pb.tab') || 'items', seen: {}, item: null, adding: false, state: 'active', rows: { spec: 'decide', doctrine: 'all' }, row: { spec: null, doctrine: null } };
let data = null;
let seen = '';
const $ = (id) => document.getElementById(id);
@@ -576,7 +576,6 @@ function render() {
const by = (s) => items.filter((i) => stateOf(i) === s);
const active = items.filter((i) => stateOf(i) !== 'verified');
$('count-items').textContent = active.length || '';
- $('count-shouts').textContent = p.shouts.length || '';
$('count-spec').textContent = p.spec.filter((r) => ['pending', 'draft'].includes(r.status)).length || '';
$('count-doctrine').textContent = p.practice.filter((r) => ['pending', 'draft'].includes(r.status)).length || '';
@@ -692,6 +691,24 @@ function render() {
function showTab() {
document.querySelectorAll('[data-pane]').forEach((pane) => { pane.hidden = pane.dataset.pane !== view.tab; });
document.querySelectorAll('.tab').forEach((button) => button.classList.toggle('on', button.dataset.tab === view.tab));
+ countUnseen();
+}
+
+/**
+ * Count on the Shouts tab the shouts that came after the newest one the person has seen in this
+ * project. Seeing means having the Shouts tab open with the board drawn; a project shown for the
+ * first time has seen everything so far. The mark is kept in this browser, so a reload counts
+ * nothing old, and the count is never just how many shouts were loaded.
+ */
+function countUnseen() {
+ const p = data && data.project;
+ if (!p) return;
+ const key = 'pb.seen.' + view.root;
+ const kept = view.seen[key] ?? keep(key);
+ const newest = p.shouts.length ? p.shouts[0].shout_id : 0;
+ const seen = view.tab === 'shouts' || kept === null || kept === undefined ? newest : Number(kept);
+ if (String(seen) !== String(kept)) { view.seen[key] = seen; keep(key, String(seen)); }
+ $('count-shouts').textContent = p.shouts.filter((x) => x.shout_id > seen).length || '';
}
function go(target) {
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 176b7c61..52a5c3c2 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -206,6 +206,15 @@ async function settle(inflight) {
}
}
+/**
+ * A browser's local storage for the page. The test keeps it, so a second load of the page finds
+ * what the first one left, as after a reload.
+ */
+function storage() {
+ const items = new Map();
+ return { getItem: (key) => (items.has(key) ? items.get(key) : null), setItem: (key, value) => { items.set(key, String(value)); } };
+}
+
/**
* The browser's Date with its clock moved some days on, as the page would read it then.
*/
@@ -224,10 +233,10 @@ function daysOn(days) {
/**
* Open the page a view serves, at a window width, and wait for its first board; `later` moves the
- * page's clock that many days on. show(id) is what that region holds; click() and type() act as
- * the person would.
+ * page's clock that many days on, and `store` is its local storage, if it has one. show(id) is
+ * what that region holds; click() and type() act as the person would.
*/
-async function openPage(view, { width = 1280, later = 0 } = {}) {
+async function openPage(view, { width = 1280, later = 0, store = null } = {}) {
const html = await (await fetch(view.link)).text();
const script = html.slice(html.indexOf('<script>') + '<script>'.length, html.lastIndexOf('</script>'));
const known = new Set([...html.matchAll(/\bid="([^"]+)"/g)].map((match) => match[1]));
@@ -254,6 +263,7 @@ async function openPage(view, { width = 1280, later = 0 } = {}) {
matchMedia: (query) => ({ matches: width <= Number(/max-width:\s*(\d+)px/.exec(query)?.[1] ?? Infinity) }),
setInterval: () => 0,
...(later ? { Date: daysOn(later) } : {}),
+ ...(store ? { localStorage: store } : {}),
setTimeout,
clearTimeout,
fetch: (path, init) => {
@@ -851,6 +861,38 @@ test('shout ids, search and narrow windows reach the item [N26]', async () => {
}
});
+test('the shouts tab counts shouts you have not seen [N26]', async () => {
+ const box = machine();
+ const alpha = project(box, 'alpha');
+ box.run(alpha.repo, 'shout', 'web', 'first');
+ box.run(alpha.repo, 'shout', 'web', 'second');
+ const view = await startView(box);
+ try {
+ const store = storage();
+ const count = (page) => page.element('count-shouts').textContent;
+ const page = await openPage(view, { store });
+ assert.equal(count(page), '', 'the shouts there before the first look count as seen, not as 2');
+
+ box.run(alpha.web, 'shout', 'coordinator', 'web-1 is on it');
+ await page.run('refresh()');
+ assert.equal(count(page), '1', 'a shout since then counts');
+ await page.click({ tab: 'shouts' });
+ assert.equal(count(page), '', 'opening Shouts sees it');
+ box.run(alpha.web, 'shout', 'coordinator', 'and done');
+ await page.run('refresh()');
+ assert.equal(count(page), '', 'a shout that arrives while Shouts is open is seen');
+ await page.click({ tab: 'items' });
+
+ // A shout lands while the page is closed: the reload counts it, and only it.
+ box.run(alpha.web, 'shout', 'coordinator', 'while you were away');
+ const reloaded = await openPage(view, { store });
+ assert.equal(count(reloaded), '1', 'what was seen is remembered across a reload');
+ await reloaded.click({ tab: 'shouts' });
+ assert.equal(count(reloaded), '');
+ } finally {
+ await view.stop();
+ }
+});
test('the detail opens on the top item, not a blank form [N26]', async () => {
const box = machine();
const alpha = project(box, 'alpha');