/** * Copyright (c) 2021 lingdocs.com * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import { useEffect } from "react"; import verbs from "./verbs"; import nounsAdjs from "./nouns-adjs"; import Pashto from "./components/Pashto"; import Phonetics from "./components/Phonetics"; import { getVerbInfo } from "./lib/verb-info"; import ButtonSelect from "./components/ButtonSelect"; import { clamp } from "./lib/p-text-helpers"; import { randomNumber, } from "./lib/misc-helpers"; import { Modal } from "react-bootstrap"; import * as T from "./types"; import { isNounEntry } from "./lib/type-predicates"; import defualtTextOptions from "./lib/default-text-options"; import PhraseBuilder from "./components/vp-explorer/VPExplorer"; import { useStickyState } from "./library"; type VerbType = "simple" | "stative compound" | "dynamic compound"; const verbTypes: VerbType[] = [ "simple", "stative compound", "dynamic compound", ]; const nouns = nounsAdjs.filter(isNounEntry); const transitivities: T.Transitivity[] = [ "transitive", "intransitive", "grammatically transitive", ]; const allVerbs = verbs.map((v: { entry: T.DictionaryEntry, complement?: T.DictionaryEntry }) => ({ verb: v, info: getVerbInfo(v.entry, v.complement), })); function App() { const [verbTs, setVerbTs] = useStickyState(0, "verbTs1"); const [verbTypeShowing, setVerbTypeShowing] = useStickyState("simple", "vTypeShowing"); const [regularIrregular, setRegularIrregular] = useStickyState<"regular" | "irregular">("regular", "regIrreg"); const [transitivityShowing, setTransitivityShowing] = useStickyState("intransitive", "transitivityShowing1"); const [showingTextOptions, setShowingTextOptions] = useStickyState(false, "showTextOpts1"); const [textOptions, setTextOptions] = useStickyState(defualtTextOptions, "textOpts1"); const [theme, setTheme] = useStickyState<"light" | "dark">("light", "theme1"); // const onlyGrammTrans = (arr: Transitivity[]) => ( // arr.length === 1 && arr[0] === "grammatically transitive" // ); // const ensureSimpleVerbTypeSelected = () => { // if (!verbTypesShowing.includes["simple"]) { // setVerbTypesShowing([...verbTypesShowing, "simple"]); // } // } useEffect(() => { document.documentElement.setAttribute("data-theme", theme); }, [theme]) const handleVerbIndexChange = (e: any) => { console.log("changing to", e.target.value); setVerbTs(parseInt(e.target.value)); } const handleTypeSelection = (e: any) => { const type = e.target.value as VerbType; if (type === "dynamic compound") { setTransitivityShowing("transitive"); } if (type === "stative compound" && transitivityShowing === "grammatically transitive") { setTransitivityShowing("transitive"); } setVerbTypeShowing(type); } const handleTransitivitySelection = (e: any) => { const transitivity = e.target.value as T.Transitivity; if (transitivity === "grammatically transitive") { setVerbTypeShowing("simple"); } if (transitivity === "intransitive" && verbTypeShowing === "dynamic compound") { setTransitivityShowing("transitive"); return; } setTransitivityShowing(e.target.value as T.Transitivity); } const isRegularVerb = (entry: T.DictionaryEntry): boolean => ( !entry.l && !entry.psp && !entry.ssp && !entry.prp && !entry.pprtp && !entry.noOo && !entry.sepOo ); const verbsAvailable = allVerbs.filter((verb) => ( ( (verb.info.type === "transitive or grammatically transitive simple" && verbTypeShowing === "simple") && (transitivityShowing === "transitive" || transitivityShowing === "grammatically transitive") ) || (( verbTypeShowing === verb.info.type || (verbTypeShowing === "stative compound" && verb.info.type === "dynamic or stative compound") || (verbTypeShowing === "dynamic compound" && verb.info.type === "dynamic or stative compound") || (verbTypeShowing === "dynamic compound" && verb.info.type === "dynamic or generative stative compound") || (verbTypeShowing === "stative compound" && verb.info.type === "dynamic or generative stative compound") ) && ( transitivityShowing === verb.info.transitivity )) )).filter((verb) => { if (verbTypeShowing !== "simple") { return true; } return regularIrregular === "regular" ? isRegularVerb(verb.verb.entry) : !isRegularVerb(verb.verb.entry); }).sort((a, b) => a.verb.entry.p.localeCompare(b.verb.entry.p, "ps")); const v = (() => { const vFound = verbsAvailable.find(v => v.verb.entry.ts === verbTs); if (vFound) return vFound; if (verbsAvailable.length === 0) return undefined; const vTopOfList = verbsAvailable[0]; setVerbTs(vTopOfList.verb.entry.ts); return vTopOfList; })(); const pickRandomVerb = () => { let newIndex: number; do { newIndex = randomNumber(0, verbsAvailable.length); } while(verbsAvailable[newIndex].verb.entry.ts === verbTs); setVerbTs(verbsAvailable[newIndex].verb.entry.ts); }; const makeVerbLabel = (entry: T.DictionaryEntry): string => ( `${entry.p} - ${clamp(entry.e, 20)}` ); return <>
setShowingTextOptions(true)} >
setTheme(theme === "light" ? "dark" : "light")} >

Pashto Verb Explorer

by LingDocs

Each form is made from one simple formula which works for all verbs. 👨‍🔬

Choose a verb 👇, look at its roots and stems 🌳, see how all the forms are made. 🤓

{v ?
Select a verb:
{v.verb.entry} {` `}-{` `} {v.verb.entry} {` `} {v.verb.entry.c}
{v.verb.entry.e}
:
No such verbs available...
}
Verb type:
{verbTypes.map((type) => (
))}
{verbTypeShowing === "simple" &&
}
Transitivity:
{transitivities.map((transitivity) => (
))}
{v?.verb.entry &&
}
setShowingTextOptions(false)}> Settings
Pashto Spelling
{ setTextOptions({ ...textOptions, spelling: p, }); }} />
Diacritics
setTextOptions({ ...textOptions, diacritics: p === "true" })} />
Pashto Text Size
setTextOptions({ ...textOptions, pTextSize: p })} />
Phonetics
setTextOptions({ ...textOptions, phonetics: p })} />
} export default App;