fix bug with quiz on dynamic compounds
This commit is contained in:
parent
8cdd3c5ee1
commit
a2a0200a38
|
@ -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",
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<T.NPSelection | undefined>(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<boolean>(false);
|
||||
const passedVerb = props.verb;
|
||||
// this isn't quite working
|
||||
// const [verb, setVerb] = useStickyState<T.VerbSelection | undefined>(
|
||||
// passedVerb
|
||||
|
@ -55,8 +53,8 @@ export function VPExplorer(props: {
|
|||
// : undefined,
|
||||
// "verbExplorerVerb",
|
||||
// );
|
||||
const [verb, setVerb] = useState<T.VerbSelection | undefined>(
|
||||
passedVerb ? makeVerbSelection(passedVerb, setSubject) : undefined
|
||||
const [verb, setVerb] = useState<T.VerbSelection>(
|
||||
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,
|
||||
},
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue