Skip to content

Commit

Permalink
Merge branch 'master' into feature/fix-crt-indicate-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
fehmer authored Dec 22, 2024
2 parents e26eb65 + 353fc14 commit ca166a4
Show file tree
Hide file tree
Showing 20 changed files with 202 additions and 42 deletions.
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
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
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
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
1 change: 1 addition & 0 deletions frontend/static/languages/_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@
"code_lua",
"code_luau",
"code_latex",
"code_typst",
"code_matlab",
"code_sql",
"code_perl",
Expand Down
1 change: 1 addition & 0 deletions frontend/static/languages/_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,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"
]
}
1 change: 0 additions & 1 deletion frontend/static/languages/polish_2k.json
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,6 @@
"Bóg",
"wybrać",
"zjawisko",
"abugida",
"według",
"kara",
"czas",
Expand Down
24 changes: 24 additions & 0 deletions frontend/static/quotes/dutch.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,30 @@
"source": "Etty Hillesum",
"length": 95,
"id": 65
},
{
"text": "Geef al uw geld aan de arme mensen... als zij hetzelfde doen heb je het morgen misschien al terug.",
"source": "Herman Brusselmans",
"length": 98,
"id": 66
},
{
"text": "Schrap het woord 'ik' uit het taalgebruik en de hele mensheid staat met de mond vol tanden en het paniekzweet op het voorhoofd.",
"source": "Herman Brusselmans",
"length": 127,
"id": 67
},
{
"text": "Een James Bond-boek is stom maar opwindend, terwijl een meesterwerk van de Vlaamse literatuur even stom maar daarbij ook nog vervelend is.",
"source": "Louis Paul Boon",
"length": 138,
"id": 68
},
{
"text": "Ik ben absoluut tegen de puurheid van de taal. Als het iets wezenlijks meebrengt, moet je anglicismen, germanismen en gallicismen meteen cultiveren. Ik geloof niet in het uitgedunde, dat men voorhoudt als het enige Nederlands, ik irriteer me aan de Nederlandse overheersing.",
"source": "Hugo Claus",
"length": 274,
"id": 69
}
]
}
2 changes: 1 addition & 1 deletion frontend/static/quotes/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@
"length": 204
},
{
"text": "There are mysteries to the universe we were never meant to solve, but who we are and why we are here, are not among them, those answers we carry inside.",
"text": "There are mysteries to the universe we were never meant to solve. But who we are and why we are here, are not among them. Those answers we carry inside.",
"source": "Transformers: Age of Extinction",
"id": 192,
"length": 152
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const UserNameSchema = doesNotContainProfanity(
.max(16)
.regex(
/^[\da-zA-Z_-]+$/,
"Can only contain lower/uppercase letters, underscare and minus."
"Can only contain lower/uppercase letters, underscore and minus."
)
);

Expand Down
20 changes: 20 additions & 0 deletions packages/funbox/__test__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as Util from "../src/util";

describe("util", () => {
describe("stringToFunboxNames", () => {
it("should get single funbox", () => {
expect(Util.stringToFunboxNames("58008")).toEqual(["58008"]);
});
it("should fail for unknown funbox name", () => {
expect(() => Util.stringToFunboxNames("unknown")).toThrowError(
new Error("Invalid funbox name: unknown")
);
});
it("should split multiple funboxes by hash", () => {
expect(Util.stringToFunboxNames("58008#choo_choo")).toEqual([
"58008",
"choo_choo",
]);
});
});
});
42 changes: 42 additions & 0 deletions packages/util/__test__/json.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { parseWithSchema } from "../src/json";
import { z } from "zod";

describe("json", () => {
describe("parseWithSchema", () => {
const schema = z.object({
test: z.boolean().optional(),
name: z.string(),
nested: z.object({ foo: z.string() }).strict().optional(),
});
it("should parse", () => {
const json = `{
"test":true,
"name":"bob",
"unknown":"unknown",
"nested":{
"foo":"bar"
}
}`;

expect(parseWithSchema(json, schema)).toStrictEqual({
test: true,
name: "bob",
nested: { foo: "bar" },
});
});
it("should fail with invalid schema", () => {
const json = `{
"test":"yes",
"nested":{
"foo":1
}
}`;

expect(() => parseWithSchema(json, schema)).toThrowError(
new Error(
`"test" Expected boolean, received string\n"name" Required\n"nested.foo" Expected string, received number`
)
);
});
});
});
3 changes: 2 additions & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"madge": "8.0.0",
"rimraf": "6.0.1",
"typescript": "5.5.4",
"vitest": "2.0.5"
"vitest": "2.0.5",
"zod": "3.23.8"
},
"exports": {
".": {
Expand Down
Loading

0 comments on commit ca166a4

Please sign in to comment.