2022-04-08 10:04:16 +00:00
|
|
|
import {
|
|
|
|
makeNounSelection,
|
|
|
|
} from "./picker-tools";
|
|
|
|
import * as T from "../../types";
|
|
|
|
import ButtonSelect from "../ButtonSelect";
|
|
|
|
import InlinePs from "../InlinePs";
|
|
|
|
// import { isFemNounEntry, isPattern1Entry, isPattern2Entry, isPattern3Entry, isPattern4Entry, isPattern5Entry, isPattern6FemEntry } from "../../lib/type-predicates";
|
|
|
|
import EntrySelect from "../EntrySelect";
|
2022-04-27 06:38:43 +00:00
|
|
|
import AdjectiveManager from "./AdjectiveManager";
|
2022-04-08 10:04:16 +00:00
|
|
|
|
|
|
|
// const filterOptions = [
|
|
|
|
// {
|
|
|
|
// label: "1",
|
|
|
|
// value: "1",
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// label: "2",
|
|
|
|
// value: "2",
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// label: "3",
|
|
|
|
// value: "3",
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// label: "4",
|
|
|
|
// value: "4",
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// label: "5",
|
|
|
|
// value: "5",
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// label: "6",
|
|
|
|
// value: "6",
|
|
|
|
// },
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// type FilterPattern = "1" | "2" | "3" | "4" | "5" | "6";
|
|
|
|
|
|
|
|
// function nounFilter(p: FilterPattern | undefined) {
|
|
|
|
// return p === undefined
|
|
|
|
// ? () => true
|
|
|
|
// : (p === "1")
|
|
|
|
// ? isPattern1Entry
|
|
|
|
// : (p === "2")
|
|
|
|
// ? isPattern2Entry
|
|
|
|
// : (p === "3")
|
|
|
|
// ? isPattern3Entry
|
|
|
|
// : (p === "4")
|
|
|
|
// ? isPattern4Entry
|
|
|
|
// : (p === "5")
|
|
|
|
// ? isPattern5Entry
|
|
|
|
// : (p === "6")
|
|
|
|
// ? (n: NounEntry) => (isFemNounEntry(n) && isPattern6FemEntry(n))
|
|
|
|
// : () => true;
|
|
|
|
// }
|
|
|
|
|
2022-04-26 07:11:46 +00:00
|
|
|
function NPNounPicker(props: {
|
2022-04-27 06:38:43 +00:00
|
|
|
entryFeeder: T.EntryFeeder,
|
2022-04-08 10:04:16 +00:00
|
|
|
noun: T.NounSelection | undefined,
|
|
|
|
onChange: (p: T.NounSelection | undefined) => void,
|
|
|
|
opts: T.TextOptions,
|
|
|
|
}) {
|
|
|
|
// const [patternFilter, setPatternFilter] = useState<FilterPattern | undefined>(undefined);
|
|
|
|
// const [showFilter, setShowFilter] = useState<boolean>(false)
|
|
|
|
// const nounsFiltered = props.nouns
|
|
|
|
// .filter(nounFilter(patternFilter))
|
|
|
|
// .sort((a, b) => (a.p.localeCompare(b.p, "af-PS")));
|
|
|
|
function onEntrySelect(entry: T.NounEntry | undefined) {
|
|
|
|
if (!entry) {
|
|
|
|
return props.onChange(undefined);
|
|
|
|
}
|
2022-05-06 19:57:39 +00:00
|
|
|
props.onChange(makeNounSelection(entry, props.noun));
|
2022-04-08 10:04:16 +00:00
|
|
|
}
|
|
|
|
// function handleFilterClose() {
|
|
|
|
// setPatternFilter(undefined);
|
|
|
|
// setShowFilter(false);
|
|
|
|
// }
|
2022-04-27 06:38:43 +00:00
|
|
|
function handelAdjectivesUpdate(adjectives: T.AdjectiveSelection[]) {
|
|
|
|
if (props.noun) {
|
|
|
|
props.onChange({
|
|
|
|
...props.noun,
|
|
|
|
adjectives,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-04-08 10:04:16 +00:00
|
|
|
return <div style={{ maxWidth: "225px", minWidth: "125px" }}>
|
|
|
|
{/* {showFilter && <div className="mb-2 text-center">
|
|
|
|
<div className="d-flex flex-row justify-content-between">
|
|
|
|
<div className="text-small mb-1">Filter by inflection pattern</div>
|
|
|
|
<div className="clickable" onClick={handleFilterClose}>X</div>
|
|
|
|
</div>
|
|
|
|
<ButtonSelect
|
|
|
|
options={filterOptions}
|
|
|
|
// @ts-ignore
|
|
|
|
value={patternFilter}
|
|
|
|
// @ts-ignore
|
|
|
|
handleChange={setPatternFilter}
|
|
|
|
/>
|
|
|
|
</div>} */}
|
2022-04-27 06:38:43 +00:00
|
|
|
{props.noun && <AdjectiveManager
|
|
|
|
adjectives={props.noun?.adjectives}
|
|
|
|
entryFeeder={props.entryFeeder.adjectives}
|
|
|
|
opts={props.opts}
|
|
|
|
onChange={handelAdjectivesUpdate}
|
|
|
|
/>}
|
2022-04-09 12:45:07 +00:00
|
|
|
<h6>Noun</h6>
|
2022-04-08 10:04:16 +00:00
|
|
|
{!(props.noun && props.noun.dynamicComplement) ? <div>
|
|
|
|
<EntrySelect
|
|
|
|
value={props.noun?.entry}
|
2022-04-27 06:38:43 +00:00
|
|
|
entryFeeder={props.entryFeeder.nouns}
|
2022-04-08 10:04:16 +00:00
|
|
|
onChange={onEntrySelect}
|
|
|
|
name="Noun"
|
|
|
|
opts={props.opts}
|
|
|
|
/>
|
|
|
|
</div> : <div>
|
|
|
|
{props.noun && <div>
|
|
|
|
<div className="mb-2">Included in Dyn. Compound:</div>
|
|
|
|
<div className="mb-3 text-center">
|
|
|
|
<InlinePs opts={props.opts}>
|
|
|
|
{{ p: props.noun.entry.p, f: props.noun.entry.f }}
|
|
|
|
</InlinePs>
|
|
|
|
<div className="text-muted">{props.noun.entry.e}</div>
|
|
|
|
</div>
|
|
|
|
</div>}
|
|
|
|
</div>}
|
|
|
|
{props.noun && <div className="my-2 d-flex flex-row justify-content-around align-items-center">
|
|
|
|
<div>
|
2022-04-27 06:38:43 +00:00
|
|
|
{props.noun.genderCanChange ? <ButtonSelect
|
2022-04-08 10:04:16 +00:00
|
|
|
small
|
|
|
|
options={[
|
|
|
|
{ label: "Masc", value: "masc" },
|
|
|
|
{ label: "Fem", value: "fem" },
|
|
|
|
]}
|
|
|
|
value={props.noun.gender}
|
2022-04-27 06:38:43 +00:00
|
|
|
handleChange={(gender) => {
|
|
|
|
if (!props.noun || !props.noun.genderCanChange) return;
|
|
|
|
props.onChange({
|
|
|
|
...props.noun,
|
|
|
|
gender,
|
|
|
|
});
|
2022-04-08 10:04:16 +00:00
|
|
|
}}
|
|
|
|
/> : props.noun.gender === "masc" ? "Masc." : "Fem."}
|
|
|
|
</div>
|
|
|
|
<div>
|
2022-04-27 06:38:43 +00:00
|
|
|
{props.noun.numberCanChange ? <ButtonSelect
|
2022-04-08 10:04:16 +00:00
|
|
|
small
|
|
|
|
options={[
|
|
|
|
{ label: "Sing.", value: "singular" },
|
|
|
|
{ label: "Plur.", value: "plural" },
|
|
|
|
]}
|
|
|
|
value={props.noun.number}
|
2022-04-27 06:38:43 +00:00
|
|
|
handleChange={(number) => {
|
|
|
|
if (!props.noun || !props.noun.numberCanChange) return;
|
|
|
|
props.onChange({
|
|
|
|
...props.noun,
|
|
|
|
number,
|
|
|
|
});
|
2022-04-08 10:04:16 +00:00
|
|
|
}}
|
|
|
|
/> : props.noun.number === "singular" ? "Sing." : "Plur."}
|
|
|
|
</div>
|
|
|
|
</div>}
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NPNounPicker;
|