aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-28 20:22:06 -0700
committerAdam Soltys <[email protected]>2026-09-28 20:22:06 -0700
commitf95093a90637abfa9f0adbb3d7d28127ecd20569 (patch)
tree31ed8de577bd9ed022401366932262536067929e
parent5989090d93119fd10c642db622986227e4ae1b03 (diff)
downloadcoinosv3-f95093a90637abfa9f0adbb3d7d28127ecd20569.tar.gz
coinosv3-f95093a90637abfa9f0adbb3d7d28127ecd20569.zip
Add scrolling feed navigation for home, messages and notifications
-rw-r--r--src/features/messages.js27
-rw-r--r--src/style.css18
-rw-r--r--tools/feed-bottom-nav-test.js73
3 files changed, 117 insertions, 1 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 31a3e4d..3af968f 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -3472,6 +3472,9 @@ export function messagesFeature(ctx) {
// only runs once a wallet opens.
if (typeof window !== 'undefined') {
window.addEventListener('scroll', () => {
+ // Update just the navigation visibility; scrolling must not repaint posts.
+ const nav = document.querySelector('.feed-bottom-nav');
+ if (nav) nav.hidden = window.scrollY < 160;
if (!ui.profilePk && (!(ui.chatOpen && ui.msgView === 'feed') || ui.noteThread)) return;
windowScrolled(ui.profilePk ? notesCache.get(ui.profilePk) : feed);
// back at the top by yourself: the new posts are under your eyes, so
@@ -7524,6 +7527,27 @@ export function messagesFeature(ctx) {
} catch {}
}, 0);
}
+ function feedBottomNav() {
+ const icon = (paths) => '<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + paths + '</svg>';
+ const button = (label, paths, onClick) => h('button', {
+ type: 'button', class: 'feed-nav-button', 'aria-label': label, onClick,
+ }, h('span', { html: icon(paths) }), h('span', {}, label));
+ return h('nav', {
+ class: 'feed-bottom-nav', 'data-key': 'feed-bottom-nav', 'aria-label': t('feedTitle'),
+ hidden: typeof window === 'undefined' || window.scrollY < 160,
+ },
+ button(t('home'), '<path d="m3 10 9-7 9 7v10a1 1 0 0 1-1 1h-5v-7H9v7H4a1 1 0 0 1-1-1z"/>', jumpToNew),
+ button(t('msgDmsTitle'), '<path d="M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8z"/>', () => {
+ if (signinAsk()) return;
+ stopFeedWatch(); ui.msgView = 'home'; render();
+ window.scrollTo({ top: 0 });
+ }),
+ button(t('alertsTitle'), '<path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4"/>', () => {
+ if (signinAsk()) return;
+ stopFeedWatch(); openNotifs();
+ window.scrollTo({ top: 0 });
+ }));
+ }
function feedView() {
syncFollowSets().catch(() => {}); // throttled inside
syncReports().catch(() => {}); // likewise
@@ -7563,7 +7587,7 @@ export function messagesFeature(ctx) {
waiting === 1 ? t('feedOneNewWord') : t('feedNNewWord'))
: null;
// the chat shell draws the brand header; this is just the page under it
- return h('div', { class: 'card col chat-page', style: 'gap:10px' },
+ return h('div', { class: 'card col chat-page feed-page', style: 'gap:10px' },
h('div', { 'data-key': 'feed-notice', style: 'display:contents' }, pill),
h('div', { class: 'row gap6', style: 'align-items:center' },
backBtn(() => {
@@ -7618,6 +7642,7 @@ export function messagesFeature(ctx) {
// the reader's language, right where a curated feed is judged by it
ctx.languagePicker ? h('div', { class: 'row gap6 feed-lang', 'data-key': 'feed-lang', style: 'justify-content:center;align-items:center;padding:6px 0 2px' },
h('span', { class: 'small muted' }, t('feedLangLabel')), ctx.languagePicker()) : null,
+ feedBottomNav(),
...noteOverlays());
}
diff --git a/src/style.css b/src/style.css
index 6507ba5..d2ad443 100644
--- a/src/style.css
+++ b/src/style.css
@@ -770,6 +770,24 @@ html.no-scroll { overflow: hidden; scrollbar-gutter: auto; }
feed near the top, out of the way of the thumb, and takes you up to them
when tapped. Fixed, not sticky: the feed is the page scroller, and a
sticky element inside the card would scroll away with the card. */
+.feed-page { padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }
+.feed-bottom-nav {
+ position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
+ z-index: 30; display: flex; width: min(100%, 560px); box-sizing: border-box;
+ padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
+ background: var(--paper); border-top: 1px solid var(--line);
+ box-shadow: 0 -4px 18px rgba(0, 0, 0, .06);
+}
+.feed-bottom-nav[hidden] { display: none; }
+.feed-nav-button {
+ display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: center;
+ justify-content: center; gap: 3px; min-height: 52px; padding: 4px;
+ border: 0; background: transparent; color: var(--ink); font-size: 12px;
+}
+.feed-nav-button > span:first-child { display: flex; }
+.feed-page:has(.feed-bottom-nav:not([hidden])) .feed-new-pill {
+ bottom: calc(env(safe-area-inset-bottom, 0px) + 82px);
+}
.feed-new-pill {
/* Rides at the bottom of the window, where a thumb already is; the tap
takes the reader up to the new posts. */
diff --git a/tools/feed-bottom-nav-test.js b/tools/feed-bottom-nav-test.js
new file mode 100644
index 0000000..f277c4a
--- /dev/null
+++ b/tools/feed-bottom-nav-test.js
@@ -0,0 +1,73 @@
+// Real feed/navigation views with local posts and no relay traffic.
+// Run: bun tools/feed-bottom-nav-test.js
+import assert from 'node:assert/strict';
+import puppeteer from 'puppeteer-core';
+const app = await Bun.file('src/app.js').text();
+const dom = app.slice(app.indexOf('function h(tag,'), app.indexOf("const root = document.getElementById('app');"));
+const entry = `
+import { messagesFeature } from './src/features/messages.js';
+${dom}
+const author = 'a'.repeat(64);
+const ui = { screen: 'wallet', chatOpen: true, msgView: 'feed' };
+const wallet = { xpub: 'test-wallet', loaded: true, nostrRelays: () => [],
+ loadFeatureState: (k, d) => k === 'follows' ? { tags: [['p', author]], at: Date.now()/1000 } : d,
+ saveFeatureState() {}, registerCacheExtension() {} };
+let feature;
+function render() { if (feature) morphChildren(document.querySelector('#app'), [feature.screenView()]); }
+feature = messagesFeature({ h, ui, wallet, render, toast() {}, hook() {}, brandHeader: () => h('div', { style: 'height:60px' }, 'Coinos') });
+window.test = { ui, wallet, render, async feed() {
+ ui.chatOpen = true; ui.msgView = 'feed'; ui.noteThread = null;
+ await feature.testSeed(Array.from({length:20}, (_, i) => ({ id: i.toString(16).padStart(64,'0'), pubkey:author, kind:1, tags:[], created_at:Math.floor(Date.now()/1000)-i,
+ content: 'A post in the feed. Scroll to keep Home, messages and notifications within reach. '.repeat(3) })));
+ render(); window.scrollTo(0,0);
+}, unseen() { feature.testUnseen(); render(); } };
+await test.feed();
+`;
+const bundle = await Bun.build({ entrypoints: ['nav-test-entry'], target: 'browser', plugins: [{ name: 'nav-test', setup(build) {
+ build.onResolve({filter:/^nav-test-entry$/},()=>({path:'entry',namespace:'nav-test'}));
+ build.onLoad({filter:/.*/,namespace:'nav-test'},()=>({contents:entry,loader:'js',resolveDir:process.cwd()}));
+ build.onLoad({filter:/src\/features\/messages\.js$/},async({path})=>({loader:'js',contents:(await Bun.file(path).text()).replace("id: 'messages',", "id: 'messages', testSeed: async (notes) => { const c = feedNow(); await c.boot; Object.assign(c, { notes, status: 'ready', booting: false, end: true, shown: 20 }); }, testUnseen: () => { feed.unseen = 2; },")}));
+ build.onLoad({filter:/src\/nostr\.js$/},async({path})=>({loader:'js',contents:(await Bun.file(path).text())
+ .replace('export async function queryOn(relays, filter, maxWait = 1500) {','export async function queryOn(relays, filter, maxWait = 1500) { return [];')
+ .replace(/export function subscribeOn\(([^)]*)\) \{/,'export function subscribeOn($1) { return () => {};')}));
+} }] });
+assert(bundle.success,bundle.logs.join('\n'));
+const html=`<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>${await Bun.file('src/style.css').text()}</style><div id="app"></div><script type="module">${await bundle.outputs[0].text()}</script>`;
+const remote = !!process.env.BROWSER_URL;
+const server=Bun.serve({port:remote ? 5303 : 0,fetch:()=>new Response(html,{headers:{'content-type':'text/html'}})});
+const browser=remote ? await puppeteer.connect({browserURL:process.env.BROWSER_URL}) : await puppeteer.launch({executablePath:'/usr/bin/google-chrome',headless:true,args:['--no-sandbox']});
+const page=await browser.newPage(), errors=[];
+page.on('pageerror', e=>errors.push(e.message));
+await page.setRequestInterception(true);
+page.on('request',r=>r.url().startsWith(server.url.origin)?r.continue():r.abort());
+const scroll=async()=>{ await page.evaluate(()=>window.scrollTo(0,700)); await page.waitForFunction(()=>!document.querySelector('.feed-bottom-nav')?.hidden); };
+try {
+ await page.setViewport({width:390,height:844,isMobile:true,hasTouch:true});
+ await page.emulateMediaFeatures([{name:'prefers-reduced-motion',value:'reduce'}]);
+ await page.goto(server.url.href);
+ await page.waitForSelector('.note-post', {timeout:5000});
+ assert(await page.$eval('.feed-bottom-nav',e=>e.hidden),'hidden at top');
+ await scroll();
+ assert.deepEqual(await page.$$eval('.feed-nav-button',els=>els.map(e=>e.textContent)),['Home','Messages','Notifications']);
+ assert(await page.$eval('.feed-bottom-nav',e=>Math.abs(e.getBoundingClientRect().bottom-innerHeight)<1),'fixed at viewport bottom');
+ await page.evaluate(()=>test.unseen());
+ assert(await page.evaluate(()=>document.querySelector('.feed-new-pill').getBoundingClientRect().bottom < document.querySelector('.feed-bottom-nav').getBoundingClientRect().top),'new posts pill stays above navigation');
+ await page.screenshot({path:'/tmp/feed-bottom-nav-mobile.png'});
+ await page.tap('.feed-nav-button:nth-child(1)');
+ await page.waitForFunction(()=>scrollY===0 && document.querySelector('.feed-bottom-nav').hidden);
+ assert.equal(await page.evaluate(()=>test.ui.msgView),'feed','Home stays in feed');
+ await scroll(); await page.tap('.feed-nav-button:nth-child(2)');
+ await page.waitForFunction(()=>test.ui.msgView==='home' && !document.querySelector('.feed-bottom-nav'));
+ assert((await page.evaluate(()=>document.body.innerText)).includes('Messages'),'chat list renders');
+ await page.evaluate(()=>test.feed()); await scroll(); await page.tap('.feed-nav-button:nth-child(3)');
+ await page.waitForFunction(()=>test.ui.msgView==='notifs' && !document.querySelector('.feed-bottom-nav'));
+ assert((await page.evaluate(()=>document.body.innerText)).includes('Notifications'),'notifications render');
+ await page.evaluate(()=>test.feed()); await scroll(); await page.tap('.note-text');
+ await page.waitForFunction(()=>!!test.ui.noteThread && !document.querySelector('.feed-bottom-nav'));
+ await page.evaluate(()=>test.feed());
+ await page.evaluate(()=>{test.wallet.xpub=null;test.render();}); await scroll();
+ await page.tap('.feed-nav-button:nth-child(2)');
+ assert(await page.evaluate(()=>test.ui.signinAsk && test.ui.msgView==='feed'),'visitor gets sign-in prompt');
+ assert.deepEqual(errors,[]);
+ console.log('✓ Feed nav appears on scroll; Home returns to top; Messages and Notifications open their views; nav leaves threads; visitor sign-in and new-post pill work');
+} finally { await page.close(); if (remote) await browser.disconnect(); else await browser.close(); server.stop(true); }