Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aitchz authored Dec 23, 2024
2 parents a99e468 + 955bb50 commit 8573146
Show file tree
Hide file tree
Showing 30 changed files with 1,508 additions and 49 deletions.
7 changes: 7 additions & 0 deletions frontend/src/styles/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,13 @@ body.fb-nospace {
}
}

/* funbox underscore_spaces */
body.fb-underscore-spaces {
#words .word {
margin: 0.5em 0;
}
}

/* funbox arrows */
body.fb-arrows {
#words .word {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/ts/controllers/account-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { navigate } from "./route-controller";
import { FirebaseError } from "firebase/app";
import * as PSA from "../elements/psa";
import defaultResultFilters from "../constants/default-result-filters";
import { getActiveFunboxes } from "../test/funbox/list";

export const gmailProvider = new GoogleAuthProvider();
export const githubProvider = new GithubAuthProvider();
Expand Down Expand Up @@ -171,6 +172,11 @@ async function getDataAndInit(): Promise<boolean> {
);
await UpdateConfig.apply(snapshot.config);
UpdateConfig.saveFullConfigToLocalStorage(true);

//funboxes might be different and they wont activate on the account page
for (const fb of getActiveFunboxes()) {
fb.functions?.applyGlobalCSS?.();
}
}
AccountButton.loading(false);
TagController.loadActiveFromLocalStorage();
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,14 @@ function isCharCorrect(char: string, charIndex: number): boolean {
char === "‘" ||
char === "'" ||
char === "ʼ" ||
char === "׳") &&
char === "׳" ||
char === "ʻ") &&
(originalChar === "’" ||
originalChar === "‘" ||
originalChar === "'" ||
originalChar === "ʼ" ||
originalChar === "׳")
originalChar === "׳" ||
originalChar === "ʻ")
) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/ts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ export async function getUserResults(offset?: number): Promise<boolean> {
return false;
}

//another check in case user logs out while waiting for response
if (!isAuthenticated()) return false;

const results: SnapshotResult<Mode>[] = response.body.data.map((result) => {
if (result.bailedOut === undefined) result.bailedOut = false;
if (result.blindMode === undefined) result.blindMode = false;
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/ts/pages/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ async function fillSettingsPage(): Promise<void> {
/_/g,
" "
)}</div>`;
} else if (funbox.name === "underscore_spaces") {
// Display as "underscore_spaces". Does not replace underscores with spaces.
funboxElHTML += `<div class="funbox button" data-config-value='${funbox.name}' aria-label="${funbox.description}" data-balloon-pos="up" data-balloon-length="fit">${funbox.name}</div>`;
} else {
funboxElHTML += `<div class="funbox button" data-config-value='${
funbox.name
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/ts/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import * as AccountButton from "./elements/account-button";
import Konami from "konami";
import * as ServerConfiguration from "./ape/server-configuration";
import { getActiveFunboxes } from "./test/funbox/list";
import { loadPromise } from "./config";

$((): void => {
$(async (): Promise<void> => {
await loadPromise;
Misc.loadCSS("/css/slimselect.min.css", true);
Misc.loadCSS("/css/balloon.min.css", true);

Expand All @@ -19,11 +21,10 @@ $((): void => {
//to make sure the initial theme application doesnt animate the background color
$("body").css("transition", "background .25s, transform .05s");
MerchBanner.showIfNotClosedBefore();
setTimeout(() => {
for (const fb of getActiveFunboxes()) {
fb.functions?.applyGlobalCSS?.();
}
}, 500); //this approach will probably bite me in the ass at some point

for (const fb of getActiveFunboxes()) {
fb.functions?.applyGlobalCSS?.();
}

$("#app")
.css("opacity", "0")
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/ts/test/funbox/funbox-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type FunboxFunctions = {
getWord?: (wordset?: Wordset, wordIndex?: number) => string;
punctuateWord?: (word: string) => string;
withWords?: (words?: string[]) => Promise<Wordset>;
alterText?: (word: string) => string;
alterText?: (word: string, wordIndex: number, wordsBound: number) => string;
applyConfig?: () => void;
applyGlobalCSS?: () => void;
clearGlobal?: () => void;
Expand Down Expand Up @@ -584,6 +584,12 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
return GetText.getMorse(word);
},
},
underscore_spaces: {
alterText(word: string, wordIndex: number, limit: number): string {
if (wordIndex === limit - 1) return word; // don't add underscore to the last word
return word + "_";
},
},
crt: {
applyGlobalCSS(): void {
const isSafari = /^((?!chrome|android).)*safari/i.test(
Expand Down Expand Up @@ -620,6 +626,11 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
$("#globalFunBoxTheme").attr("href", ``);
},
},
ALL_CAPS: {
alterText(word: string): string {
return word.toUpperCase();
},
},
};

export function getFunboxFunctions(): Record<FunboxName, FunboxFunctions> {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ts/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export function getStats(): unknown {
lastResult,
start,
end,
start3,
end3,
afkHistory: TestInput.afkHistory,
errorHistory: TestInput.errorHistory,
wpmHistory: TestInput.wpmHistory,
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/ts/test/test-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function layoutfluid(): void {
function checkIfFailed(
wpmAndRaw: { wpm: number; raw: number },
acc: number
): void {
): boolean {
if (timerDebug) console.time("fail conditions");
TestInput.pushKeypressesToHistory();
TestInput.pushErrorToHistory();
Expand All @@ -143,16 +143,17 @@ function checkIfFailed(
SlowTimer.clear();
slowTimerCount = 0;
TimerEvent.dispatch("fail", "min speed");
return;
return true;
}
if (Config.minAcc === "custom" && acc < Config.minAccCustom) {
if (timer !== null) clearTimeout(timer);
SlowTimer.clear();
slowTimerCount = 0;
TimerEvent.dispatch("fail", "min accuracy");
return;
return true;
}
if (timerDebug) console.timeEnd("fail conditions");
return false;
}

function checkIfTimeIsUp(): void {
Expand Down Expand Up @@ -200,8 +201,8 @@ async function timerStep(): Promise<void> {
const acc = calculateAcc();
monkey(wpmAndRaw);
layoutfluid();
checkIfFailed(wpmAndRaw, acc);
checkIfTimeIsUp();
const failed = checkIfFailed(wpmAndRaw, acc);
if (!failed) checkIfTimeIsUp();
if (timerDebug) console.timeEnd("timer step -----------------------------");
}

Expand Down
10 changes: 7 additions & 3 deletions frontend/src/ts/test/words-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,14 @@ function getFunboxWord(
return word;
}

function applyFunboxesToWord(word: string): string {
function applyFunboxesToWord(
word: string,
wordIndex: number,
wordsBound: number
): string {
for (const fb of getActiveFunboxes()) {
if (fb.functions?.alterText) {
word = fb.functions.alterText(word);
word = fb.functions.alterText(word, wordIndex, wordsBound);
}
}
return word;
Expand Down Expand Up @@ -911,7 +915,7 @@ export async function getNextWord(
}
}

randomWord = applyFunboxesToWord(randomWord);
randomWord = applyFunboxesToWord(randomWord, wordIndex, wordsBound);

console.debug("Word:", randomWord);

Expand Down
21 changes: 0 additions & 21 deletions frontend/src/ts/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Mode2,
PersonalBests,
} from "@monkeytype/contracts/schemas/shared";
import { ZodError, ZodSchema } from "zod";
import {
CustomTextDataWithTextLen,
Result,
Expand Down Expand Up @@ -655,26 +654,6 @@ export function isObject(obj: unknown): obj is Record<string, unknown> {
return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
}

/**
* Parse a JSON string into an object and validate it against a schema
* @param input JSON string
* @param schema Zod schema to validate the JSON against
* @returns The parsed JSON object
*/
export function parseJsonWithSchema<T>(input: string, schema: ZodSchema<T>): T {
try {
const jsonParsed = JSON.parse(input) as unknown;
const zodParsed = schema.parse(jsonParsed);
return zodParsed;
} catch (error) {
if (error instanceof ZodError) {
throw new Error(error.errors.map((err) => err.message).join("\n"));
} else {
throw error;
}
}
}

export function deepClone<T>(obj: T[]): T[];
export function deepClone<T extends object>(obj: T): T;
export function deepClone<T>(obj: T): T;
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/ts/utils/url-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Difficulty,
} from "@monkeytype/contracts/schemas/configs";
import { z } from "zod";
import { parseWithSchema as parseJsonWithSchema } from "@monkeytype/util/json";

export async function linkDiscord(hashOverride: string): Promise<void> {
if (!hashOverride) return;
Expand Down Expand Up @@ -78,10 +79,7 @@ export function loadCustomThemeFromUrl(getOverride?: string): void {

let decoded: z.infer<typeof customThemeUrlDataSchema>;
try {
decoded = Misc.parseJsonWithSchema(
atob(getValue),
customThemeUrlDataSchema
);
decoded = parseJsonWithSchema(atob(getValue), customThemeUrlDataSchema);
} catch (e) {
console.log("Custom theme URL decoding failed", e);
Notifications.add(
Expand Down
4 changes: 2 additions & 2 deletions frontend/static/funbox/crt.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ body.crtmode footer,
body.crtmode #result,
body.crtmode #popups,
body.crtmode #notificationCenter,
body.crtmode .word.error,
body.crtmode .word .hints hint,
body.crtmode #words .word.error,
body.crtmode #words .word .hints hint,
body.crtmode input,
body.crtmode button,
body.crtmode textarea,
Expand Down
6 changes: 6 additions & 0 deletions frontend/static/languages/_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"name": "portuguese",
"languages": [
"portuguese",
"portuguese_1k",
"portuguese_3k",
"portuguese_5k",
"portuguese_320k",
Expand Down Expand Up @@ -180,6 +181,10 @@
"name": "irish",
"languages": ["irish"]
},
{
"name": "galician",
"languages": ["galician"]
},
{
"name": "thai",
"languages": ["thai"]
Expand Down Expand Up @@ -601,6 +606,7 @@
"code_lua",
"code_luau",
"code_latex",
"code_typst",
"code_matlab",
"code_sql",
"code_perl",
Expand Down
3 changes: 3 additions & 0 deletions frontend/static/languages/_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
,"ukrainian_latynka_endings"
,"portuguese"
,"portuguese_acentos_e_cedilha"
,"portuguese_1k"
,"portuguese_3k"
,"portuguese_5k"
,"portuguese_320k"
Expand Down Expand Up @@ -110,6 +111,7 @@
,"italian_280k"
,"friulian"
,"latin"
,"galician"
,"thai"
,"polish"
,"polish_2k"
Expand Down Expand Up @@ -337,6 +339,7 @@
,"code_lua"
,"code_luau"
,"code_latex"
,"code_typst"
,"code_matlab"
,"code_sql"
,"code_perl"
Expand Down
50 changes: 50 additions & 0 deletions frontend/static/languages/code_typst.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "code_typst",
"noLazyMode": true,
"ligatures": false,
"words": [
"#use",
"#set par(justify: true)",
"#show",
"#set",
"#let",
"#par",
"#figure",
"#underline",
"#smallcaps",
"#grid",
"#box",
"#place",
"#import",
"#link",
"#lorem(50)",
"let",
"#{",
"}",
"#(",
")",
"#[",
"]",
"$",
"@",
"*",
"-",
"_",
"\\",
"/",
"//",
"floor(x)",
"cal(A)",
"NN",
"RR",
">",
"<",
">=",
"gt.eq.not",
"sum_(k=1)^oo",
"pi",
"&=",
"vec",
"mat"
]
}
Loading

0 comments on commit 8573146

Please sign in to comment.