diff --git a/src/components/equative-explorer/EquativeExplorer.tsx b/src/components/equative-explorer/EquativeExplorer.tsx index 0ad1914..effb38e 100644 --- a/src/components/equative-explorer/EquativeExplorer.tsx +++ b/src/components/equative-explorer/EquativeExplorer.tsx @@ -1,28 +1,34 @@ -import React, { useState } from "react"; +import { useState } from "react"; import { defaultTextOptions as opts, VerbTable, } from "@lingdocs/pashto-inflector"; import { - makeBlock, - makeOptionLabel, + makeBlockWPronouns, } from "./explorer-helpers"; -import inputs from "./explorer-inputs"; -import { reducer, ExplorerReducerAction } from "./explorer-reducer"; - -export type PredicateType = "adjectives" | "unisexNouns"; -const predicateTypes: PredicateType[] = ["adjectives", "unisexNouns"]; -// type SubjectType = "pronouns" | "nouns"; +import { + reducer, +} from "./explorer-reducer"; +import { + PredicateSelector, +} from "./explorer-selectors"; +import { + ExplorerState, + ExplorerReducerAction, +} from "./explorer-types"; +import { + defaultUnisexNoun, + defaultAdjective, +} from "./explorer-inputs"; // TODO: Plural nouns like shoode -export type ExplorerState = { - predicate: Adjective | UnisexNoun, - predicateType: PredicateType, -}; const defaultState: ExplorerState = { - predicate: inputs.adjectives.find(ps => ps.p === "ستړی") || inputs.adjectives[0], - predicateType: "adjectives", + predicatesSelected: { + adjective: defaultAdjective, + unisexNoun: defaultUnisexNoun, + }, + predicateType: "adjective", }; function EquativeExplorer() { @@ -31,89 +37,17 @@ function EquativeExplorer() { const newState = reducer(state, action); unsafeSetState(newState); } - function handlePredicateSelect(e: React.ChangeEvent) { - dispatch({ type: "setPredicate", payload: parseInt(e.target.value) }); - } - function handlePredicateTypeSelect(e: React.ChangeEvent) { - const payload = e.target.value as PredicateType; - dispatch({ type: "setPredicateType", payload }); - } return <>
- {/*
- -
- - -
-
- - -
-
*/} -
- -
- - -
-
- - -
- -
+
- + ; } diff --git a/src/components/equative-explorer/explorer-helpers.ts b/src/components/equative-explorer/explorer-helpers.ts index 998f97a..abf2808 100644 --- a/src/components/equative-explorer/explorer-helpers.ts +++ b/src/components/equative-explorer/explorer-helpers.ts @@ -14,7 +14,7 @@ export function sort(arr: (Adjective | UnisexNoun)[]): (Adjective | UnisexNoun)[ return arr.sort((a, b) => a.p.localeCompare(b.p)); } -export function makeBlock(e: Adjective | UnisexNoun): T.VerbBlock { +export function makeBlockWPronouns(e: Adjective | UnisexNoun): 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; diff --git a/src/components/equative-explorer/explorer-inputs.ts b/src/components/equative-explorer/explorer-inputs.ts index cd41f05..b3355e1 100644 --- a/src/components/equative-explorer/explorer-inputs.ts +++ b/src/components/equative-explorer/explorer-inputs.ts @@ -7,8 +7,11 @@ import { sort } from "./explorer-helpers"; const unisexNouns = nouns.filter(x => isUnisexNoun(x)) as UnisexNoun[]; const inputs = { - adjectives: sort(adjectives), - unisexNouns: sort(unisexNouns), + adjective: sort(adjectives), + unisexNoun: sort(unisexNouns), }; +export const defaultAdjective = inputs.adjective.find(ps => ps.p === "ستړی") || inputs.adjective[0]; +export const defaultUnisexNoun = inputs.unisexNoun.find(ps => ps.p === "پښتون") || inputs.unisexNoun[0]; + export default inputs; \ No newline at end of file diff --git a/src/components/equative-explorer/explorer-reducer.ts b/src/components/equative-explorer/explorer-reducer.ts index 4539a86..d7f30b0 100644 --- a/src/components/equative-explorer/explorer-reducer.ts +++ b/src/components/equative-explorer/explorer-reducer.ts @@ -1,11 +1,5 @@ import inputs from "./explorer-inputs"; -import { PredicateType, ExplorerState } from "./EquativeExplorer"; - -export type ExplorerReducerAction = { - type: "setPredicateType", payload: PredicateType, -} | { - type: "setPredicate", payload: number, -}; +import { ExplorerState, ExplorerReducerAction } from "./explorer-types"; export function reducer(state: ExplorerState, action: ExplorerReducerAction): ExplorerState { if (action.type === "setPredicate") { @@ -13,13 +7,15 @@ export function reducer(state: ExplorerState, action: ExplorerReducerAction): Ex const predicate = (pile.find(p => p.ts === action.payload) || pile[0]); return { ...state, - predicate, + predicatesSelected: { + ...state.predicatesSelected, + [state.predicateType]: predicate, + }, }; } // if (action.type === "setPredicateType") { - const predicate = inputs[action.payload][0]; return { - predicate, + ...state, predicateType: action.payload, }; // } diff --git a/src/components/equative-explorer/explorer-selectors.tsx b/src/components/equative-explorer/explorer-selectors.tsx new file mode 100644 index 0000000..75bc4ae --- /dev/null +++ b/src/components/equative-explorer/explorer-selectors.tsx @@ -0,0 +1,59 @@ +import { ExplorerState, PredicateType } from "./explorer-types"; +import { makeOptionLabel } from "./explorer-helpers"; +import inputs from "./explorer-inputs"; +import { ExplorerReducerAction } from "./explorer-types"; + +export function PredicateSelector({ state, dispatch }: { + state: ExplorerState, + dispatch: (action: ExplorerReducerAction) => void, +}) { + function onTypeSelect(e: React.ChangeEvent) { + const t = e.target.value as PredicateType; + dispatch({ type: "setPredicateType", payload: t }); + } + function onPredicateSelect(e: React.ChangeEvent) { + const ts = parseInt(e.target.value); + dispatch({ type: "setPredicate", payload: ts }); + } + return
+ +
+ + +
+
+ + +
+ +
; +} \ No newline at end of file diff --git a/src/components/equative-explorer/explorer-types.ts b/src/components/equative-explorer/explorer-types.ts new file mode 100644 index 0000000..58188e5 --- /dev/null +++ b/src/components/equative-explorer/explorer-types.ts @@ -0,0 +1,16 @@ +export type PredicateType = keyof PredicatesSelected; + +export type ExplorerState = { + predicateType: PredicateType, + predicatesSelected: PredicatesSelected, +}; +type PredicatesSelected = { + adjective: Adjective, + unisexNoun: UnisexNoun, +}; + +export type ExplorerReducerAction = { + type: "setPredicateType", payload: PredicateType, +} | { + type: "setPredicate", payload: number, +}; \ No newline at end of file