mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-28 16:54:04 +08:00
showing if language supports zipf or not
This commit is contained in:
parent
083d2c80ff
commit
d18e930840
2 changed files with 41 additions and 0 deletions
|
@ -17,8 +17,40 @@ import format from "date-fns/format";
|
|||
import { Auth } from "../firebase";
|
||||
import { skipXpBreakdown } from "../elements/account-button";
|
||||
import * as FunboxList from "./funbox/funbox-list";
|
||||
import { debounce } from "throttle-debounce";
|
||||
|
||||
const debouncedZipfCheck = debounce(250, () => {
|
||||
Misc.checkIfLanguageSupportsZipf(Config.language).then((supports) => {
|
||||
if (supports === "no") {
|
||||
Notifications.add(
|
||||
`${Misc.capitalizeFirstLetter(
|
||||
Config.language.replace(/_/g, " ")
|
||||
)} does not support Zipf funbox, because the list is not ordered by frequency. Please try another word list.`,
|
||||
0,
|
||||
7
|
||||
);
|
||||
}
|
||||
if (supports === "unknown") {
|
||||
Notifications.add(
|
||||
`${Misc.capitalizeFirstLetter(
|
||||
Config.language.replace(/_/g, " ")
|
||||
)} may not support Zipf funbox, because we don't know if its ordered by frequency or not. If you would like to add this label, please contact us.`,
|
||||
0,
|
||||
7
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ConfigEvent.subscribe((eventKey, eventValue) => {
|
||||
if (
|
||||
eventKey === "language" ||
|
||||
(eventKey === "funbox" &&
|
||||
(eventValue as string).split("#").includes("zipf"))
|
||||
) {
|
||||
debouncedZipfCheck();
|
||||
}
|
||||
|
||||
if (eventValue === undefined || typeof eventValue !== "boolean") return;
|
||||
if (eventKey === "flipTestColors") flipColors(eventValue);
|
||||
if (eventKey === "colorfulMode") colorful(eventValue);
|
||||
|
|
|
@ -1402,3 +1402,12 @@ export function dreymarIndex(arrayLength: number): number {
|
|||
const W = Math.ceil(h);
|
||||
return W - 1;
|
||||
}
|
||||
|
||||
export async function checkIfLanguageSupportsZipf(
|
||||
language: string
|
||||
): Promise<"yes" | "no" | "unknown"> {
|
||||
const lang = await getLanguage(language);
|
||||
if (lang.orderedByFrequency === true) return "yes";
|
||||
if (lang.orderedByFrequency === false) return "no";
|
||||
return "unknown";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue