diff --git a/frontend/src/ts/test/test-ui.ts b/frontend/src/ts/test/test-ui.ts index 30d53613b..f27bccac8 100644 --- a/frontend/src/ts/test/test-ui.ts +++ b/frontend/src/ts/test/test-ui.ts @@ -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); diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index c6252c1be..ad8569417 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -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"; +}