oops got the search ability back in there

This commit is contained in:
lingdocs 2022-04-07 15:41:02 +05:00
parent 35a5c3d3a5
commit d0850066a2
1 changed files with 36 additions and 8 deletions

View File

@ -12,7 +12,9 @@ import {
getEnglishWord, getEnglishWord,
removeFVarients, removeFVarients,
Types as T, Types as T,
InlinePs, phoneticsToDiacritics,
convertSpelling,
translatePhonetics,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
export const zIndexProps = { export const zIndexProps = {
@ -22,18 +24,42 @@ export const zIndexProps = {
export function makeVerbSelectOption(e: VerbEntry, opts: T.TextOptions): { value: string, label: string | JSX.Element } { export function makeVerbSelectOption(e: VerbEntry, opts: T.TextOptions): { value: string, label: string | JSX.Element } {
const eng = getEnglishVerb(e.entry); const eng = getEnglishVerb(e.entry);
const ps = plainTextPsAdjustment(
{ p: e.entry.p, f: removeFVarients(e.entry.f) },
opts,
);
return { return {
label: <InlinePs opts={opts}> label: `${ps.p} - ${ps.f} (${eng})`,
{{ p: e.entry.p, f: removeFVarients(e.entry.f), e: eng }}
</InlinePs>,
value: e.entry.ts.toString(), value: e.entry.ts.toString(),
}; };
} }
function plainTextPsAdjustment(ps: T.PsString, opts: T.TextOptions): T.PsString {
function getP(ps: T.PsString): string {
const p = opts.diacritics
? (phoneticsToDiacritics(ps.p, ps.f) || ps.p)
: ps.p;
return convertSpelling(p, opts.spelling);
}
function getF(f: string): string {
if (opts.phonetics === "none") {
return "";
}
return opts.phonetics === "lingdocs"
? f
: translatePhonetics(f, {
dialect: opts.dialect,
// @ts-ignore - weird TS not picking up the elimination of "none herre"
system: opts.phonetics,
});
}
return { p: getP(ps), f: getF(ps.f) };
}
export function makeSelectOption( export function makeSelectOption(
e: T.DictionaryEntry | VerbEntry | NounEntry | AdjectiveEntry | LocativeAdverbEntry, e: T.DictionaryEntry | VerbEntry | NounEntry | AdjectiveEntry | LocativeAdverbEntry,
opts: T.TextOptions, opts: T.TextOptions,
): { value: string, label: JSX.Element | string } { ): { value: string, label: string } {
const entry = "entry" in e ? e.entry : e; const entry = "entry" in e ? e.entry : e;
const eng = (isVerbEntry(e)) const eng = (isVerbEntry(e))
? (getEnglishParticiple(e.entry)) ? (getEnglishParticiple(e.entry))
@ -45,10 +71,12 @@ export function makeSelectOption(
: ("singular" in eng && eng.singular !== undefined) : ("singular" in eng && eng.singular !== undefined)
? eng.singular ? eng.singular
: eng.plural; : eng.plural;
const ps = plainTextPsAdjustment(
{ p: entry.p, f: removeFVarients(entry.f) },
opts,
);
return { return {
label: <InlinePs opts={opts}> label: `${ps.p} - ${ps.f} (${english})`,
{{ p: entry.p, f: removeFVarients(entry.f), e: english }}
</InlinePs>,
value: entry.ts.toString(), value: entry.ts.toString(),
}; };
} }