diff --git a/src/components/equative-explorer/EquativeDisplay.tsx b/src/components/equative-explorer/EquativeDisplay.tsx index 8608ed2..0938b02 100644 --- a/src/components/equative-explorer/EquativeDisplay.tsx +++ b/src/components/equative-explorer/EquativeDisplay.tsx @@ -1,9 +1,12 @@ import { VerbTable, defaultTextOptions as opts, + ButtonSelect, + Types as T, } from "@lingdocs/pashto-inflector"; import { ExplorerState, + ExplorerReducerAction, } from "./explorer-types"; import { makeBlockWPronouns, @@ -15,12 +18,13 @@ import { } from "../../lib/equative-machine"; import { isNoun, isPluralEntry, isUnisexNoun } from "../../lib/type-predicates"; -function EquativeDisplay({ state }: { state: ExplorerState }) { +export function chooseLength(o: T.SingleOrLengthOpts, length: "short" | "long"): O { + return ("long" in o) ? o[length] : o; +} + +function SingleItemDisplay({ state }: { state: ExplorerState }) { if (state.subjectType === "pronouns") { - return + return
ERROR: Wrong display being used
; } const entry = state.subjectsSelected[state.subjectType]; // @ts-ignore - TODO: safer and for use with unisex nouns @@ -32,13 +36,40 @@ function EquativeDisplay({ state }: { state: ExplorerState }) { } : {}, } : entry; - const eq = assembleEquativeOutput( - equativeMachine(subjInput, state.predicatesSelected[state.predicateType]) + const block = assembleEquativeOutput( + equativeMachine(subjInput, state.predicatesSelected[state.predicateType], state.tense) ); - if ("short" in eq) return
length options not supported yet
; return
- +
; } -export default EquativeDisplay; \ No newline at end of file +function PronounBlockDisplay({ state }: { state: ExplorerState }) { + const block = makeBlockWPronouns(state.predicatesSelected[state.predicateType], state.tense); + return ; +} + +function EquativeDisplay({ state, dispatch }: { state: ExplorerState, dispatch: (action: ExplorerReducerAction) => void }) { + return <> + {state.tense === "past" &&
+ dispatch({ type: "setLength", payload: p as "long" | "short" })} + /> +
} + {state.subjectType === "pronouns" + ? + : + } + ; +} + +export default EquativeDisplay; diff --git a/src/components/equative-explorer/EquativeExplorer.tsx b/src/components/equative-explorer/EquativeExplorer.tsx index 708fb94..5350bbe 100644 --- a/src/components/equative-explorer/EquativeExplorer.tsx +++ b/src/components/equative-explorer/EquativeExplorer.tsx @@ -5,6 +5,7 @@ import { import { PredicateSelector, SubjectSelector, + TenseSelector, } from "./explorer-selectors"; import { ExplorerState, @@ -18,9 +19,9 @@ import { } from "./explorer-inputs"; import EquativeDisplay from "./EquativeDisplay"; -// TODO: Plural nouns like shoode - const defaultState: ExplorerState = { + tense: "present", + length: "short", predicatesSelected: { adjective: defaultAdjective, unisexNoun: defaultUnisexNoun, @@ -45,11 +46,12 @@ function EquativeExplorer() { unsafeSetState(newState); } return <> -
+ +
- + ; } diff --git a/src/components/equative-explorer/explorer-helpers.ts b/src/components/equative-explorer/explorer-helpers.ts index efd7dfc..41f11e5 100644 --- a/src/components/equative-explorer/explorer-helpers.ts +++ b/src/components/equative-explorer/explorer-helpers.ts @@ -9,16 +9,27 @@ import { ParticipleInput, isParticipleInput, getEnglishParticiple, + TenseInput, } from "../../lib/equative-machine"; export function sort(arr: Readonly): T[] { return [...arr].sort((a, b) => a.p.localeCompare(b.p)); } -export function makeBlockWPronouns(e: Adjective | UnisexNoun): T.VerbBlock { +export function makeBlockWPronouns(e: Adjective | UnisexNoun, tense: TenseInput, length?: "short" | "long"): T.SingleOrLengthOpts { + if (tense === "past" && !length) { + return { + short: makeBlockWPronouns(e, tense, "short") as T.VerbBlock, + long: makeBlockWPronouns(e, tense, "long") as T.VerbBlock, + }; + } const makeP = (p: T.Person): T.ArrayOneOrMore => { - const b = assembleEquativeOutput(equativeMachine(p, e)); - return ("long" in b ? b.long : b) as T.ArrayOneOrMore; + const b = assembleEquativeOutput(equativeMachine(p, e, tense)); + if ("long" in b) { + if (!length) throw new Error("bad length processing"); + return b[length]; + } + return b; }; return [ [makeP(0), makeP(6)], diff --git a/src/components/equative-explorer/explorer-reducer.ts b/src/components/equative-explorer/explorer-reducer.ts index e248d2c..8980c2b 100644 --- a/src/components/equative-explorer/explorer-reducer.ts +++ b/src/components/equative-explorer/explorer-reducer.ts @@ -53,14 +53,26 @@ export function reducer(state: ExplorerState, action: ExplorerReducerAction): Ex }, }; } + if (action.type === "setSubjectGender") { + return { + ...state, + subjectsSelected: { + ...state.subjectsSelected, + info: { + ...state.subjectsSelected.info, + gender: action.payload, + }, + }, + }; + } + if (action.type === "setTense") { + return { + ...state, + tense: action.payload, + }; + } return { ...state, - subjectsSelected: { - ...state.subjectsSelected, - info: { - ...state.subjectsSelected.info, - gender: action.payload, - }, - }, + length: action.payload, }; } \ No newline at end of file diff --git a/src/components/equative-explorer/explorer-selectors.tsx b/src/components/equative-explorer/explorer-selectors.tsx index 6af6cfd..c64898c 100644 --- a/src/components/equative-explorer/explorer-selectors.tsx +++ b/src/components/equative-explorer/explorer-selectors.tsx @@ -204,3 +204,27 @@ export function PredicateSelector({ state, dispatch }: {
; } +export function TenseSelector({ state, dispatch }: { + state: ExplorerState, + dispatch: (action: ExplorerReducerAction) => void, +}) { + const options = [ + { value: "present", label: "Present" }, + { value: "past", label: "Past" }, + ]; + function onTenseSelect({ value }: any) { + dispatch({ type: "setTense", payload: value }); + } + return
+
Tense:
+