/** * 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 PersonInfsPicker from "./PersInfsPicker"; import InflectionsTable from "./InflectionsTable"; import SingleItemDisplay from "./SingleItemDisplay"; import ButtonSelect from "./ButtonSelect"; import VerbTable from "./VerbTable"; import { getEnglishPersonInfo, isSentenceForm, } from "../lib/misc-helpers"; import { isAllOne, } from "../lib/p-text-helpers"; import * as T from "../types"; function agreementInfo(info: T.NonComboVerbInfo, displayForm: T.DisplayForm): React.ReactNode { if (!displayForm.past) { return null; } const beginning = "Verb agrees with the "; const agreesWith = (info.transitivity !== "intransitive" && displayForm.past && !displayForm.passive) ? "object" : "subject"; const extraExplanation = (!displayForm.past) ? "" : (info.transitivity === "grammatically transitive") ? " which is an unwritten 3rd pers. masc. object." : (info.type === "generative stative compound" || info.type === "dynamic compound") ? ` which is the complement ${info.objComplement.plural ? info.objComplement.plural.p : info.objComplement.entry.p} (${getEnglishPersonInfo(info.objComplement.person)})` : "" return <>Note: {beginning}{agreesWith}{extraExplanation} } function VerbFormDisplay({ displayForm, textOptions, info, showingFormInfo, english }: { displayForm: T.DisplayForm | T.VerbForm, english?: T.EnglishBlock | string, textOptions: T.TextOptions, showingFormInfo: boolean, info?: T.NonComboVerbInfo, }) { const [persInf, setPersInf] = useState("mascSing"); const [length, setLength] = useState("long"); const [showingExplanation, setShowingExplanation] = useState(false); const block = "label" in displayForm ? displayForm.form : displayForm; const chosenPersInf = "mascSing" in block ? block[persInf] : block; const form = "long" in chosenPersInf ? chosenPersInf[length] || chosenPersInf.short : chosenPersInf; useEffect(() => { if (length === "mini" && !("mini" in chosenPersInf)) { setLength("long"); } // setPersInf("mascSing"); setShowingExplanation(false); }, [block, length, chosenPersInf]); // TODO: This could be handled better to avoid the react-hooks/exhaustive-deps warning ? useEffect(() => { setShowingExplanation(false); }, [block]); const hasVariations = (!("masc" in form)) && (!("p" in form)) && (!isSentenceForm(form)) && !isAllOne(form as T.VerbBlock | T.ImperativeBlock); return <> {(("label" in displayForm && info) && showingFormInfo) && <> {(hasVariations || displayForm.past) &&

{agreementInfo(info, displayForm)}

}
Formula: {displayForm.formula}
{showingExplanation &&
{displayForm.explanation}
} } {"long" in chosenPersInf &&
setLength(p as T.Length)} />
} {("mascSing" in block && info) && setPersInf(p)} transitivity={info.transitivity} />} {"masc" in form ? : "p" in form ? : } } export default VerbFormDisplay;