Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
698 changes: 12 additions & 686 deletions backend/src/api/controllers/result.ts

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions backend/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function formatSeconds(
}

export function intersect<T>(a: T[], b: T[], removeDuplicates = false): T[] {
let t;
let t: T[];
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
if (b.length > a.length) (t = b), (b = a), (a = t); // indexOf to loop over shorter
const filtered = a.filter(function (e) {
Expand All @@ -198,9 +198,8 @@ export function intersect<T>(a: T[], b: T[], removeDuplicates = false): T[] {
return removeDuplicates ? [...new Set(filtered)] : filtered;
}


export function escapeHTML(str: string): string {
return String(str).replace(/[^\w. ]/gi, function (c) {
return str.replace(/[^\w. ]/gi, function (c) {
return "&#" + c.charCodeAt(0) + ";";
});
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/html/pages/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,10 @@
<i class="fas fa-fw fa-ad"></i>
</button> -->
</div>
</div>
<div class="loginTip">
<a href="/login" router-link>Sign in</a>
to save your result
<div class="loginTip">
<a href="/login" router-link>Sign in</a>
to save your result
</div>
</div>
<div class="ssWatermark hidden">monkeytype.com</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/styles/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@
"tribeResults tribeResults"
"stats chart"
"morestats morestats"
"bottom bottom"
"tribeBottom tribeBottom";
// "wordsHistory wordsHistory"
// "buttons buttons"
Expand Down Expand Up @@ -780,6 +781,10 @@
-webkit-user-select: none;
}

.bottom {
grid-area: bottom;
}

.chart {
grid-area: chart;
width: 100%;
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/styles/tribe.scss
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,17 @@
}
}

.pageTest #typingTest .tribeBars,
.pageTribe .tribeBars {
grid-area: players;
}

.pageTest #typingTest .tribeBars {
margin-bottom: 1em;
font-size: 1rem;
}

.pageTest #typingTest .tribeBars,
.pageTribe .tribeBars {
td {
padding: 0 0.5rem;
}
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/ts/commandline/commandline-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,16 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = {
options: "fromSchema",
},
},

//tribe
tribeDelta: {
subgroup: {
options: "fromSchema",
},
},
tribeCarets: {
subgroup: {
options: "fromSchema",
},
},
};
30 changes: 18 additions & 12 deletions frontend/src/ts/commandline/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const adsCommand = buildCommandForConfigKey("ads");
const minSpeedCommand = buildCommandForConfigKey("minWpm");
const minAccCommand = buildCommandForConfigKey("minAcc");
const paceCaretCommand = buildCommandForConfigKey("paceCaret");
const modeCommand = buildCommandForConfigKey("mode");
const timeCommand = buildCommandForConfigKey("time");
const wordsCommand = buildCommandForConfigKey("words");
const quoteLengthCommand = buildCommandForConfigKey("quoteLength");
const punctuationCommand = buildCommandForConfigKey("punctuation");
const numbersCommand = buildCommandForConfigKey("numbers");

export const commands: CommandsSubgroup = {
title: "",
Expand All @@ -68,12 +74,12 @@ export const commands: CommandsSubgroup = {
...ResultScreenCommands,

//test screen
buildCommandForConfigKey("punctuation"),
buildCommandForConfigKey("numbers"),
buildCommandForConfigKey("mode"),
buildCommandForConfigKey("time"),
buildCommandForConfigKey("words"),
buildCommandForConfigKey("quoteLength"),
punctuationCommand,
numbersCommand,
modeCommand,
timeCommand,
wordsCommand,
quoteLengthCommand,
languageCommand,
{
id: "changeCustomModeText",
Expand Down Expand Up @@ -371,12 +377,12 @@ const lists = {
tags: TagsCommands[0]?.subgroup,
resultSaving: ResultSavingCommands[0]?.subgroup,
blindMode: blindModeCommand.subgroup,
mode: ModeCommands[0]?.subgroup,
time: TimeCommands[0]?.subgroup,
words: WordsCommands[0]?.subgroup,
quoteLength: QuoteLengthCommands[0]?.subgroup,
punctuation: PunctuationCommands[0]?.subgroup,
numbers: NumbersCommands[0]?.subgroup,
mode: modeCommand.subgroup,
time: timeCommand.subgroup,
words: wordsCommand.subgroup,
quoteLength: quoteLengthCommand.subgroup,
punctuation: punctuationCommand.subgroup,
numbers: numbersCommand.subgroup,
};

export function doesListExist(listName: string): boolean {
Expand Down
24 changes: 18 additions & 6 deletions frontend/src/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,29 @@ export function genericSet<T extends keyof ConfigSchemas.Config>(
}

//numbers
export function setNumbers(numb: boolean, nosave?: boolean): boolean {
return genericSet("numbers", numb, nosave);
export function setNumbers(
numb: boolean,
nosave?: boolean,
tribeOverride = false
): boolean {
return genericSet("numbers", numb, nosave, tribeOverride);
}

//punctuation
export function setPunctuation(punc: boolean, nosave?: boolean): boolean {
return genericSet("punctuation", punc, nosave);
export function setPunctuation(
punc: boolean,
nosave?: boolean,
tribeOverride = false
): boolean {
return genericSet("punctuation", punc, nosave, tribeOverride);
}

export function setMode(mode: Mode, nosave?: boolean): boolean {
return genericSet("mode", mode, nosave);
export function setMode(
mode: Mode,
nosave?: boolean,
tribeOverride = false
): boolean {
return genericSet("mode", mode, nosave, tribeOverride);
}

export function setPlaySoundOnError(
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,12 @@ $(document).on("keydown", async (event) => {
if (TribeState.getState() >= 5) {
if (TribeState.getState() > 5 && TribeState.getState() < 21) return;
if (TribeState.getState() === 5 && ActivePage.get() !== "tribe") {
navigate("/tribe");
void navigate("/tribe");
return;
}
} else {
if (ActivePage.get() !== "test") {
navigate("/");
void navigate("/");
return;
}
}
Expand Down Expand Up @@ -1061,10 +1061,10 @@ $(document).on("keydown", async (event) => {
event,
});
} else {
handleChar("\n", TestInput.input.current.length);
void handleChar("\n", TestInput.input.current.length);
setWordsInput(" " + TestInput.input.current);
if (Config.tapeMode !== "off") {
TestUI.scrollTape();
void TestUI.scrollTape();
}
}
}
Expand Down Expand Up @@ -1093,12 +1093,12 @@ $(document).on("keydown", async (event) => {
if (TribeState.getState() >= 5) {
if (TribeState.getState() > 5 && TribeState.getState() < 21) return;
if (TribeState.getState() === 5 && ActivePage.get() !== "tribe") {
navigate("/tribe");
void navigate("/tribe");
return;
}
} else {
if (ActivePage.get() !== "test") {
navigate("/");
void navigate("/");
return;
}
}
Expand Down Expand Up @@ -1146,10 +1146,10 @@ $(document).on("keydown", async (event) => {
event,
});
} else {
handleChar("\n", TestInput.input.current.length);
void handleChar("\n", TestInput.input.current.length);
setWordsInput(" " + TestInput.input.current);
if (Config.tapeMode !== "off") {
TestUI.scrollTape();
void TestUI.scrollTape();
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/ts/controllers/route-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { isFunboxActive } from "../test/funbox/list";
import * as TestState from "../test/test-state";
import * as Notifications from "../elements/notifications";
import tribeSocket from "../tribe/tribe-socket";
import { setAutoJoin } from "../tribe/tribe";
import { setAutoJoin } from "../tribe/tribe-auto-join";
import { LoadingOptions } from "../pages/page";
import { setNavigationService } from "../observables/navigate-event";

//source: https://www.youtube.com/watch?v=OstALBk-jTc
// https://www.youtube.com/watch?v=OstALBk-jTc
Expand Down Expand Up @@ -310,3 +311,11 @@ document.addEventListener("DOMContentLoaded", () => {
}
});
});

// Register navigation service for modules that can't directly import navigate
// due to circular dependency constraints
setNavigationService({
navigate(url, options) {
void navigate(url, options);
},
});
6 changes: 3 additions & 3 deletions frontend/src/ts/elements/input-suggestions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as TribeTypes from "../tribe/types";

export class InputSuggestions {
private inputElement: JQuery<HTMLElement>;
private suggestionsElement: JQuery<HTMLElement> | undefined;
private inputElement: JQuery;
private suggestionsElement: JQuery | undefined;
private maxSuggestions: number;
private selectedIndex: number | undefined;
private prefix: string;
Expand All @@ -14,7 +14,7 @@ export class InputSuggestions {
private applyWith: string[];

constructor(
inputElement: JQuery<HTMLElement>,
inputElement: JQuery,
prefix: string,
suffix: string,
maxSuggestions: number,
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/ts/observables/navigate-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
type NavigateOptions = {
force?: boolean;
tribeOverride?: boolean;
};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NavigationService {
navigate(url: string, options?: NavigateOptions): void;
}

let service: NavigationService | undefined;

export function setNavigationService(s: NavigationService): void {
if (service !== undefined) {
throw new Error("NavigationService already initialized");
}
service = s;
}

export function navigate(url: string, options?: NavigateOptions): void {
if (service === undefined) {
throw new Error("NavigationService not initialized");
}
service.navigate(url, options);
}
3 changes: 1 addition & 2 deletions frontend/src/ts/pages/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ export const page = new Page({
beforeHide: async (): Promise<void> => {
$("#wordsInput").trigger("focusout");
},
afterHide: async (options): Promise<void> => {
afterHide: async (): Promise<void> => {
ManualRestart.set();
TestLogic.restart({
noAnim: true,
tribeOverride: options.tribeOverride ?? false,
});
void Funbox.clear();
void ModesNotice.update();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/pages/tribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as TribeState from "../tribe/tribe-state";
import * as TribeChat from "../tribe/tribe-chat";

export const page = new Page({
name: "tribe",
id: "tribe",
element: $(".page.pageTribe"),
path: "/tribe",
beforeHide: async () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/popups/tribe-browse-public-rooms-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function show(): void {
.css("opacity", 0)
.removeClass("hidden")
.animate({ opacity: 1 }, 125, () => {
$("#tribeBrowsePublicRoomsPopup .search").focus();
$("#tribeBrowsePublicRoomsPopup .search").trigger("focus");
$("#tribeBrowsePublicRoomsPopup .search").val("");
});
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/popups/tribe-room-code-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function show(): void {
.css("opacity", 0)
.removeClass("hidden")
.animate({ opacity: 1 }, 125, () => {
$("#tribeRoomCodePopup input").focus();
$("#tribeRoomCodePopup input").trigger("focus");
$("#tribeRoomCodePopup input").val("");
});
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ export async function retrySavingResult(): Promise<void> {

const tribeChartData = {
wpm: [...(completedEvent.chartData as ChartData).wpm],
raw: [...(completedEvent.chartData as ChartData).raw],
burst: [...(completedEvent.chartData as ChartData).burst],
err: [...(completedEvent.chartData as ChartData).err],
};

Expand Down Expand Up @@ -1302,7 +1302,7 @@ export async function finish(difficultyFailed = false): Promise<void> {

const tribeChartData = {
wpm: [...(completedEvent.chartData as ChartData).wpm],
raw: [...(completedEvent.chartData as ChartData).raw],
burst: [...(completedEvent.chartData as ChartData).burst],
err: [...(completedEvent.chartData as ChartData).err],
};

Expand Down
9 changes: 9 additions & 0 deletions frontend/src/ts/test/test-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export let isLanguageRightToLeft = false;
export let isDirectionReversed = false;
export let testRestarting = false;
export let resultVisible = false;
export let removedUIWordCount = 0;

export function setRepeated(tf: boolean): void {
isRepeated = tf;
Expand Down Expand Up @@ -85,3 +86,11 @@ export function setTestRestarting(val: boolean): void {
export function setResultVisible(val: boolean): void {
resultVisible = val;
}

export function setRemovedUIWordCount(val: number): void {
removedUIWordCount = val;
}

export function incrementRemovedUIWordCount(): void {
removedUIWordCount++;
}
Loading
Loading