From d88168dbf08d6e8060846f3a5ac86759bc096e8e Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Mon, 5 Jul 2021 19:02:25 +0300 Subject: [PATCH] conjugation viewer api change, just pass the entry (and complement) in and the conjugation will be handled by the ConjugationViewer or return null if there is none/error --- package.json | 2 +- src/App.tsx | 20 +++-------- src/components/ConjugationViewer.tsx | 35 ++++++++++++++------ {verbs => src/verbs}/dyn-comp-trans.js | 0 {verbs => src/verbs}/simple-gramm-trans.js | 0 {verbs => src/verbs}/simple-intrans.js | 0 {verbs => src/verbs}/simple-trans.js | 0 {verbs => src/verbs}/stative-comp-intrans.js | 0 {verbs => src/verbs}/stative-comp-trans.js | 0 9 files changed, 29 insertions(+), 28 deletions(-) rename {verbs => src/verbs}/dyn-comp-trans.js (100%) rename {verbs => src/verbs}/simple-gramm-trans.js (100%) rename {verbs => src/verbs}/simple-intrans.js (100%) rename {verbs => src/verbs}/simple-trans.js (100%) rename {verbs => src/verbs}/stative-comp-intrans.js (100%) rename {verbs => src/verbs}/stative-comp-trans.js (100%) diff --git a/package.json b/package.json index 58dbc33..7cf60f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "0.5.8", + "version": "0.6.0", "author": "lingdocs.com", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "homepage": "https://verbs.lingdocs.com", diff --git a/src/App.tsx b/src/App.tsx index 6501b64..375e0ab 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,7 +12,6 @@ import verbs from "./verbs"; import Pashto from "./components/Pashto"; import Phonetics from "./components/Phonetics"; import InlinePs from "./components/InlinePs"; -import { conjugateVerb } from "./lib/verb-conjugation"; import { getVerbInfo } from "./lib/verb-info"; import ButtonSelect from "./components/ButtonSelect"; import { @@ -177,16 +176,6 @@ function App() { const makeVerbLabel = (entry: T.DictionaryEntry): string => ( `${entry.p} - ${clamp(entry.e, 20)}` ); - - const conjugation = v - ? conjugateVerb(v.verb.entry, aayTailType, v.verb.complement) - : undefined; - // if (v) { - // console.log("Verb chosen:"); - // console.log(v.verb); - // console.log("Conjugation of verb:") - // console.log(conjugation); - // } return <>
@@ -216,7 +205,7 @@ function App() {
- {(v && conjugation) ? + {v ?
Select a verb:
@@ -308,11 +297,10 @@ function App() {
- {conjugation && }
diff --git a/src/components/ConjugationViewer.tsx b/src/components/ConjugationViewer.tsx index 0b7167c..8864fd8 100644 --- a/src/components/ConjugationViewer.tsx +++ b/src/components/ConjugationViewer.tsx @@ -12,6 +12,7 @@ import VerbFormDisplay from "./VerbFormDisplay"; import ButtonSelect from "./ButtonSelect"; import Hider from "./Hider"; import { getForms } from "../lib/conjugation-forms"; +import { conjugateVerb } from "../lib/verb-conjugation"; import PersonSelection from "./PersonSelection"; import { personIsAllowed, @@ -171,11 +172,11 @@ const initialState: State = { formsOpened: [], }; -function ConjugationViewer({ conjugation, textOptions, ec, ep }: { - conjugation: T.VerbOutput, +function ConjugationViewer({ entry, complement, textOptions, aayTailType }: { + entry: T.DictionaryEntry, + complement?: T.DictionaryEntry, textOptions: T.TextOptions, - ec?: string | undefined, - ep?: string | undefined, + aayTailType?: T.AayTail, }) { const [state, dispatch] = useReducer(reducer, initialState); useEffect(() => { @@ -189,6 +190,22 @@ function ConjugationViewer({ conjugation, textOptions, ec, ep }: { } } }, []); + useEffect(() => { + localStorage.setItem(stateLocalStorageName, JSON.stringify(state)); + }); + + const conjugation = (() => { + try { + return conjugateVerb(entry, aayTailType ? aayTailType : "aay", complement); + } catch(e) { + return undefined; + } + })(); + if (conjugation === undefined) { + // don't show the conjugation viewer if the verb can't be conjugated + return null; + } + const verbConj1 = ("dynamic" in conjugation) ? conjugation[state.compoundTypeSelected] : ("transitive" in conjugation) @@ -197,15 +214,11 @@ function ConjugationViewer({ conjugation, textOptions, ec, ep }: { const verbConj = (verbConj1.singularForm && state.compoundComplementVersionSelected === "sing") ? verbConj1.singularForm : verbConj1; - const englishConjugation: T.EnglishVerbConjugation | undefined = ec ? { - ec: parseEc(ec), - ep: ep, + const englishConjugation: T.EnglishVerbConjugation | undefined = entry.ec ? { + ec: parseEc(entry.ec), + ep: entry.ep, } : undefined; - useEffect(() => { - localStorage.setItem(stateLocalStorageName, JSON.stringify(state)); - }); - const filterDifficulty = (f: T.DisplayForm): boolean => ( state.difficulty === "advanced" || !f.advanced ); diff --git a/verbs/dyn-comp-trans.js b/src/verbs/dyn-comp-trans.js similarity index 100% rename from verbs/dyn-comp-trans.js rename to src/verbs/dyn-comp-trans.js diff --git a/verbs/simple-gramm-trans.js b/src/verbs/simple-gramm-trans.js similarity index 100% rename from verbs/simple-gramm-trans.js rename to src/verbs/simple-gramm-trans.js diff --git a/verbs/simple-intrans.js b/src/verbs/simple-intrans.js similarity index 100% rename from verbs/simple-intrans.js rename to src/verbs/simple-intrans.js diff --git a/verbs/simple-trans.js b/src/verbs/simple-trans.js similarity index 100% rename from verbs/simple-trans.js rename to src/verbs/simple-trans.js diff --git a/verbs/stative-comp-intrans.js b/src/verbs/stative-comp-intrans.js similarity index 100% rename from verbs/stative-comp-intrans.js rename to src/verbs/stative-comp-intrans.js diff --git a/verbs/stative-comp-trans.js b/src/verbs/stative-comp-trans.js similarity index 100% rename from verbs/stative-comp-trans.js rename to src/verbs/stative-comp-trans.js