Spaces:
Sleeping
Sleeping
| export interface DeckMeta { | |
| id: string | |
| title: string | |
| createdAt: number | |
| } | |
| export async function listMyDecks(): Promise<DeckMeta[]> { | |
| const r = await fetch('/api/decks/mine') | |
| if (!r.ok) return [] | |
| const j = (await r.json()) as { decks?: DeckMeta[] } | |
| return j.decks ?? [] | |
| } | |
| export async function createDeck(title: string): Promise<DeckMeta> { | |
| const r = await fetch('/api/decks', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ title }), | |
| }) | |
| if (!r.ok) { | |
| let msg = 'Could not create presentation' | |
| try { | |
| msg = (await r.json()).error || msg | |
| } catch { | |
| /* ignore */ | |
| } | |
| throw new Error(msg) | |
| } | |
| return (await r.json()) as DeckMeta | |
| } | |
| /** Deck id from the URL (/d/<id>), or null for the home page. */ | |
| export function currentDeckId(): string | null { | |
| const m = location.pathname.match(/^\/d\/([A-Za-z0-9_-]+)$/) | |
| return m ? m[1] : null | |
| } | |