(props: {
request: QuestionRequest
theme: RunFooterTheme
onReply: (input: QuestionReply) => void | Promise<void>
onReject: (input: QuestionReject) => void | Promise<void>
})
| 45 | import type { QuestionReject, QuestionReply } from "./types" |
| 46 | |
| 47 | export function RunQuestionBody(props: { |
| 48 | request: QuestionRequest |
| 49 | theme: RunFooterTheme |
| 50 | onReply: (input: QuestionReply) => void | Promise<void> |
| 51 | onReject: (input: QuestionReject) => void | Promise<void> |
| 52 | }) { |
| 53 | const dims = useTerminalDimensions() |
| 54 | const [state, setState] = createSignal(createQuestionBodyState(props.request.id)) |
| 55 | const single = createMemo(() => questionSingle(props.request)) |
| 56 | const confirm = createMemo(() => questionConfirm(props.request, state())) |
| 57 | const info = createMemo(() => questionInfo(props.request, state())) |
| 58 | const input = createMemo(() => questionInput(state())) |
| 59 | const other = createMemo(() => questionOther(props.request, state())) |
| 60 | const picked = createMemo(() => questionPicked(state())) |
| 61 | const disabled = createMemo(() => state().submitting) |
| 62 | const narrow = createMemo(() => footerWidthPolicy(dims().width).dialog.narrow) |
| 63 | const verb = createMemo(() => { |
| 64 | if (confirm()) { |
| 65 | return "submit" |
| 66 | } |
| 67 | |
| 68 | if (info()?.multiple) { |
| 69 | return "toggle" |
| 70 | } |
| 71 | |
| 72 | if (single()) { |
| 73 | return "submit" |
| 74 | } |
| 75 | |
| 76 | return "confirm" |
| 77 | }) |
| 78 | let area: TextareaRenderable | undefined |
| 79 | |
| 80 | createEffect(() => { |
| 81 | setState((prev) => questionSync(prev, props.request.id)) |
| 82 | }) |
| 83 | |
| 84 | const setTab = (tab: number) => { |
| 85 | setState((prev) => questionSetTab(prev, tab)) |
| 86 | } |
| 87 | |
| 88 | const move = (dir: -1 | 1) => { |
| 89 | setState((prev) => questionMove(prev, props.request, dir)) |
| 90 | } |
| 91 | |
| 92 | const beginReply = async (input: QuestionReply) => { |
| 93 | setState((prev) => questionSetSubmitting(prev, true)) |
| 94 | |
| 95 | try { |
| 96 | await props.onReply(input) |
| 97 | } catch { |
| 98 | setState((prev) => questionSetSubmitting(prev, false)) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | const beginReject = async (input: QuestionReject) => { |
| 103 | setState((prev) => questionSetSubmitting(prev, true)) |
| 104 |
nothing calls this directly
no test coverage detected