Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354// How many articles a publication has, beside its name.//// The number is network-wide and comes from Constellation, so it is off the// render path and allowed to be missing: a publication whose count could not// be read looks like a publication without a row, not like one with no posts// (see documentCount in src/lib/subscribers.ts).//// Kept with the publication it describes, so a redraw after the popup has// moved to another tab cannot draw the previous page's number.
import { documentCount } from '../../lib/subscribers'import { $ } from '../dom'import type { Card, CardHost } from './card'
let posts: { uri: string; count: number | null } | undefined/** Publication whose lookup already ran this popup open. */let loadedFor: string | undefined
export const postsCard: Card = { id: 'posts',
async load(host, refresh) { const pub = host.state()?.pub if (!pub) return if (!refresh && loadedFor === pub.uri) return loadedFor = pub.uri const count = await documentCount(pub.uri, pub.handle) posts = { uri: pub.uri, count } host.rerender() },
render(host) { const pub = host.state()?.pub const count = pub && posts?.uri === pub.uri ? posts.count : null const el = $('post-count') // Nothing known, zero posts, or an answer about a different publication: // all three are silence rather than a number the reader has to interpret. // There is no placeholder, since the count appends to the name and its // absence does not move anything. if (count === null || count === undefined || count === 0) { el.hidden = true el.textContent = '' return } el.textContent = count === 1 ? '1 post' : `${count} posts` el.hidden = false },
reset() { posts = undefined loadedFor = undefined },}