/** * — lists choice shapes (polls, rankings, spider charts) * from the current space and links to the canvas to create/interact with them. */ class FolkChoicesDashboard extends HTMLElement { private shadow: ShadowRoot; private choices: any[] = []; private loading = true; private space: string; constructor() { super(); this.shadow = this.attachShadow({ mode: "open" }); this.space = this.getAttribute("space") || "demo"; } connectedCallback() { this.render(); this.loadChoices(); } private getApiBase(): string { const path = window.location.pathname; const parts = path.split("/").filter(Boolean); return parts.length >= 2 ? `/${parts[0]}/choices` : "/demo/choices"; } private async loadChoices() { this.loading = true; this.render(); try { const res = await fetch(`${this.getApiBase()}/api/choices`); const data = await res.json(); this.choices = data.choices || []; } catch (e) { console.error("Failed to load choices:", e); } this.loading = false; this.render(); } private render() { const typeIcons: Record = { "folk-choice-vote": "\u2611", "folk-choice-rank": "\uD83D\uDCCA", "folk-choice-spider": "\uD83D\uDD78", }; const typeLabels: Record = { "folk-choice-vote": "Poll", "folk-choice-rank": "Ranking", "folk-choice-spider": "Spider Chart", }; this.shadow.innerHTML = `

\u2611 Choices

Choice tools (Polls, Rankings, Spider Charts) live on the collaborative canvas. Create them there and they'll appear here for quick access.
${this.loading ? `
\u23F3 Loading choices...
` : this.choices.length === 0 ? this.renderEmpty() : this.renderGrid(typeIcons, typeLabels)} `; } private renderEmpty(): string { return `
\u2611

No choices in this space yet.

Open the canvas and use the Poll, Rank, or Spider buttons to create one.

`; } private renderGrid(icons: Record, labels: Record): string { return ``; } private esc(s: string): string { const d = document.createElement("div"); d.textContent = s; return d.innerHTML; } } customElements.define("folk-choices-dashboard", FolkChoicesDashboard);