Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940import { del, get, keys, set } from 'idb-keyval'
export interface Draft { id: string title: string markdown: string sourceUri: string topics?: string[] createdAt: string}
/** Drafts belong to the account that saved them. */function prefix(owner: string): string { return `threadbare:draft:${owner}/`}
export async function listDrafts(owner: string): Promise<Draft[]> { const stored = await keys() const own = prefix(owner) const drafts: Draft[] = [] for (const key of stored) { if (typeof key !== 'string' || !key.startsWith(own)) continue const draft = await get<Draft>(key) if (draft) drafts.push(draft) } return drafts.sort((left, right) => right.createdAt.localeCompare(left.createdAt))}
export async function loadDraft(owner: string, id: string): Promise<Draft | undefined> { return get<Draft>(prefix(owner) + id)}
export async function saveDraft(owner: string, draft: Draft): Promise<void> { await set(prefix(owner) + draft.id, draft)}
export async function deleteDraft(owner: string, id: string): Promise<void> { await del(prefix(owner) + id)}