diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b9093662..589de7d4b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ - [Getting Started](#getting-started) - [Prerequisites](#prerequisites) - [Text Editor](#text-editor) - - [Git ](#git) + - [Git](#git) - [NodeJS and NPM](#nodejs-and-npm) - [Firebase](#firebase) - [Mongo Setup](#mongo-setup) @@ -123,7 +123,7 @@ Before submitting a theme make sure... - Be sure to add your language to the `_list` and `_groups` files - Make sure the number of words in the file corresponds to the file name (for example: `languageName.json` is 200 words, `languageName_1k.json` is 1000 words, and so on) -(If you want to contribute languages but don't know how to, check [LANGUAGES.md](https://github.com/teddinotteddy/monkeytype/blob/30f77fdc271c52743e8541d3bd2d27e23a4f5fab/LANGUAGES.md)) +(If you want to contribute languages but don't know how to, check [LANGUAGES.md](https://github.com/Miodec/monkeytype/blob/master/LANGUAGES.md)) #### Quote Guidelines diff --git a/frontend/src/scripts/misc.ts b/frontend/src/scripts/misc.ts index b8127eded..5cce387bc 100644 --- a/frontend/src/scripts/misc.ts +++ b/frontend/src/scripts/misc.ts @@ -237,10 +237,10 @@ export async function getLanguageList(): Promise { } } -type LanguageGroup = { name: string; languages: string[] }; - -let languageGroupList: LanguageGroup[] = []; -export async function getLanguageGroups(): Promise { +let languageGroupList: MonkeyTypes.LanguageGroup[] = []; +export async function getLanguageGroups(): Promise< + MonkeyTypes.LanguageGroup[] +> { if (languageGroupList.length === 0) { return $.getJSON("languages/_groups.json", function (data) { languageGroupList = data; @@ -286,8 +286,8 @@ export async function getCurrentLanguage( export async function findCurrentGroup( language: string -): Promise { - let retgroup: LanguageGroup | undefined; +): Promise { + let retgroup: MonkeyTypes.LanguageGroup | undefined; const groups = await getLanguageGroups(); groups.forEach((group) => { if (retgroup === undefined) { diff --git a/frontend/src/scripts/pages/settings.ts b/frontend/src/scripts/pages/settings.ts index 56b7fb8ff..7b486db09 100644 --- a/frontend/src/scripts/pages/settings.ts +++ b/frontend/src/scripts/pages/settings.ts @@ -9,8 +9,6 @@ import * as Misc from "../misc"; // @ts-ignore import layouts from "../test/layouts"; // @ts-ignore -import * as LanguagePicker from "../settings/language-picker"; -// @ts-ignore import * as DB from "../db"; // @ts-ignore import * as Funbox from "../test/funbox"; @@ -33,6 +31,7 @@ type SettingsGroups = { }; export const groups: SettingsGroups = {}; + async function initGroups(): Promise { await UpdateConfig.loadPromise; groups["smoothCaret"] = new SettingsGroup( @@ -404,18 +403,18 @@ export async function fillSettingsPage(): Promise { $(".pageSettings .tip").addClass("hidden"); } + // Language Selection Combobox const languageEl = $(".pageSettings .section.language select").empty(); const groups = await Misc.getLanguageGroups(); groups.forEach((group) => { - let append = ``; - group.languages.forEach((language) => { - append += ``; + let langComboBox = ``; + group.languages.forEach((language: string) => { + langComboBox += ``; }); - append += ``; - languageEl.append(append); + langComboBox += ``; + languageEl.append(langComboBox); }); languageEl.select2(); @@ -674,7 +673,7 @@ export function update(): void { refreshTagsSettingsSection(); refreshPresetsSettingsSection(); - LanguagePicker.setActiveGroup(); + // LanguagePicker.setActiveGroup(); Shifted from grouped btns to combo-box setActiveFunboxButton(); ThemePicker.updateActiveTab(); ThemePicker.setCustomInputs(true); @@ -824,14 +823,16 @@ $(document).on("click", ".pageSettings .section.minBurst .button.save", () => { ); }); -$(document).on( - "click", - ".pageSettings .section.languageGroups .button", - (e) => { - const group = $(e.currentTarget).attr("group"); - LanguagePicker.setActiveGroup(group, true); - } -); +// Commented because started using combo-box for choosing languages instead of grouped buttons +// languages +// $(document).on( +// "click", +// ".pageSettings .section.languageGroups .button", +// (e) => { +// const group = $(e.currentTarget).attr("group"); +// LanguagePicker.setActiveGroup(group, true); +// } +// ); //funbox $(document).on("click", ".pageSettings .section.funbox .button", (e) => { diff --git a/frontend/src/scripts/settings/language-picker.js b/frontend/src/scripts/settings/language-picker.ts similarity index 52% rename from frontend/src/scripts/settings/language-picker.js rename to frontend/src/scripts/settings/language-picker.ts index 856657da7..631be35fd 100644 --- a/frontend/src/scripts/settings/language-picker.js +++ b/frontend/src/scripts/settings/language-picker.ts @@ -1,30 +1,41 @@ import * as Misc from "../misc"; +// @ts-ignore import Config, * as UpdateConfig from "../config"; +import * as Types from "../types/interfaces"; + +export async function setActiveGroup( + groupName: string | undefined, + clicked: boolean | undefined = false +): Promise { + let currentGroup: Types.LanguageGroup | undefined; -export async function setActiveGroup(groupName, clicked = false) { - let currentGroup; if (groupName === undefined) { currentGroup = await Misc.findCurrentGroup(Config.language); } else { - let groups = await Misc.getLanguageGroups(); - groups.forEach((g) => { + const groups: Types.LanguageGroup[] = await Misc.getLanguageGroups(); + groups.forEach((g: Types.LanguageGroup) => { if (g.name === groupName) { currentGroup = g; } }); } + $(`.pageSettings .section.languageGroups .button`).removeClass("active"); + + if (currentGroup === undefined) return; + $( `.pageSettings .section.languageGroups .button[group='${currentGroup.name}']` ).addClass("active"); - let langEl = $(".pageSettings .section.language .buttons").empty(); - currentGroup.languages.forEach((language) => { - langEl.append( - `
${language.replace( - /_/g, - " " - )}
` + const langElement: JQuery = $( + ".pageSettings .section.language .buttons" + ).empty(); + currentGroup.languages.forEach((langName: string) => { + langElement.append( + `
+ ${langName.replace(/_/g, " ")} +
` ); }); diff --git a/frontend/src/scripts/types/interfaces.ts b/frontend/src/scripts/types/interfaces.ts index 1f6f516a0..4d26b4b21 100644 --- a/frontend/src/scripts/types/interfaces.ts +++ b/frontend/src/scripts/types/interfaces.ts @@ -6,6 +6,8 @@ export declare type Mode = "time" | "words" | "quote" | "zen" | CustomModes; export declare type Mode2 = keyof PersonalBests[M]; +export declare type LanguageGroup = { name: string; languages: string[] }; + // export declare type Mode2 = 10 | 15 | 25 | 30 | 50 | 60 | 100 | 120 | 200 | "zen" | "custom"; export declare type NoncustomWordsModes = 10 | 25 | 50 | 100 | 200;