Skip to content

Commit

Permalink
added event emitter for VPExplorer for monitoring events
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed May 5, 2024
1 parent b5e33b1 commit 23f3dcd
Show file tree
Hide file tree
Showing 20 changed files with 1,505 additions and 339 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pashto-inflector",
"version": "7.0.9",
"version": "7.0.11",
"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",
Expand Down
4 changes: 2 additions & 2 deletions src/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/ps-react",
"version": "7.0.9",
"version": "7.0.11",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",
Expand Down
715 changes: 715 additions & 0 deletions src/components/src/verb-info/non-faded-tree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 26 additions & 8 deletions src/components/src/vp-explorer/VPExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { completeVPSelection } from "../../../lib/src/phrase-building/vp-tools";
import VPExplorerQuiz from "./VPExplorerQuiz";
// @ts-ignore
import LZString from "lz-string";
import { vpsReducer } from "../../../lib/src/phrase-building/vps-reducer";
import {
VpsReducerAction,
vpsReducer,
} from "../../../lib/src/phrase-building/vps-reducer";
import { getObjectSelection } from "../../../lib/src/phrase-building/blocks-utils";
import VPPicker from "./VPPicker";
import AllTensesDisplay from "./AllTensesDisplay";
Expand All @@ -34,6 +37,7 @@ function VPExplorer(props: {
handleLinkClick: ((ts: number) => void) | "none";
entryFeeder: T.EntryFeeder;
onlyPhrases?: boolean;
eventEmitter?: (e: string) => void;
}) {
const [vps, adjustVps] = useStickyReducer(
vpsReducer,
Expand Down Expand Up @@ -85,15 +89,23 @@ function VPExplorer(props: {
const VPSFromUrl = getVPSFromUrl();
if (VPSFromUrl) {
setMode("phrases");
adjustVps({
eventWrapper(adjustVps)({
type: "load vps",
payload: VPSFromUrl,
});
}
// eslint-disable-next-line
}, []);
function handleSubjObjSwap() {
adjustVps({ type: "swap subj/obj" });
eventWrapper(adjustVps)({ type: "swap subj/obj" });
}
function eventWrapper(f: (a: VpsReducerAction) => void) {
return function (action: VpsReducerAction) {
if (props.eventEmitter) {
props.eventEmitter(`VP exlorer ${props.verb.entry.p}`);
}
return f(action);
};
}
function quizLock<T>(f: T) {
if (mode === "quiz") {
Expand All @@ -105,7 +117,7 @@ function VPExplorer(props: {
return f;
}
function handleSetForm(form: T.FormVersion) {
adjustVps({
eventWrapper(adjustVps)({
type: "set form",
payload: form,
});
Expand Down Expand Up @@ -134,7 +146,7 @@ function VPExplorer(props: {
<div className="mt-3" style={{ maxWidth: "950px" }}>
<VerbPicker
vps={vps}
onChange={quizLock(adjustVps)}
onChange={quizLock(eventWrapper(adjustVps))}
opts={props.opts}
handleLinkClick={props.handleLinkClick}
/>
Expand Down Expand Up @@ -190,13 +202,19 @@ function VPExplorer(props: {
<VPPicker
opts={props.opts}
entryFeeder={props.entryFeeder}
onChange={(payload) => adjustVps({ type: "load vps", payload })}
onChange={(payload) =>
eventWrapper(adjustVps)({ type: "load vps", payload })
}
vps={vps}
/>
)}
{mode !== "phrases" && (
<div className="my-2">
<TensePicker vps={vps} onChange={adjustVps} mode={mode} />
<TensePicker
vps={vps}
onChange={eventWrapper(adjustVps)}
mode={mode}
/>
</div>
)}
{mode === "phrases" && (
Expand All @@ -207,7 +225,7 @@ function VPExplorer(props: {
object={object}
VS={vps.verb}
opts={props.opts}
onChange={adjustVps}
onChange={eventWrapper(adjustVps)}
/>
)}
{mode === "quiz" && <VPExplorerQuiz opts={props.opts} vps={vps} />}
Expand Down
Loading

0 comments on commit 23f3dcd

Please sign in to comment.