refactor(ask): reorganize ask flow internals

This commit is contained in:
Erik Kotsiuba
2026-04-17 19:58:58 +02:00
parent c1ac241655
commit 87cbfa546e
25 changed files with 2448 additions and 1639 deletions
+5 -22
View File
@@ -1,29 +1,12 @@
import { CANCELLED_RESULT_TEXT, SUBMITTED_RESULT_TEXT } from "./constants.ts";
import { formatResultLines } from "./result-format.ts";
import type { AskResult } from "./types.ts";
export function renderResultText(result: AskResult): string {
if (result.cancelled) {
return "Cancelled";
return CANCELLED_RESULT_TEXT;
}
const lines: string[] = [];
for (const question of result.questions) {
const answer = result.answers[question.id];
if (!answer) continue;
if (answer.customText) {
lines.push(`✓ ${question.label}: (wrote) ${answer.customText}`);
} else if (answer.labels.length > 0) {
lines.push(`✓ ${question.label}: ${answer.labels.join(", ")}`);
}
if (answer.note) {
lines.push(` note: ${answer.note}`);
}
for (let index = 0; index < answer.values.length; index++) {
const value = answer.values[index];
const label = answer.labels[index] ?? value;
const note = answer.optionNotes?.[value];
if (!note) continue;
lines.push(` ${label} note: ${note}`);
}
}
return lines.join("\n") || "Submitted";
const lines = formatResultLines(result, { mode: "render" });
return lines.join("\n") || SUBMITTED_RESULT_TEXT;
}