v2.0.5 — Read feature (mobile zen reader on the relay)
Per-card opt-in push to the relay for distraction-free mobile reading.
Not tag-based: a real cards.read_push column so the reading state
stays independent of whatever tags the user organises by.
hyprcrd
- cards.read_push column (0/1, default 0) via Database migration.
- POST /api/cards + PATCH /api/cards/{id} accept read_push; save hook
posts the card (title+body, encrypted) and referenced images
to the relay's /api/read endpoint. First inline image is flagged
as the hero. Toggle-off / DELETE wipes the remote copy.
- Detail-bar toggle button ("Read" → "On relay") with filled book
icon + inverted accent background when active; outline book icon
in the bottom meta row of the board card when read_push=1.
relay
- read_items + read_attachments tables, encrypted under the
inter-tenant key like messages (dual-format envelope).
- Client API: POST /api/read, DELETE /api/read/{uid}, POST
/api/read-attachments. Session API: GET /api/read (list),
GET /api/read/{uid} (single decrypted), GET /api/read-attachments/
{uid}/{filename} (serves decrypted image bytes).
- Payload size caps raised to 15MB (attachments) / 2MB (items).
- New nav tab + view: list with thumbnails, click opens a zen reader
overlay. Reader caps article width at 680px, bumps type to 17px/1.7,
renders a minimal markdown subset (headings, lists, code fences,
blockquotes, links, inline images), rewrites uploads/ references
to the session-authed image endpoint. Escape closes the reader.
- Mobile-first: wider touch targets, tighter padding at ≤640px.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f986a41ccc
commit
1e51bdec7c
12 files changed
+840
-17
No files matched your search
+194
-4
@@ -68,17 +68,18 @@ function showView(name) {
|
||||
if (me && me.password_changed === false && !['setup', 'login', 'change-password'].includes(name)) {
|
||||
name = 'change-password';
|
||||
}
|
||||
['setup', 'login', 'change-password', 'compose', 'inbox', 'account', 'admin', 'chat', 'shopping'].forEach(v => {
|
||||
['setup', 'login', 'change-password', 'compose', 'inbox', 'account', 'admin', 'chat', 'shopping', 'read'].forEach(v => {
|
||||
$('view-' + v)?.classList.add('hidden');
|
||||
});
|
||||
$('view-' + name)?.classList.remove('hidden');
|
||||
|
||||
if (['compose', 'inbox', 'account', 'admin', 'chat', 'shopping'].includes(name)) {
|
||||
if (['compose', 'inbox', 'account', 'admin', 'chat', 'shopping', 'read'].includes(name)) {
|
||||
$('nav-buttons').classList.remove('hidden');
|
||||
$('nav-compose').classList.toggle('active', name === 'compose');
|
||||
$('nav-inbox')?.classList.toggle('active', name === 'inbox');
|
||||
$('nav-chat')?.classList.toggle('active', name === 'chat');
|
||||
$('nav-shopping')?.classList.toggle('active', name === 'shopping');
|
||||
$('nav-read')?.classList.toggle('active', name === 'read');
|
||||
$('nav-account').classList.toggle('active', name === 'account');
|
||||
$('nav-admin').classList.toggle('active', name === 'admin');
|
||||
$('nav-burger')?.classList.remove('hidden');
|
||||
@@ -119,9 +120,14 @@ function showView(name) {
|
||||
} else {
|
||||
stopShoppingPoll();
|
||||
}
|
||||
if (name === 'read') {
|
||||
loadReadList();
|
||||
// Close any open article when switching into the list view.
|
||||
closeReader();
|
||||
}
|
||||
// Remember the active view so a page reload lands back here
|
||||
// instead of defaulting to compose every time.
|
||||
if (['compose', 'inbox', 'account', 'admin', 'chat', 'shopping'].includes(name)) {
|
||||
if (['compose', 'inbox', 'account', 'admin', 'chat', 'shopping', 'read'].includes(name)) {
|
||||
try { localStorage.setItem('relay-last-view', name); } catch {}
|
||||
}
|
||||
if (name === 'admin') {
|
||||
@@ -278,7 +284,7 @@ function routePostLogin(status) {
|
||||
toast('set your client secret to start using the relay');
|
||||
} else {
|
||||
const last = localStorage.getItem('relay-last-view') || 'compose';
|
||||
showView(['compose', 'inbox', 'account', 'admin', 'chat', 'shopping'].includes(last) ? last : 'compose');
|
||||
showView(['compose', 'inbox', 'account', 'admin', 'chat', 'shopping', 'read'].includes(last) ? last : 'compose');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1179,3 +1185,187 @@ document.addEventListener('keydown', e => {
|
||||
if (document.activeElement?.id === 'compose-body' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); sendCompose(); }
|
||||
}
|
||||
});
|
||||
|
||||
// ── Read view: list + zen reader ──────────────────────────────────
|
||||
//
|
||||
// The hyprcrd client pushes cards here when the user toggles "Read later"
|
||||
// on a card. This view renders the list, and the reader overlay renders
|
||||
// the markdown in a mobile-first, distraction-free column. Images in the
|
||||
// body are rewritten to the relay's session-authed image endpoint.
|
||||
|
||||
let readCurrentUid = null;
|
||||
|
||||
async function loadReadList() {
|
||||
const list = $('read-items');
|
||||
const empty = $('read-empty');
|
||||
if (!list) return;
|
||||
list.innerHTML = '';
|
||||
try {
|
||||
const res = await api('api/read');
|
||||
const items = res?.items || [];
|
||||
if (!items.length) {
|
||||
empty.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
empty.classList.add('hidden');
|
||||
list.innerHTML = items.map(it => {
|
||||
const title = it.title?.trim() || '(untitled)';
|
||||
const thumb = it.hero_filename
|
||||
? `<div class="read-item-thumb" style="background-image:url('api/read-attachments/${encodeURIComponent(it.relay_uid)}/${encodeURIComponent(it.hero_filename)}');"></div>`
|
||||
: `<div class="read-item-thumb read-item-thumb-placeholder"><i class="ph ph-book-open"></i></div>`;
|
||||
return `
|
||||
<li class="read-item" data-uid="${escapeHtml(it.relay_uid)}">
|
||||
${thumb}
|
||||
<div class="read-item-body">
|
||||
<div class="read-item-title">${escapeHtml(title)}</div>
|
||||
<div class="read-item-meta">${escapeHtml(formatRelTime(it.updated_at))}</div>
|
||||
</div>
|
||||
</li>`;
|
||||
}).join('');
|
||||
list.querySelectorAll('.read-item').forEach(el => {
|
||||
el.addEventListener('click', () => openReader(el.dataset.uid));
|
||||
});
|
||||
} catch (e) {
|
||||
list.innerHTML = `<li style="color:var(--danger);font-size:12px;">Failed to load: ${escapeHtml(e.message)}</li>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function openReader(uid) {
|
||||
const reader = $('read-reader');
|
||||
const article = $('read-article');
|
||||
if (!reader || !article) return;
|
||||
readCurrentUid = uid;
|
||||
article.innerHTML = '<p style="color:var(--dim);">loading…</p>';
|
||||
reader.classList.remove('hidden');
|
||||
reader.scrollTop = 0;
|
||||
try {
|
||||
const res = await api('api/read/' + encodeURIComponent(uid));
|
||||
if (res?.error) throw new Error(res.error);
|
||||
article.innerHTML = renderReadArticle(res);
|
||||
} catch (e) {
|
||||
article.innerHTML = `<p style="color:var(--danger);">Failed to load: ${escapeHtml(e.message)}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
function closeReader() {
|
||||
readCurrentUid = null;
|
||||
$('read-reader')?.classList.add('hidden');
|
||||
}
|
||||
|
||||
function renderReadArticle(item) {
|
||||
const title = item.title?.trim() || '(untitled)';
|
||||
const rawBody = item.body || '';
|
||||
// Hero: first uploads/<hex>.<ext> reference in body. Rewrite to the
|
||||
// session-authed relay endpoint so the <img src> resolves server-side
|
||||
// against the tenant's own read_attachments rows.
|
||||
const uid = encodeURIComponent(item.relay_uid);
|
||||
const bodyForRender = rawBody.replace(
|
||||
/uploads\/([a-f0-9]+\.[a-z0-9]+)/gi,
|
||||
(_m, fn) => `api/read-attachments/${uid}/${encodeURIComponent(fn)}`
|
||||
);
|
||||
const hero = item.hero_filename
|
||||
? `<img class="read-hero" src="api/read-attachments/${uid}/${encodeURIComponent(item.hero_filename)}" alt="">`
|
||||
: '';
|
||||
const date = item.updated_at ? formatRelTime(item.updated_at) : '';
|
||||
return `
|
||||
${hero}
|
||||
<h1 class="read-title">${escapeHtml(title)}</h1>
|
||||
<div class="read-date">${escapeHtml(date)}</div>
|
||||
${renderMarkdown(bodyForRender)}
|
||||
`;
|
||||
}
|
||||
|
||||
// Tiny inline markdown renderer. Covers the cases hyprcrd cards actually
|
||||
// use: paragraphs, headings, bold/italic, inline code, links, bullet +
|
||||
// numbered lists, blockquotes, hr, fenced code blocks, inline images.
|
||||
// We do NOT pull a full library in — this matches the UI's existing
|
||||
// minimal-deps stance (fonts + phosphor, nothing else).
|
||||
function renderMarkdown(src) {
|
||||
if (!src) return '';
|
||||
const placeholders = [];
|
||||
const stash = (html) => { placeholders.push(html); return `\u0000${placeholders.length - 1}\u0000`; };
|
||||
|
||||
// Fenced code
|
||||
src = src.replace(/```(\w+)?\n([\s\S]*?)```/g, (_m, _lang, code) =>
|
||||
stash(`<pre><code>${escapeHtml(code)}</code></pre>`));
|
||||
// Inline code
|
||||
src = src.replace(/`([^`\n]+)`/g, (_m, c) => stash(`<code>${escapeHtml(c)}</code>`));
|
||||
|
||||
// Escape remaining HTML
|
||||
src = escapeHtml(src);
|
||||
|
||||
// Restore stashed code first (before we mangle further)
|
||||
src = src.replace(/\u0000(\d+)\u0000/g, (_m, i) => placeholders[Number(i)]);
|
||||
|
||||
// Images: 
|
||||
src = src.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (_m, alt, url) =>
|
||||
`<img src="${escapeAttr(url)}" alt="${escapeAttr(alt)}">`);
|
||||
// Links: [text](url)
|
||||
src = src.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, text, url) =>
|
||||
`<a href="${escapeAttr(url)}" target="_blank" rel="noopener">${text}</a>`);
|
||||
|
||||
// Headings (## etc.), line-anchored
|
||||
src = src.replace(/^###\s+(.+)$/gm, '<h3>$1</h3>');
|
||||
src = src.replace(/^##\s+(.+)$/gm, '<h2>$1</h2>');
|
||||
src = src.replace(/^#\s+(.+)$/gm, '<h1>$1</h1>');
|
||||
|
||||
// HR
|
||||
src = src.replace(/^---+$/gm, '<hr>');
|
||||
|
||||
// Blockquotes: consecutive "> " lines collapse into one <blockquote>
|
||||
src = src.replace(/(^|\n)((?:> [^\n]*\n?)+)/g, (_m, pre, block) => {
|
||||
const inner = block.replace(/^> ?/gm, '').trim();
|
||||
return `${pre}<blockquote>${inner.replace(/\n/g, '<br>')}</blockquote>\n`;
|
||||
});
|
||||
|
||||
// Lists: grouped runs of "- " / "* " / "N." items
|
||||
src = src.replace(/(^|\n)((?:[-*]\s+[^\n]+\n?)+)/g, (_m, pre, block) => {
|
||||
const items = block.trim().split(/\n/).map(l => l.replace(/^[-*]\s+/, '')).map(i => `<li>${i}</li>`).join('');
|
||||
return `${pre}<ul>${items}</ul>\n`;
|
||||
});
|
||||
src = src.replace(/(^|\n)((?:\d+\.\s+[^\n]+\n?)+)/g, (_m, pre, block) => {
|
||||
const items = block.trim().split(/\n/).map(l => l.replace(/^\d+\.\s+/, '')).map(i => `<li>${i}</li>`).join('');
|
||||
return `${pre}<ol>${items}</ol>\n`;
|
||||
});
|
||||
|
||||
// Bold + italic (do bold first to avoid partial capture)
|
||||
src = src.replace(/\*\*([^*\n]+)\*\*/g, '<strong>$1</strong>');
|
||||
src = src.replace(/(?<!\w)\*([^*\n]+)\*(?!\w)/g, '<em>$1</em>');
|
||||
|
||||
// Paragraphs: wrap any run of non-block-level lines. Block-level tags
|
||||
// we've already emitted stay as-is.
|
||||
const blocks = src.split(/\n{2,}/);
|
||||
return blocks.map(b => {
|
||||
const t = b.trim();
|
||||
if (!t) return '';
|
||||
if (/^<(h[1-6]|ul|ol|pre|blockquote|hr|img)/.test(t)) return t;
|
||||
return `<p>${t.replace(/\n/g, '<br>')}</p>`;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
function escapeAttr(s) {
|
||||
return String(s ?? '').replace(/["&<>]/g, c => ({ '"': '"', '&': '&', '<': '<', '>': '>' }[c]));
|
||||
}
|
||||
|
||||
$('read-back')?.addEventListener('click', closeReader);
|
||||
$('read-delete')?.addEventListener('click', async () => {
|
||||
if (!readCurrentUid) return;
|
||||
if (!await relayConfirm('Remove this item from your read list?', { okLabel: 'Remove', danger: true })) return;
|
||||
const uid = readCurrentUid;
|
||||
try {
|
||||
await api('api/read/' + encodeURIComponent(uid), { method: 'DELETE' });
|
||||
closeReader();
|
||||
loadReadList();
|
||||
toast('removed');
|
||||
} catch (e) {
|
||||
toast(e.message || 'failed', true);
|
||||
}
|
||||
});
|
||||
|
||||
// Browser back should close the reader first, then leave the view.
|
||||
window.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape' && readCurrentUid) {
|
||||
e.preventDefault();
|
||||
closeReader();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user