import m, {MithrilComponent} from '@garage44/mithril' import {Badge, FieldText} from '@garage44/mithril/components' import {confirmButton} from '@/components/confirm' import {who} from '@/components/who' import {act} from '@/lib/actions' import {api} from '@/lib/api' import {age, when} from '@/lib/format' import {sessions} from '@/lib/markdown' import {speaker} from '@/lib/names' import {bind, local} from '@/lib/reactive' import {$s} from '@/lib/store' import type {Decision} from '@/lib/types' /** What is being written to each open question, kept while the page redraws. */ const words = local({notes: {} as Record, free: {} as Record}) function decide(d: Decision, choice: string) { const note = (words.notes[d.id] ?? '').trim() || undefined void act(`${d.id}: ${choice}`, () => api.decide(d.id, choice, note)) } /** The element a question is drawn in, for a card's "?" to scroll to. */ export const decisionAnchor = (id: string) => `decision-${id}` /** * One question a session put to the person (`midas ask`): a button per option, * each asking for a second tap, or a box for a free answer. The answer goes to * the asking session, and to those it named, as a note. */ export function openDecision(d: Decision): m.Children { return (
{d.id} {sessions(d.question)}
asked by {who(d.by, {max: 40})} · {age(d.at)} ago {d.with.length ? [' · concerns ', d.with.map((w, i) => [i ? ', ' : '', who(w, {max: 30})])] : ''}
{d.options.length ? [ d.options.map((o) => confirmButton(`decide-${d.id}-${o}`, { label: o, armedLabel: `Tap again: “${o}”`, variant: 'secondary', disabled: !$s.hasKey, run: () => decide(d, o), }), ), , ] : [ , confirmButton(`decide-${d.id}`, { label: 'Answer', armedLabel: 'Tap again to send', variant: 'secondary', disabled: !$s.hasKey || !(words.free[d.id] ?? '').trim(), run: () => decide(d, words.free[d.id].trim()), }), ]}
) } /** * The questions already answered, beside the board: folded under "show N * decided", newest first. The open ones are at the top of the board. */ export class Decided extends MithrilComponent { s = local({open: false}) view() { const done = $s.decisions.filter((d) => d.answer != null).sort((a, b) => (b.answered_at ?? 0) - (a.answered_at ?? 0)) if (!done.length) return null return (

Decided

{this.s.open ? (
    {done.map((d) => (
  • ✓ {sessions(d.question)} — {d.answer}
    {d.id} · {speaker(d.answered_by ?? '').title} · {when(d.answered_at)} {d.note ? ` — ${d.note}` : ''}
  • ))}
) : null}
) } }