From 8d2f2c72a7bb7087879e110f8575bcef00bbc2c0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Nov 2026 16:09:04 -0700 Subject: Scrolling the feed shows when you are. "When I'm scrolling the feed, could we have some sort of little counter that shows the date and time of posts where I'm in the timeline, so I can kind of roughly gauge how far back I've scrolled in time?" (Adam, 2026-11-17). Past the first screenful, a small chip under the top bar shows the date and time of the post at the top of the screen, and how long ago it was (Mon 16 Nov · 09:57 · yesterday). It updates as the feed or a profile's posts move and fades 1.2 s after scrolling stops. It is drawn straight into the page each frame, outside render(). New feed-when-test passes, along with feed-new-posts and features-smoke. feed-stability fails at the same step with and without this change. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- src/features/messages.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/features') diff --git a/src/features/messages.js b/src/features/messages.js index 6875856..6b3ff4c 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -5420,6 +5420,7 @@ export function messagesFeature(ctx) { lastScrollAt = Date.now(); if (!ui.profilePk && (!(ui.chatOpen && ui.msgView === 'feed') || ui.noteThread)) return; windowScrolled(ui.profilePk ? notesCache.get(ui.profilePk) : feed); + scrollWhen(ui.profilePk ? notesCache.get(ui.profilePk) : feed); // Starting to scroll up dismisses the notice: the reader is already // heading toward the new posts. Keyed rows keep their positions. // Upward only: holding the page still as posts go in above scrolls it @@ -5442,6 +5443,63 @@ export function messagesFeature(ctx) { else loadOlderFeed().catch(() => {}); }, { passive: true }); } + // How far back you've scrolled: while the feed (or a profile's posts) + // moves, a small chip under the top bar says when the post at the top of + // the screen was written, and fades a moment after the scrolling stops + // ("some sort of little counter that shows the date and time of posts + // where I'm in the timeline", Adam, 2026-11-17). Painted straight into the + // DOM, outside render(): it changes every frame of a fling. + let whenEl = null, whenRaf = 0, whenHide = 0, whenIdx = { list: null, map: null }; + function whenLabel(sec) { + const d = new Date(sec * 1000), now = new Date(); + const time = d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }); + const date = d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric', ...(d.getFullYear() !== now.getFullYear() ? { year: 'numeric' } : {}) }); + const ago = Math.max(0, (now - d) / 1000); + let rel = ''; + try { + const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' }); + rel = ago < 3600 ? rtf.format(-Math.max(1, Math.round(ago / 60)), 'minute') + : ago < 86400 ? rtf.format(-Math.round(ago / 3600), 'hour') + : ago < 86400 * 60 ? rtf.format(-Math.round(ago / 86400), 'day') + : ago < 86400 * 730 ? rtf.format(-Math.round(ago / (86400 * 30.4)), 'month') + : rtf.format(-Math.round(ago / (86400 * 365)), 'year'); + } catch {} + const today = d.toDateString() === now.toDateString(); + return (today ? time : date + ' · ' + time) + (rel ? ' · ' + rel : ''); + } + function scrollWhen(c) { + if (whenRaf || typeof document === 'undefined') return; + whenRaf = requestAnimationFrame(() => { + whenRaf = 0; + const list = c?.winList ? c.winList() : null; + const rows = list ? document.querySelectorAll('.notes-feed > .row[data-key]') : []; + const head = document.querySelector('.brand-header'); + const top = head ? Math.max(0, head.getBoundingClientRect().bottom) : 0; + // the post at the top of the screen, below the bar + let key = null, box = null; + for (const r of rows) { + const b = r.getBoundingClientRect(); + if (b.bottom > top + 12) { key = r.getAttribute('data-key'); box = r.parentElement.getBoundingClientRect(); break; } + } + if (whenIdx.list !== list) whenIdx = { list, map: list ? new Map(list.map((e) => [e.id, e])) : null }; + const ev = key && whenIdx.map?.get(key); + // only once you're past the first screenful: at the top the posts' own times say it + if (!ev || (window.scrollY || 0) < window.innerHeight * 0.75) { if (whenEl) whenEl.classList.remove('on'); return; } + if (!whenEl) { + whenEl = document.createElement('div'); + whenEl.className = 'feed-when'; + whenEl.setAttribute('aria-hidden', 'true'); + document.body.appendChild(whenEl); + } + const label = whenLabel(ev.created_at); + if (whenEl.textContent !== label) whenEl.textContent = label; + whenEl.style.top = (top + 8) + 'px'; + whenEl.style.left = (box.left + box.width / 2) + 'px'; + whenEl.classList.add('on'); + clearTimeout(whenHide); + whenHide = setTimeout(() => whenEl && whenEl.classList.remove('on'), 1200); + }); + } async function loadOlderNotes(pk) { const c = notesCache.get(pk); if (!c || c.status !== 'ready' || c.loadingMore || c.end) return; -- cgit v1.2.3