import m from '@garage44/mithril' import {Button} from '@garage44/mithril/components' import {adminOpenRow, adminRequestRow} from '@/components/admin' import {openDecision} from '@/components/decisions' import {icon} from '@/components/icons' import {age, now, span} from '@/lib/format' import {needs} from '@/lib/needs' import type {Need} from '@/lib/needs' import {$s} from '@/lib/store' import {go} from '@/lib/route' import {hosted} from '@/lib/stream' /** Everything that waits for the person now: the tab's title and the nav count this. */ export const waitingForYou = (): Need[] => needs($s.decisions, hosted(), now(), $s.admin?.requests ?? []) const open = (id: string) => go(`sessions/${id}`) function row(n: Need): m.Children { if (n.kind === 'admin') return adminRequestRow(n.request) if (n.kind === 'decision') return openDecision(n.decision) const s = n.session if (n.kind === 'awaits') return (
{icon.key()} {s.awaits?.text} ยท {s.title}, since {age(s.awaits?.at)}
) return (
{n.kind === 'permission' ? ( <> {s.title} waits for your answer ) : ( <> {s.title} has been starting for {span(n.for_s)}: it may be stuck )}
) } /** * The top of the board: questions to answer (here, inline), permissions a * session waits for, and sessions that never got going. Nothing when nothing waits. */ export function NeedsYou(): m.Children { const list = waitingForYou() // Root open on the hub's machine is shown while it lasts, though it asks nothing of them. const open = adminOpenRow() if (!list.length && !open) return null return (
Needs you {list.length}
{open} {list.map(row)}
) }