Skip to content

Commit

Permalink
new determiners functionality in phrase builder
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Aug 7, 2024
1 parent e40b383 commit 6451cee
Show file tree
Hide file tree
Showing 29 changed files with 1,431 additions and 887 deletions.
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.4.1",
"version": "7.5.0",
"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.4.1",
"version": "7.5.0",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",
Expand Down
227 changes: 136 additions & 91 deletions src/components/src/ComplementPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,150 @@ import * as T from "../../types";
import AdjectivePicker from "./np-picker/AdjectivePicker";
import LocativeAdverbPicker from "./ep-explorer/eq-comp-picker/LocativeAdverbPicker";
import SandwichPicker from "./np-picker/SandwichPicker";
const compTypes: T.ComplementType[] = ["adjective", "loc. adv.", "sandwich", "comp. noun"];
const compTypes: T.ComplementType[] = [
"adjective",
"loc. adv.",
"sandwich",
"comp. noun",
];

function selectionTypeToCompType(s: Exclude<T.ComplementType, "comp. noun"> | "noun"): T.ComplementType {
if (s === "noun") return "comp. noun";
return s;
function selectionTypeToCompType(
s: Exclude<T.ComplementType, "comp. noun"> | "noun"
): T.ComplementType {
if (s === "noun") return "comp. noun";
return s;
}

function ComplementPicker(props: {
phraseIsComplete: boolean,
onChange: (comp: T.ComplementSelection | undefined) => void,
comp: T.ComplementSelection | undefined,
opts: T.TextOptions,
cantClear?: boolean,
heading?: JSX.Element | string,
entryFeeder: T.EntryFeeder,
phraseIsComplete: boolean;
onChange: (comp: T.ComplementSelection | undefined) => void;
comp: T.ComplementSelection | undefined;
opts: T.TextOptions;
cantClear?: boolean;
heading?: JSX.Element | string;
entryFeeder: T.EntryFeeder;
negative: boolean;
}) {
const [compType, setCompType] = useState<T.ComplementType | undefined>(props.comp
const [compType, setCompType] = useState<T.ComplementType | undefined>(
props.comp ? selectionTypeToCompType(props.comp.selection.type) : undefined
);
useEffect(() => {
setCompType(
props.comp
? selectionTypeToCompType(props.comp.selection.type)
: undefined);
useEffect(() => {
setCompType(props.comp
? selectionTypeToCompType(props.comp.selection.type)
: undefined);
}, [props.comp]);
function handleClear() {
setCompType(undefined);
props.onChange(undefined);
}
function handleCompTypeChange(ctp: T.ComplementType) {
props.onChange(undefined);
setCompType(ctp);
}
function handleSandwichExit() {
setCompType(undefined);
props.onChange(undefined);
}
const clearButton = (compType && !props.cantClear)
? <button className="btn btn-sm btn-light mb-2" onClick={handleClear}>X</button>
: <div></div>;
return <>
<div className="d-flex flex-row justify-content-between">
<div></div>
<div>
{typeof props.heading === "string"
? <div className="h5 text-center">{props.heading}</div>
: props.heading}
</div>
<div>
{clearButton}
</div>
: undefined
);
}, [props.comp]);
function handleClear() {
setCompType(undefined);
props.onChange(undefined);
}
function handleCompTypeChange(ctp: T.ComplementType) {
props.onChange(undefined);
setCompType(ctp);
}
function handleSandwichExit() {
setCompType(undefined);
props.onChange(undefined);
}
const clearButton =
compType && !props.cantClear ? (
<button className="btn btn-sm btn-light mb-2" onClick={handleClear}>
X
</button>
) : (
<div></div>
);
return (
<>
<div className="d-flex flex-row justify-content-between">
<div></div>
<div>
{typeof props.heading === "string" ? (
<div className="h5 text-center">{props.heading}</div>
) : (
props.heading
)}
</div>
{!compType && <div className="text-center">
<div className="h6 mr-3">
Choose Complement
</div>
{compTypes.map((cpt) => <div key={cpt} className="mb-2">
<button
key={cpt}
type="button"
className="mr-2 btn btn-sm btn-outline-secondary"
onClick={() => handleCompTypeChange(cpt)}
>
{cpt}
</button>
</div>)}
</div>}
<div style={{ minWidth: "9rem" }}>
{compType === "adjective" ?
<AdjectivePicker
entryFeeder={props.entryFeeder}
adjective={props.comp?.selection.type === "adjective" ? props.comp.selection : undefined}
opts={props.opts}
onChange={(a) => props.onChange(a ? { type: "complement", selection: a } : undefined)}
phraseIsComplete={props.phraseIsComplete}
/>
: compType === "loc. adv."
? <LocativeAdverbPicker
entryFeeder={props.entryFeeder.locativeAdverbs}
adjective={props.comp?.selection.type === "loc. adv." ? props.comp.selection : undefined}
opts={props.opts}
onChange={(a) => props.onChange(a ? { type: "complement", selection: a } : undefined)}
/>
: compType === "sandwich"
? <SandwichPicker
onChange={(a) => props.onChange(a ? { type: "complement", selection: a } : undefined)}
opts={props.opts}
sandwich={props.comp?.selection.type === "sandwich" ? props.comp.selection : undefined}
entryFeeder={props.entryFeeder}
onExit={handleSandwichExit}
// TODO: get phraseIsComplete working here
phraseIsComplete={props.phraseIsComplete}
/>
: compType === "comp. noun"
? <div style={{ maxWidth: "9rem" }}>
Sorry, can't choose complement nouns yet 🚧
<div>{clearButton}</div>
</div>
{!compType && (
<div className="text-center">
<div className="h6 mr-3">Choose Complement</div>
{compTypes.map((cpt) => (
<div key={cpt} className="mb-2">
<button
key={cpt}
type="button"
className="mr-2 btn btn-sm btn-outline-secondary"
onClick={() => handleCompTypeChange(cpt)}
>
{cpt}
</button>
</div>
: null}
))}
</div>
</>;
)}
<div style={{ minWidth: "9rem" }}>
{compType === "adjective" ? (
<AdjectivePicker
entryFeeder={props.entryFeeder}
adjective={
props.comp?.selection.type === "adjective"
? props.comp.selection
: undefined
}
opts={props.opts}
onChange={(a) =>
props.onChange(
a ? { type: "complement", selection: a } : undefined
)
}
phraseIsComplete={props.phraseIsComplete}
negative={props.negative}
/>
) : compType === "loc. adv." ? (
<LocativeAdverbPicker
entryFeeder={props.entryFeeder.locativeAdverbs}
adjective={
props.comp?.selection.type === "loc. adv."
? props.comp.selection
: undefined
}
opts={props.opts}
onChange={(a) =>
props.onChange(
a ? { type: "complement", selection: a } : undefined
)
}
/>
) : compType === "sandwich" ? (
<SandwichPicker
onChange={(a) =>
props.onChange(
a ? { type: "complement", selection: a } : undefined
)
}
opts={props.opts}
sandwich={
props.comp?.selection.type === "sandwich"
? props.comp.selection
: undefined
}
entryFeeder={props.entryFeeder}
onExit={handleSandwichExit}
// TODO: get phraseIsComplete working here
phraseIsComplete={props.phraseIsComplete}
negative={props.negative}
/>
) : compType === "comp. noun" ? (
<div style={{ maxWidth: "9rem" }}>
Sorry, can't choose complement nouns yet 🚧
</div>
) : null}
</div>
</>
);
}

export default ComplementPicker;
export default ComplementPicker;
Loading

0 comments on commit 6451cee

Please sign in to comment.