more on equative explorer
This commit is contained in:
parent
cb1ea724d8
commit
bb21dac626
|
@ -13,7 +13,7 @@ import {
|
||||||
assembleEquativeOutput,
|
assembleEquativeOutput,
|
||||||
SubjectInput,
|
SubjectInput,
|
||||||
} from "../../lib/equative-machine";
|
} from "../../lib/equative-machine";
|
||||||
import { isNoun, isPluralEntry } from "../../lib/type-predicates";
|
import { isNoun, isPluralEntry, isUnisexNoun } from "../../lib/type-predicates";
|
||||||
|
|
||||||
function EquativeDisplay({ state }: { state: ExplorerState }) {
|
function EquativeDisplay({ state }: { state: ExplorerState }) {
|
||||||
if (state.subjectType === "pronouns") {
|
if (state.subjectType === "pronouns") {
|
||||||
|
@ -27,6 +27,9 @@ function EquativeDisplay({ state }: { state: ExplorerState }) {
|
||||||
const subjInput: SubjectInput = isNoun(entry) ? {
|
const subjInput: SubjectInput = isNoun(entry) ? {
|
||||||
entry,
|
entry,
|
||||||
plural: isPluralEntry(entry) ? true : state.subjectsSelected.info.plural,
|
plural: isPluralEntry(entry) ? true : state.subjectsSelected.info.plural,
|
||||||
|
...isUnisexNoun(entry) ? {
|
||||||
|
gender: state.subjectsSelected.info.gender,
|
||||||
|
} : {},
|
||||||
} : entry;
|
} : entry;
|
||||||
|
|
||||||
const eq = assembleEquativeOutput(
|
const eq = assembleEquativeOutput(
|
||||||
|
|
|
@ -28,6 +28,7 @@ const defaultState: ExplorerState = {
|
||||||
subjectsSelected: {
|
subjectsSelected: {
|
||||||
noun: defaultNoun,
|
noun: defaultNoun,
|
||||||
participle: defaultParticiple,
|
participle: defaultParticiple,
|
||||||
|
unisexNoun: defaultUnisexNoun,
|
||||||
info: {
|
info: {
|
||||||
plural: false,
|
plural: false,
|
||||||
gender: "masc",
|
gender: "masc",
|
||||||
|
@ -44,7 +45,7 @@ function EquativeExplorer() {
|
||||||
unsafeSetState(newState);
|
unsafeSetState(newState);
|
||||||
}
|
}
|
||||||
return <>
|
return <>
|
||||||
<div className="d-flex flex-row justify-content-between">
|
<div className="d-flex flex-row justify-content-between align-items-center">
|
||||||
<SubjectSelector state={state} dispatch={dispatch} />
|
<SubjectSelector state={state} dispatch={dispatch} />
|
||||||
<PredicateSelector state={state} dispatch={dispatch} />
|
<PredicateSelector state={state} dispatch={dispatch} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,14 +7,14 @@ import {
|
||||||
ParticipleInput,
|
ParticipleInput,
|
||||||
} from "../../lib/equative-machine";
|
} from "../../lib/equative-machine";
|
||||||
|
|
||||||
const unisexNouns = nouns.filter(x => isUnisexNoun(x)) as UnisexNoun[];
|
const unisexNouns = sort(nouns.filter(x => isUnisexNoun(x)) as UnisexNoun[]);
|
||||||
const nonUnisexNouns = nouns.filter(x => !isUnisexNoun(x)) as (MascNoun | FemNoun)[];
|
const nonUnisexNouns = sort(nouns.filter(x => !isUnisexNoun(x)) as (MascNoun | FemNoun)[]);
|
||||||
|
|
||||||
|
|
||||||
const inputs = {
|
const inputs = {
|
||||||
adjective: sort(adjectives),
|
adjective: sort(adjectives),
|
||||||
unisexNoun: sort(unisexNouns),
|
unisexNoun: unisexNouns,
|
||||||
noun: sort(nonUnisexNouns),
|
noun: nonUnisexNouns,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
participle: sort(verbs.map(e => e.entry) as ParticipleInput[]),
|
participle: sort(verbs.map(e => e.entry) as ParticipleInput[]),
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,6 +41,7 @@ export function reducer(state: ExplorerState, action: ExplorerReducerAction): Ex
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (action.type === "setSubjectPlural") {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
subjectsSelected: {
|
subjectsSelected: {
|
||||||
|
@ -51,4 +52,15 @@ export function reducer(state: ExplorerState, action: ExplorerReducerAction): Ex
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
subjectsSelected: {
|
||||||
|
...state.subjectsSelected,
|
||||||
|
info: {
|
||||||
|
...state.subjectsSelected.info,
|
||||||
|
gender: action.payload,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
|
@ -8,10 +8,16 @@ import {
|
||||||
} from "./explorer-types";
|
} from "./explorer-types";
|
||||||
import {
|
import {
|
||||||
ButtonSelect,
|
ButtonSelect,
|
||||||
|
Types as T,
|
||||||
} from "@lingdocs/pashto-inflector";
|
} from "@lingdocs/pashto-inflector";
|
||||||
import { isPluralEntry } from "../../lib/type-predicates";
|
import { isPluralEntry } from "../../lib/type-predicates";
|
||||||
import Select from "react-select";
|
import Select from "react-select";
|
||||||
|
|
||||||
|
const zIndexProps = {
|
||||||
|
menuPortalTarget: document.body,
|
||||||
|
styles: { menuPortal: (base: any) => ({ ...base, zIndex: 9999 }) },
|
||||||
|
};
|
||||||
|
|
||||||
export function SubjectSelector({ state, dispatch }: {
|
export function SubjectSelector({ state, dispatch }: {
|
||||||
state: ExplorerState,
|
state: ExplorerState,
|
||||||
dispatch: (action: ExplorerReducerAction) => void,
|
dispatch: (action: ExplorerReducerAction) => void,
|
||||||
|
@ -36,7 +42,7 @@ export function SubjectSelector({ state, dispatch }: {
|
||||||
? undefined
|
? undefined
|
||||||
: state.subjectsSelected[state.subjectType];
|
: state.subjectsSelected[state.subjectType];
|
||||||
return <div className="form-group mr-2 flex-fill">
|
return <div className="form-group mr-2 flex-fill">
|
||||||
<label htmlFor="predicate-select"><strong>Subject:</strong></label>
|
<label htmlFor="predicate-select"><h5>Subject:</h5></label>
|
||||||
<div className="form-check">
|
<div className="form-check">
|
||||||
<input
|
<input
|
||||||
className="form-check-input"
|
className="form-check-input"
|
||||||
|
@ -65,6 +71,20 @@ export function SubjectSelector({ state, dispatch }: {
|
||||||
Nouns
|
Nouns
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="form-check">
|
||||||
|
<input
|
||||||
|
className="form-check-input"
|
||||||
|
type="radio"
|
||||||
|
name="unisexNounsSubjectRadio"
|
||||||
|
id="unisexNounsSubjectRadio"
|
||||||
|
value="unisexNoun"
|
||||||
|
checked={state.subjectType === "unisexNoun"}
|
||||||
|
onChange={onTypeSelect}
|
||||||
|
/>
|
||||||
|
<label className="form-check-label" htmlFor="unisexNounsPredicateRadio">
|
||||||
|
Unisex Nouns
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div className="form-check mb-2">
|
<div className="form-check mb-2">
|
||||||
<input
|
<input
|
||||||
className="form-check-input"
|
className="form-check-input"
|
||||||
|
@ -89,8 +109,11 @@ export function SubjectSelector({ state, dispatch }: {
|
||||||
options={options}
|
options={options}
|
||||||
isSearchable
|
isSearchable
|
||||||
placeholder={options.find(o => o.value === subject?.ts.toString())?.label}
|
placeholder={options.find(o => o.value === subject?.ts.toString())?.label}
|
||||||
|
{...zIndexProps}
|
||||||
/>
|
/>
|
||||||
{state.subjectType === "noun" && <ButtonSelect
|
<div className="d-flex flex-row justify-content-center">
|
||||||
|
{state.subjectType !== "participle" && <div className={state.subjectType === "unisexNoun" ? "mr-2" : ""}>
|
||||||
|
<ButtonSelect
|
||||||
small
|
small
|
||||||
options={[
|
options={[
|
||||||
...!pluralNounSelected ? [{ label: "Singular", value: "singular" }] : [],
|
...!pluralNounSelected ? [{ label: "Singular", value: "singular" }] : [],
|
||||||
|
@ -98,7 +121,20 @@ export function SubjectSelector({ state, dispatch }: {
|
||||||
]}
|
]}
|
||||||
value={(state.subjectsSelected.info.plural || pluralNounSelected) ? "plural" : "singular"}
|
value={(state.subjectsSelected.info.plural || pluralNounSelected) ? "plural" : "singular"}
|
||||||
handleChange={(p) => dispatch({ type: "setSubjectPlural", payload: p === "plural" ? true : false })}
|
handleChange={(p) => dispatch({ type: "setSubjectPlural", payload: p === "plural" ? true : false })}
|
||||||
/>}
|
/>
|
||||||
|
</div>}
|
||||||
|
{state.subjectType === "unisexNoun" && <div className="ml-2">
|
||||||
|
<ButtonSelect
|
||||||
|
small
|
||||||
|
options={[
|
||||||
|
{ label: "Masc.", value: "masc" },
|
||||||
|
{ label: "Fem.", value: "fem" },
|
||||||
|
]}
|
||||||
|
value={state.subjectsSelected.info.gender}
|
||||||
|
handleChange={(p) => dispatch({ type: "setSubjectGender", payload: p as T.Gender })}
|
||||||
|
/>
|
||||||
|
</div>}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</div>;
|
</div>;
|
||||||
|
@ -121,7 +157,7 @@ export function PredicateSelector({ state, dispatch }: {
|
||||||
}));
|
}));
|
||||||
const predicate = state.predicatesSelected[state.predicateType];
|
const predicate = state.predicatesSelected[state.predicateType];
|
||||||
return <div className="form-group ml-2 flex-fill" style={{ maxWidth: "50%" }}>
|
return <div className="form-group ml-2 flex-fill" style={{ maxWidth: "50%" }}>
|
||||||
<label htmlFor="predicate-select"><strong>Predicate:</strong></label>
|
<label htmlFor="predicate-select"><h5>Predicate:</h5></label>
|
||||||
<div className="form-check">
|
<div className="form-check">
|
||||||
<input
|
<input
|
||||||
className="form-check-input"
|
className="form-check-input"
|
||||||
|
@ -159,6 +195,7 @@ export function PredicateSelector({ state, dispatch }: {
|
||||||
options={options}
|
options={options}
|
||||||
isSearchable
|
isSearchable
|
||||||
placeholder={options.find(o => o.value === predicate.ts.toString())?.label}
|
placeholder={options.find(o => o.value === predicate.ts.toString())?.label}
|
||||||
|
{...zIndexProps}
|
||||||
/>
|
/>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Types as T } from "@lingdocs/pashto-inflector";
|
||||||
import { ParticipleInput } from "../../lib/equative-machine";
|
import { ParticipleInput } from "../../lib/equative-machine";
|
||||||
|
|
||||||
export type PredicateType = keyof PredicatesSelected;
|
export type PredicateType = keyof PredicatesSelected;
|
||||||
export type SubjectType = "noun" | "pronouns" | "participle";
|
export type SubjectType = "noun" | "pronouns" | "participle" | "unisexNoun";
|
||||||
|
|
||||||
export type ExplorerState = {
|
export type ExplorerState = {
|
||||||
subjectType: SubjectType,
|
subjectType: SubjectType,
|
||||||
|
@ -17,6 +17,7 @@ type PredicatesSelected = {
|
||||||
type SubjectSelected = {
|
type SubjectSelected = {
|
||||||
noun: Noun,
|
noun: Noun,
|
||||||
participle: ParticipleInput,
|
participle: ParticipleInput,
|
||||||
|
unisexNoun: UnisexNoun,
|
||||||
info: {
|
info: {
|
||||||
plural: boolean,
|
plural: boolean,
|
||||||
gender: T.Gender,
|
gender: T.Gender,
|
||||||
|
@ -33,4 +34,6 @@ export type ExplorerReducerAction = {
|
||||||
type: "setSubject", payload: number,
|
type: "setSubject", payload: number,
|
||||||
} | {
|
} | {
|
||||||
type: "setSubjectPlural", payload: boolean,
|
type: "setSubjectPlural", payload: boolean,
|
||||||
|
} | {
|
||||||
|
type: "setSubjectGender", payload: T.Gender,
|
||||||
};
|
};
|
|
@ -4,6 +4,4 @@ title: Equative Explorer 🌎
|
||||||
|
|
||||||
import EquativeExplorer from "../../components/equative-explorer/EquativeExplorer";
|
import EquativeExplorer from "../../components/equative-explorer/EquativeExplorer";
|
||||||
|
|
||||||
This is in progress... will be able to explore much more soon. 👷♂️
|
|
||||||
|
|
||||||
<EquativeExplorer />
|
<EquativeExplorer />
|
||||||
|
|
Loading…
Reference in New Issue