fix bug with quiz on dynamic compounds

This commit is contained in:
lingdocs 2022-04-10 13:12:47 +05:00
parent 8cdd3c5ee1
commit a2a0200a38
4 changed files with 22 additions and 24 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "1.8.8", "version": "1.8.9",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -56,8 +56,8 @@ const perfectTenseOptions: { label: string | JSX.Element, value: T.PerfectTense
}]; }];
function TensePicker({ onChange, verb, mode }: { function TensePicker({ onChange, verb, mode }: {
verb: T.VerbSelection | undefined, verb: T.VerbSelection,
onChange: (p: T.VerbSelection | undefined) => void, onChange: (p: T.VerbSelection) => void,
mode: "charts" | "phrases" | "quiz", mode: "charts" | "phrases" | "quiz",
}) { }) {
function onTenseSelect(o: { value: T.VerbTense | T.PerfectTense } | null) { function onTenseSelect(o: { value: T.VerbTense | T.PerfectTense } | null) {

View File

@ -30,7 +30,7 @@ const servantEmoji = "🙇‍♂️";
// TODO: error handling on error with rendering etc // TODO: error handling on error with rendering etc
export function VPExplorer(props: { export function VPExplorer(props: {
verb?: T.VerbEntry, verb: T.VerbEntry,
opts: T.TextOptions, opts: T.TextOptions,
} & ({ } & ({
nouns: T.NounEntry[], nouns: T.NounEntry[],
@ -45,9 +45,7 @@ export function VPExplorer(props: {
const [subject, setSubject] = useStickyState<T.NPSelection | undefined>(undefined, "subjectNPSelection"); const [subject, setSubject] = useStickyState<T.NPSelection | undefined>(undefined, "subjectNPSelection");
// not quite working with stickyState // not quite working with stickyState
const [mode, setMode] = useStickyState<"charts" | "phrases" | "quiz">("phrases", "verbExplorerMode"); const [mode, setMode] = useStickyState<"charts" | "phrases" | "quiz">("phrases", "verbExplorerMode");
// const [mode, setMode] = useState<"charts" | "phrases" | "quiz">("charts");
const [showAnswer, setShowAnswer] = useState<boolean>(false); const [showAnswer, setShowAnswer] = useState<boolean>(false);
const passedVerb = props.verb;
// this isn't quite working // this isn't quite working
// const [verb, setVerb] = useStickyState<T.VerbSelection | undefined>( // const [verb, setVerb] = useStickyState<T.VerbSelection | undefined>(
// passedVerb // passedVerb
@ -55,8 +53,8 @@ export function VPExplorer(props: {
// : undefined, // : undefined,
// "verbExplorerVerb", // "verbExplorerVerb",
// ); // );
const [verb, setVerb] = useState<T.VerbSelection | undefined>( const [verb, setVerb] = useState<T.VerbSelection>(
passedVerb ? makeVerbSelection(passedVerb, setSubject) : undefined makeVerbSelection(props.verb, setSubject)
) )
useEffect(() => { useEffect(() => {
if (mode === "quiz") { if (mode === "quiz") {
@ -67,24 +65,20 @@ export function VPExplorer(props: {
// eslint-disable-next-line // eslint-disable-next-line
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!passedVerb) { setVerb(o => makeVerbSelection(props.verb, setSubject, o));
setVerb(undefined); if (mode === "quiz") {
} else { // TODO: Better
setVerb(o => makeVerbSelection(passedVerb, setSubject, o)); setMode("charts");
if (mode === "quiz") {
// TODO: Better
setMode("charts");
}
} }
// eslint-disable-next-line // eslint-disable-next-line
}, [passedVerb]); }, [props.verb]);
function handleChangeMode(m: "charts" | "phrases" | "quiz") { function handleChangeMode(m: "charts" | "phrases" | "quiz") {
if (m === "quiz") { if (m === "quiz") {
handleResetQuiz(); handleResetQuiz();
} }
setMode(m); setMode(m);
} }
function handleSetVerb(v: T.VerbSelection | undefined) { function handleSetVerb(v: T.VerbSelection) {
if (v?.verb.entry.ts !== verb?.verb.entry.ts) { if (v?.verb.entry.ts !== verb?.verb.entry.ts) {
handleResetQuiz(); handleResetQuiz();
} }
@ -237,7 +231,7 @@ function hasPronounConflict(subject: T.NPSelection | undefined, object: undefine
return isInvalidSubjObjCombo(subjPronoun.person, objPronoun.person); 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 (!subject) return undefined;
if (!verb) return undefined; if (!verb) return undefined;
if (verb.object === undefined) 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 { function switchSubjObj({ subject, verb }: SOClump): SOClump {
if (!subject|| !verb || !verb.object || !(typeof verb.object === "object")) { if (!subject|| !verb || !verb.object || !(typeof verb.object === "object")) {
return { subject, verb }; return { subject, verb };
@ -305,7 +299,11 @@ function setRandomQuizState(subject: T.NPSelection | undefined, verb: T.VerbSele
S: randSubj, S: randSubj,
V: { V: {
...verb, ...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 ? randObj
: verb.object, : verb.object,
}, },

View File

@ -16,9 +16,9 @@ function VerbPicker(props: ({
verbs: (s: string) => T.VerbEntry[], verbs: (s: string) => T.VerbEntry[],
getVerbByTs: (ts: number) => T.VerbEntry | undefined; getVerbByTs: (ts: number) => T.VerbEntry | undefined;
}) & { }) & {
verb: T.VerbSelection | undefined, verb: T.VerbSelection,
subject: T.NPSelection | undefined, subject: T.NPSelection | undefined,
onChange: (p: T.VerbSelection | undefined) => void, onChange: (p: T.VerbSelection) => void,
changeSubject: (p: T.NPSelection | undefined) => void, changeSubject: (p: T.NPSelection | undefined) => void,
opts: T.TextOptions, opts: T.TextOptions,
verbLocked: boolean, verbLocked: boolean,
@ -45,7 +45,7 @@ function VerbPicker(props: ({
function onVerbSelect(v: T.VerbEntry | undefined) { function onVerbSelect(v: T.VerbEntry | undefined) {
// TODO: what to do when clearing // TODO: what to do when clearing
if (!v) { if (!v) {
return props.onChange(v); return;
} }
props.onChange(makeVerbSelection(v, props.changeSubject, props.verb)); props.onChange(makeVerbSelection(v, props.changeSubject, props.verb));
} }