You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.7 KiB
118 lines
4.7 KiB
import {isPopulatedArray} from "../../utils/Arrays.js";
|
|
import chalk from "chalk";
|
|
import pluralize from "pluralize";
|
|
import {totalItems} from "../../datatypes/EmpathyGroupList.js";
|
|
import {ExpandQuestion} from "inquirer";
|
|
import {YamlPromptFunction} from "../../schemata/YAMLPrompt.js";
|
|
import {InquireFunction, Separator} from "../Inquire.js";
|
|
import {EmpathyGroupListPromptOptions} from "./EmpathyGroupListPrompt.js";
|
|
import {EmpathyGroup} from "../../datatypes/EmpathyGroup.js";
|
|
import {EmpathyGuide, EmpathyGuideJTD} from "../../datatypes/EmpathyGuide.js";
|
|
|
|
export interface EmpathyGuidePromptOptions {
|
|
readonly default?: EmpathyGuide
|
|
}
|
|
|
|
export interface EmpathyGuidePromptDependencies {
|
|
readonly inquire: InquireFunction<ExpandQuestion, typeof PLEASANT | typeof UNPLEASANT | typeof NEEDS | typeof INSPECT | typeof SAVE>
|
|
readonly promptForEmpathyGroupList: (opts: EmpathyGroupListPromptOptions) => Promise<readonly EmpathyGroup[]>
|
|
readonly promptYaml: YamlPromptFunction
|
|
}
|
|
|
|
export function empathyGuidePrompt(deps: EmpathyGuidePromptDependencies): (opts: EmpathyGuidePromptOptions) => Promise<EmpathyGuide> {
|
|
return (opts) => promptForEmpathyGuide(opts, deps)
|
|
}
|
|
|
|
const PLEASANT = "Pleasant"
|
|
const UNPLEASANT = "Unpleasant"
|
|
const NEEDS = "Needs"
|
|
const INSPECT = "Inspect"
|
|
const SAVE = "Save"
|
|
|
|
export async function promptForEmpathyGuide(opts: EmpathyGuidePromptOptions, deps: EmpathyGuidePromptDependencies): Promise<EmpathyGuide> {
|
|
const {default: value} = opts
|
|
const {inquire, promptForEmpathyGroupList, promptYaml} = deps
|
|
const result = await inquire({
|
|
type: "expand",
|
|
message: "What would you like to modify?",
|
|
pageSize: 999,
|
|
choices: [
|
|
{
|
|
key: "p",
|
|
name: `Pleasant (met needs) feelings${isPopulatedArray(value?.feelings?.pleasant) ? chalk.dim(` (currently ${pluralize("group", value?.feelings?.pleasant?.length || 0, true)} totaling ${pluralize("item", totalItems(value?.feelings?.pleasant || []), true)})`) : ""}`,
|
|
value: PLEASANT,
|
|
},
|
|
{
|
|
key: "u",
|
|
name: `Unpleasant (unmet needs) feelings${isPopulatedArray(value?.feelings?.unpleasant) ? chalk.dim(` (currently ${pluralize("group", value?.feelings?.unpleasant?.length || 0, true)} totaling ${pluralize("item", totalItems(value?.feelings?.unpleasant || []), true)})`) : ""}`,
|
|
value: UNPLEASANT,
|
|
},
|
|
{
|
|
key: "n",
|
|
name: `Needs${isPopulatedArray(value?.needs) ? chalk.dim(` (currently ${pluralize("group", value?.needs?.length || 0, true)} totaling ${pluralize("item", totalItems(value?.needs || []), true)})`) : ""}`,
|
|
value: NEEDS,
|
|
},
|
|
new Separator(),
|
|
{
|
|
key: "i",
|
|
name: "Inspect and modify the current empathy guide in the editor",
|
|
value: INSPECT,
|
|
},
|
|
{
|
|
key: "s",
|
|
name: "Save the empathy guide",
|
|
value: SAVE
|
|
},
|
|
new Separator(),
|
|
]
|
|
})
|
|
switch (result) {
|
|
case PLEASANT:
|
|
const newPleasant = await promptForEmpathyGroupList({
|
|
default: value?.feelings?.pleasant,
|
|
listName: "pleasant (met needs) feelings"
|
|
})
|
|
return promptForEmpathyGuide({
|
|
default: {
|
|
...value,
|
|
feelings: {
|
|
...value?.feelings || {},
|
|
pleasant: newPleasant,
|
|
}
|
|
}
|
|
}, deps)
|
|
case UNPLEASANT:
|
|
const newUnpleasant = await promptForEmpathyGroupList({
|
|
default: value?.feelings?.unpleasant,
|
|
listName: "unpleasant (unmet needs) feelings"
|
|
})
|
|
return promptForEmpathyGuide({
|
|
default: {
|
|
...value,
|
|
feelings: {
|
|
...value?.feelings || {},
|
|
unpleasant: newUnpleasant,
|
|
}
|
|
}
|
|
}, deps)
|
|
case NEEDS:
|
|
const newNeeds = await promptForEmpathyGroupList({default: value?.needs, listName: "needs"})
|
|
return promptForEmpathyGuide({
|
|
default: {
|
|
...value,
|
|
needs: newNeeds
|
|
}
|
|
}, deps)
|
|
case SAVE:
|
|
return value || {}
|
|
default:
|
|
case INSPECT:
|
|
return promptForEmpathyGuide({
|
|
default: await promptYaml({
|
|
schema: EmpathyGuideJTD,
|
|
currentValue: value,
|
|
name: "the current empathy guide",
|
|
})
|
|
}, deps)
|
|
}
|
|
} |