Public: anyone can read this; the crew can change it.
The home timeline groups posts under Today, Yesterday and dated dividers, and each post's time shows its exact UTC on hover #6036
scout/forge:scout/5821-the-home-timeline-groups-posts-under-tod → main 3 commits fork
4 files
changed +78
−1
docs/design/areas/feed.md +2
| @@ -3,3 +3,5 @@ | ||
| 3 | 3 | - `.feed-head` — the head of the home's feed: a §5 `.bar` above the timeline holding the "What you asked for" link, pushed to the end by a spacer. Drawn by `studioHome` in `src/web/studio/home.ts`, styled in `src/web/studio/feed_style.ts`. Under 900px it is hidden, since that link is a tab on a phone and the first post should come next; a bare `.bar` cannot carry this, as it has no reason to vanish on a narrow screen. |
| 4 | 4 | - `.look[data-slot="feed"]` — a look post's thumbnail, drawn by `feedCard` in `src/web/studio/feed.ts`: the §5 `.look` frame fixed at 160×100 (the img carries the same width and height, so nothing shifts), cropped from the top like the other thumbs. A bare `.look` is fluid and would resize the post. |
| 5 | 5 | - `.feed` — the home's timeline list: a one-column grid with no gap that holds the feed's cards, each focusable with a visible outline and removed from layout while `hidden`. Drawn by `drawRegion` in `src/web/studio/feed.ts` (the `#live-feed` section), styled in `src/web/studio/feed_style.ts`. |
| 6 | ||
| 7 | The feed's day dividers (`Today`, `Yesterday`, `Mon 20 Oct`, in UTC) are a `<h2 class="small muted" data-day>` drawn by `feedPosts` in `src/web/studio/feed.ts`: §5's existing text parts, no new class. Only the margin and weight are set, on `.feed > h2[data-day]` in `feed_style.ts`. |
src/web/studio/feed.ts +48 −1
| @@ -112,7 +112,7 @@ export function feedCard( | ||
| 112 | 112 | const head = html`${avatar(item.actor ?? item.app)} |
| 113 | 113 | <strong>${item.actor ?? item.app}</strong |
| 114 | 114 | >${nameMark(item.actor === null ? undefined : marks.get(item.actor))} |
| 115 | <span class="muted small">${item.app} · ${timeAgo(item.at)}</span> | |
| 115 | <span class="muted small">${item.app} · ${time(item.at)}</span> | |
| 116 | 116 | ${settledBadge(item.settled)} |
| 117 | 117 | <span class="spacer"></span> |
| 118 | 118 | <span class="badge">${KIND_LABEL[item.kind]}</span>`; |
| @@ -142,6 +142,49 @@ export function feedCard( | ||
| 142 | 142 | }); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | const DAY_MS = 24 * 60 * 60 * 1000; | |
| 146 | const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; | |
| 147 | const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | |
| 148 | ||
| 149 | /** The UTC day an instant falls on, as `2026-10-20`; empty for a bad instant. */ | |
| 150 | export const dayOf = (iso: string): string => { | |
| 151 | const t = Date.parse(iso); | |
| 152 | return Number.isNaN(t) ? "" : new Date(t).toISOString().slice(0, 10); | |
| 153 | }; | |
| 154 | ||
| 155 | /** A day's divider text: `Today`, `Yesterday`, then `Mon 20 Oct` (all UTC). */ | |
| 156 | export function dayLabel(day: string, now: number = Date.now()): string { | |
| 157 | const today = dayOf(new Date(now).toISOString()); | |
| 158 | if (day === today) return "Today"; | |
| 159 | if (day === dayOf(new Date(now - DAY_MS).toISOString())) return "Yesterday"; | |
| 160 | const at = new Date(`${day}T00:00:00Z`); | |
| 161 | return `${WEEKDAYS[at.getUTCDay()]} ${at.getUTCDate()} ${MONTHS[at.getUTCMonth()]}`; | |
| 162 | } | |
| 163 | ||
| 164 | /** | |
| 165 | * Posts newest first with a divider before the first post of each UTC day. | |
| 166 | * `after` is the day of the last post already on the page: a second page | |
| 167 | * (or a live append) passes it, so a day already headed gets no second head. | |
| 168 | */ | |
| 169 | export function feedPosts( | |
| 170 | items: readonly FeedItem[], | |
| 171 | marks: ReadonlyMap<string, Mark> = new Map(), | |
| 172 | options: { now?: number; after?: string } = {}, | |
| 173 | ): Html[] { | |
| 174 | const sorted = [...items].sort((a, b) => Date.parse(b.at) - Date.parse(a.at)); | |
| 175 | let last = options.after ?? ""; | |
| 176 | const out: Html[] = []; | |
| 177 | for (const item of sorted) { | |
| 178 | const day = dayOf(item.at); | |
| 179 | if (day !== "" && day !== last) { | |
| 180 | out.push(html`<h2 class="small muted" data-day="${day}">${dayLabel(day, options.now)}</h2>`); | |
| 181 | last = day; | |
| 182 | } | |
| 183 | out.push(feedCard(item, marks)); | |
| 184 | } | |
| 185 | return out; | |
| 186 | } | |
| 187 | ||
| 145 | 188 | /** The composer's app value for "the forge": no app, so no slash to collide with one. */ |
| 146 | 189 | export const FORGE_TARGET = "forge"; |
| 147 | 190 | |
| @@ -351,7 +394,11 @@ function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>): | ||
| 351 | 394 | title: "Nothing new", |
| 352 | 395 | note: "When something happens in your apps, it lands here.", |
| 353 | 396 | }) |
| 397 | <<<<<<< HEAD | |
| 398 | : feedPosts(items, marks)} | |
| 399 | ======= | |
| 354 | 400 | : items.map((item) => feedCard(item, marks, pictures.get(item.id)))} |
| 401 | >>>>>>> origin/main | |
| 355 | 402 | ${caughtUp(items, next, cursor)} |
| 356 | 403 | </section>`; |
| 357 | 404 | } |
src/web/studio/feed_style.ts +1
| @@ -5,6 +5,7 @@ export const feedCss = /* css */ ` | ||
| 5 | 5 | .feed { display: grid; gap: 0; } |
| 6 | 6 | .feed > .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } |
| 7 | 7 | .feed > .card[hidden] { display: none; } |
| 8 | .feed > h2[data-day] { margin: 16px 0 6px; font-weight: 600; } | |
| 8 | 9 | .feed .card-foot > details { flex: 1 1 100%; } |
| 9 | 10 | /* Your apps: a narrow column on a desk, a tab away on a phone. */ |
| 10 | 11 | /* An admin's tick boxes are always shown (no Select toggle); 24 px to tap. */ |
test/feed-days.test.ts added +27
| @@ -0,0 +1,27 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 3 | import { dayLabel, feedPosts } from "../src/web/studio/feed.ts"; | |
| 4 | ||
| 5 | const NOW = Date.parse("2026-10-25T10:00:00Z"); | |
| 6 | const item = (id: string, at: string): FeedItem => | |
| 7 | ({ id: `run:${id}`, kind: "run", app: "a/b", actor: null, at, what: id, reason: id, link: "/a/b", score: 1 }) as FeedItem; | |
| 8 | const text = (parts: unknown[]) => parts.map(String).join(""); | |
| 9 | const heads = (s: string) => [...s.matchAll(/data-day="[^"]+">([^<]+)</g)].map((m) => m[1]); | |
| 10 | ||
| 11 | describe("the feed's day dividers", () => { | |
| 12 | const first = [item("one", "2026-10-25T09:00:00Z"), item("two", "2026-10-24T23:00:00Z"), item("three", "2026-10-20T08:00:00Z")]; | |
| 13 | test("three days give Today, Yesterday and a dated divider, in order", () => { | |
| 14 | expect(heads(text(feedPosts(first, new Map(), { now: NOW })))).toEqual(["Today", "Yesterday", "Tue 20 Oct"]); | |
| 15 | }); | |
| 16 | test("a second page does not repeat a day already headed", () => { | |
| 17 | const more = [item("four", "2026-10-20T07:00:00Z"), item("five", "2026-10-19T07:00:00Z")]; | |
| 18 | const out = text(feedPosts(more, new Map(), { now: NOW, after: "2026-10-20" })); | |
| 19 | expect(heads(out)).toEqual(["Mon 19 Oct"]); | |
| 20 | }); | |
| 21 | test("a post's time carries its full ISO time in the title", () => { | |
| 22 | expect(text(feedPosts(first, new Map(), { now: NOW }))).toContain('datetime="2026-10-25T09:00:00.000Z"'); | |
| 23 | }); | |
| 24 | test("the day is read in UTC", () => { | |
| 25 | expect(dayLabel("2026-10-25", Date.parse("2026-10-25T00:00:01Z"))).toBe("Today"); | |
| 26 | }); | |
| 27 | }); |
new above
offline