/** * 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, useState } from "react"; import ConjugationViewer from "./components/ConjugationViewer"; import verbs from "./verbs"; import Pashto from "./components/Pashto"; import Phonetics from "./components/Phonetics"; import { conjugateVerb } from "./lib/verb-conjugation"; 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 defualtTextOptions from "./lib/default-text-options"; import InlinePs from "./components/InlinePs"; type VerbType = "simple" | "stative compound" | "dynamic compound"; const verbTypes: VerbType[] = [ "simple", "stative compound", "dynamic compound", ]; const transitivities: T.Transitivity[] = [ "transitive", "intransitive", "grammatically transitive", ]; const allVerbs = verbs.map((v: any) => ({ verb: v, info: getVerbInfo(v.entry, v.complement), })); function App() { const [verbTs, setVerbTs] = useState(0); const [verbTypeShowing, setVerbTypeShowing] = useState("simple"); const [regularIrregular, setRegularIrregular] = useState<"regular" | "irregular">("regular"); const [transitivityShowing, setTransitivityShowing] = useState("intransitive"); const [showingTextOptions, setShowingTextOptions] = useState(false); const [textOptions, setTextOptions] = useState(defualtTextOptions); const [aayTailType, setAayTailType] = useState("aay"); const [theme, setTheme] = useState<"light" | "dark">("light"); // const onlyGrammTrans = (arr: Transitivity[]) => ( // arr.length === 1 && arr[0] === "grammatically transitive" // ); // const ensureSimpleVerbTypeSelected = () => { // if (!verbTypesShowing.includes["simple"]) { // setVerbTypesShowing([...verbTypesShowing, "simple"]); // } // } useEffect(() => { const verbTsRaw = localStorage.getItem("verbTs"); const verbTypeShowing = localStorage.getItem("verbTypeShowing") as undefined | VerbType; const regularIrregular = localStorage.getItem("regularIrregular") as "regular" | "irregular"; const transitivitiyShowing = localStorage.getItem("transitivityShowing") as undefined | T.Transitivity; const theme = localStorage.getItem("theme"); const textOptionst = localStorage.getItem("textOptions"); const aayTailType = localStorage.getItem("aayType"); if (regularIrregular) { setRegularIrregular(regularIrregular); } if (verbTsRaw) { setVerbTs(JSON.parse(verbTsRaw)); } if (verbTypeShowing) { setVerbTypeShowing(verbTypeShowing); } if (transitivitiyShowing) { setTransitivityShowing(transitivitiyShowing); } if (theme) { setTheme(theme as "light" | "dark"); } if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { setTheme("dark"); } if (textOptionst) { setTextOptions(JSON.parse(textOptionst) as T.TextOptions); } if (aayTailType) { setAayTailType(aayTailType as T.AayTail); } }, []); useEffect(() => { localStorage.setItem("verbTs", verbTs.toString()); localStorage.setItem("regularIrregular", regularIrregular); localStorage.setItem("verbTypeShowing", verbTypeShowing); localStorage.setItem("transitivityShowing", transitivityShowing); localStorage.setItem("textOptions", JSON.stringify(textOptions)); localStorage.setItem("theme", theme); localStorage.setItem("aayType", aayTailType); }); 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"); } 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)}` ); 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); } console.log(verbTypeShowing); console.log(textOptions); 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 and what they mean. 🤓

{(v && conjugation) ?
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" &&
{ setRegularIrregular(p as "regular" | "irregular"); }} />
}
Transitivity:
{transitivities.map((transitivity) => (
))}
{conjugation && }
setShowingTextOptions(false)}> Settings
Pashto Spelling
{ setTextOptions({ ...textOptions, spelling: p as "Afghan" | "Pakistani", }); if (p === "Pakistani") setAayTailType("ey"); }} /> {textOptions.spelling !== "Pakistani" && <>
Non-Inflecting Tail Spelling
{{ p: "ی", f: "ey" }}, value: "ey" }, { label: {{ p: "ای", f: "aay" }}, value: "aay" }, ]} value={aayTailType} handleChange={(p) => setAayTailType(p as "ey" | "aay")} /> }
Diacritics
setTextOptions({ ...textOptions, diacritics: p === "true" })} />
Pashto Text Size
setTextOptions({ ...textOptions, pTextSize: p as "normal" | "larger" | "largest" })} />
Phonetics
setTextOptions({ ...textOptions, phonetics: p as "lingdocs" | "ipa" | "none" | "alalc" })} />
} export default App;