From a2a0200a38a6e5394362d6899ee1fed26f2780f7 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 10 Apr 2022 13:12:47 +0500 Subject: [PATCH] fix bug with quiz on dynamic compounds --- package.json | 2 +- src/components/vp-explorer/TensePicker.tsx | 4 +-- src/components/vp-explorer/VPExplorer.tsx | 34 ++++++++++------------ src/components/vp-explorer/VerbPicker.tsx | 6 ++-- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 14ebd93..64950c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.8.8", + "version": "1.8.9", "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/components/vp-explorer/TensePicker.tsx b/src/components/vp-explorer/TensePicker.tsx index efb4ab6..a46fb7b 100644 --- a/src/components/vp-explorer/TensePicker.tsx +++ b/src/components/vp-explorer/TensePicker.tsx @@ -56,8 +56,8 @@ const perfectTenseOptions: { label: string | JSX.Element, value: T.PerfectTense }]; function TensePicker({ onChange, verb, mode }: { - verb: T.VerbSelection | undefined, - onChange: (p: T.VerbSelection | undefined) => void, + verb: T.VerbSelection, + onChange: (p: T.VerbSelection) => void, mode: "charts" | "phrases" | "quiz", }) { function onTenseSelect(o: { value: T.VerbTense | T.PerfectTense } | null) { diff --git a/src/components/vp-explorer/VPExplorer.tsx b/src/components/vp-explorer/VPExplorer.tsx index eb1a441..85d38b0 100644 --- a/src/components/vp-explorer/VPExplorer.tsx +++ b/src/components/vp-explorer/VPExplorer.tsx @@ -30,7 +30,7 @@ const servantEmoji = "🙇‍♂️"; // TODO: error handling on error with rendering etc export function VPExplorer(props: { - verb?: T.VerbEntry, + verb: T.VerbEntry, opts: T.TextOptions, } & ({ nouns: T.NounEntry[], @@ -45,9 +45,7 @@ export function VPExplorer(props: { const [subject, setSubject] = useStickyState(undefined, "subjectNPSelection"); // not quite working with stickyState const [mode, setMode] = useStickyState<"charts" | "phrases" | "quiz">("phrases", "verbExplorerMode"); - // const [mode, setMode] = useState<"charts" | "phrases" | "quiz">("charts"); const [showAnswer, setShowAnswer] = useState(false); - const passedVerb = props.verb; // this isn't quite working // const [verb, setVerb] = useStickyState( // passedVerb @@ -55,8 +53,8 @@ export function VPExplorer(props: { // : undefined, // "verbExplorerVerb", // ); - const [verb, setVerb] = useState( - passedVerb ? makeVerbSelection(passedVerb, setSubject) : undefined + const [verb, setVerb] = useState( + makeVerbSelection(props.verb, setSubject) ) useEffect(() => { if (mode === "quiz") { @@ -67,24 +65,20 @@ export function VPExplorer(props: { // eslint-disable-next-line }, []); useEffect(() => { - if (!passedVerb) { - setVerb(undefined); - } else { - setVerb(o => makeVerbSelection(passedVerb, setSubject, o)); - if (mode === "quiz") { - // TODO: Better - setMode("charts"); - } + setVerb(o => makeVerbSelection(props.verb, setSubject, o)); + if (mode === "quiz") { + // TODO: Better + setMode("charts"); } // eslint-disable-next-line - }, [passedVerb]); + }, [props.verb]); function handleChangeMode(m: "charts" | "phrases" | "quiz") { if (m === "quiz") { handleResetQuiz(); } setMode(m); } - function handleSetVerb(v: T.VerbSelection | undefined) { + function handleSetVerb(v: T.VerbSelection) { if (v?.verb.entry.ts !== verb?.verb.entry.ts) { handleResetQuiz(); } @@ -237,7 +231,7 @@ function hasPronounConflict(subject: T.NPSelection | undefined, object: undefine return isInvalidSubjObjCombo(subjPronoun.person, objPronoun.person); } -function verbPhraseComplete({ subject, verb }: { subject: T.NPSelection | undefined, verb: T.VerbSelection | undefined }): T.VPSelection | undefined { +function verbPhraseComplete({ subject, verb }: { subject: T.NPSelection | undefined, verb: T.VerbSelection }): T.VPSelection | undefined { if (!subject) return undefined; if (!verb) return undefined; if (verb.object === undefined) return undefined; @@ -257,7 +251,7 @@ function showRole(VP: T.VPRendered | undefined, member: "subject" | "object") { : ""; } -type SOClump = { subject: T.NPSelection | undefined, verb: T.VerbSelection | undefined }; +type SOClump = { subject: T.NPSelection | undefined, verb: T.VerbSelection }; function switchSubjObj({ subject, verb }: SOClump): SOClump { if (!subject|| !verb || !verb.object || !(typeof verb.object === "object")) { return { subject, verb }; @@ -305,7 +299,11 @@ function setRandomQuizState(subject: T.NPSelection | undefined, verb: T.VerbSele S: randSubj, V: { ...verb, - object: (typeof verb.object === "object" || verb.object === undefined) + object: ( + (typeof verb.object === "object" && !(verb.object.type === "noun" && verb.object.dynamicComplement)) + || + verb.object === undefined + ) ? randObj : verb.object, }, diff --git a/src/components/vp-explorer/VerbPicker.tsx b/src/components/vp-explorer/VerbPicker.tsx index 7efe787..1645dfc 100644 --- a/src/components/vp-explorer/VerbPicker.tsx +++ b/src/components/vp-explorer/VerbPicker.tsx @@ -16,9 +16,9 @@ function VerbPicker(props: ({ verbs: (s: string) => T.VerbEntry[], getVerbByTs: (ts: number) => T.VerbEntry | undefined; }) & { - verb: T.VerbSelection | undefined, + verb: T.VerbSelection, subject: T.NPSelection | undefined, - onChange: (p: T.VerbSelection | undefined) => void, + onChange: (p: T.VerbSelection) => void, changeSubject: (p: T.NPSelection | undefined) => void, opts: T.TextOptions, verbLocked: boolean, @@ -45,7 +45,7 @@ function VerbPicker(props: ({ function onVerbSelect(v: T.VerbEntry | undefined) { // TODO: what to do when clearing if (!v) { - return props.onChange(v); + return; } props.onChange(makeVerbSelection(v, props.changeSubject, props.verb)); }