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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ node_modules_bak/

# dotenv environment variables file
.env
.env*

#vs code
.vscode/*
Expand Down
1 change: 1 addition & 0 deletions frontend/src/html/popups.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<button class="xpBarTest">xp bar test</button>
<button class="toggleFakeChartData">toggle fake chart data</button>
<button class="toggleCaretDebug">toggle caret debug</button>
<button class="disableSlowTimerFail">disable slow timer fail</button>
</div>
</dialog>

Expand Down
1 change: 1 addition & 0 deletions frontend/src/ts/input/handlers/insert-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
// make sure to not call TestInput.input.syncWithInputElement in here
// it will be updated later in the body of onInsertText
setInputElementValue(inputValue.slice(0, -options.data.length));
TestInput.input.syncWithInputElement();
for (let i = 0; i < options.data.length; i++) {
const char = options.data[i] as string;

Expand Down
6 changes: 0 additions & 6 deletions frontend/src/ts/input/handlers/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ async function handleFunboxes(
}

export async function onKeydown(event: KeyboardEvent): Promise<void> {
console.debug("wordsInput event keydown", {
event,
key: event.key,
code: event.code,
});

const now = performance.now();
TestInput.recordKeydownTime(now, event);

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ts/input/input-element.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const el = document.querySelector("#wordsInput") as HTMLInputElement;
const el = document.querySelector("#wordsInput") as HTMLTextAreaElement;

if (el === null) {
throw new Error("Words input element not found");
}

export function getInputElement(): HTMLInputElement {
export function getInputElement(): HTMLTextAreaElement {
return el;
}

Expand Down
13 changes: 5 additions & 8 deletions frontend/src/ts/input/listeners/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@ inputEl.addEventListener("select selectstart", (event) => {

inputEl.addEventListener("selectionchange", (event) => {
const selection = window.getSelection();

console.debug("wordsInput event selectionchange", {
event,
selection: selection?.toString(),
isCollapsed: selection?.isCollapsed,
selectionStart: (event.target as HTMLInputElement).selectionStart,
selectionEnd: (event.target as HTMLInputElement).selectionEnd,
selectionStart: inputEl.selectionStart,
selectionEnd: inputEl.selectionEnd,
});
const el = event.target;
if (el === null || !(el instanceof HTMLInputElement)) {
return;
}

const hasSelectedText = el.selectionStart !== el.selectionEnd;
const isCursorAtEnd = el.selectionStart === el.value.length;
const hasSelectedText = inputEl.selectionStart !== inputEl.selectionEnd;
const isCursorAtEnd = inputEl.selectionStart === inputEl.value.length;
if (hasSelectedText || !isCursorAtEnd) {
moveInputElementCaretToTheEnd();
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/ts/modals/dev-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { update } from "../elements/xp-bar";
import { toggleUserFakeChartData } from "../test/result";
import { toggleCaretDebug } from "../utils/caret";
import { getInputElement } from "../input/input-element";
import { disableSlowTimerFail } from "../test/test-timer";

let mediaQueryDebugLevel = 0;

Expand Down Expand Up @@ -94,6 +95,11 @@ async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.querySelector(".toggleCaretDebug")?.addEventListener("click", () => {
toggleCaretDebug();
});
modalEl
.querySelector(".disableSlowTimerFail")
?.addEventListener("click", () => {
disableSlowTimerFail();
});
}

const modal = new AnimatedModal({
Expand Down
53 changes: 30 additions & 23 deletions frontend/src/ts/test/test-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ let timer: NodeJS.Timeout | null = null;
const interval = 1000;
let expected = 0;

let slowTimerFailEnabled = true;
export function disableSlowTimerFail(): void {
slowTimerFailEnabled = false;
}

let timerDebug = false;
export function enableTimerDebug(): void {
timerDebug = true;
Expand Down Expand Up @@ -234,30 +239,32 @@ export async function start(): Promise<void> {
expected: expected,
nextDelay: delay,
});
if (
(Config.mode === "time" && Config.time < 130 && Config.time > 0) ||
(Config.mode === "words" && Config.words < 250 && Config.words > 0)
) {
if (delay < interval / 2) {
//slow timer
SlowTimer.set();
setLowFpsMode();
}
if (delay < interval / 10) {
slowTimerCount++;
if (slowTimerCount > 5) {
if (slowTimerFailEnabled) {
if (
(Config.mode === "time" && Config.time < 130 && Config.time > 0) ||
(Config.mode === "words" && Config.words < 250 && Config.words > 0)
) {
if (delay < interval / 2) {
//slow timer

Notifications.add(
'This could be caused by "efficiency mode" on Microsoft Edge.',
);

Notifications.add(
"Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.",
-1,
);

TimerEvent.dispatch("fail", "slow timer");
SlowTimer.set();
setLowFpsMode();
}
if (delay < interval / 10) {
slowTimerCount++;
if (slowTimerCount > 5) {
//slow timer

Notifications.add(
'This could be caused by "efficiency mode" on Microsoft Edge.',
);

Notifications.add(
"Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.",
-1,
);

TimerEvent.dispatch("fail", "slow timer");
}
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { defineConfig, mergeConfig } from "vite";
import injectHTML from "vite-plugin-html-inject";
import autoprefixer from "autoprefixer";
import "dotenv/config";
import { config as dotenvConfig } from "dotenv";
import PROD_CONFIG from "./vite.config.prod";
import DEV_CONFIG from "./vite.config.dev";
import MagicString from "magic-string";
import { Fonts } from "./src/ts/constants/fonts";

// Load environment variables based on NODE_ENV
const envFile =
process.env.NODE_ENV === "production" ? ".env.production" : ".env";
dotenvConfig({ path: envFile });

/** @type {import("vite").UserConfig} */
const BASE_CONFIG = {
plugins: [
Expand Down Expand Up @@ -63,8 +68,13 @@ const BASE_CONFIG = {

export default defineConfig(({ command }) => {
if (command === "build") {
const envFileName =
process.env.NODE_ENV === "production" ? ".env.production" : ".env";
if (process.env.RECAPTCHA_SITE_KEY === undefined) {
throw new Error(".env: RECAPTCHA_SITE_KEY is not defined");
throw new Error(`${envFileName}: RECAPTCHA_SITE_KEY is not defined`);
}
if (process.env.SENTRY && process.env.SENTRY_AUTH_TOKEN === undefined) {
throw new Error(`${envFileName}: SENTRY_AUTH_TOKEN is not defined`);
}
return mergeConfig(BASE_CONFIG, PROD_CONFIG);
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/release/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ const buildProject = () => {

if (isFrontend && !isBackend) {
runProjectRootCommand(
"SENTRY=1 npx turbo lint test check-assets build --filter @monkeytype/frontend --force",
"NODE_ENV=production SENTRY=1 npx turbo lint test check-assets build --filter @monkeytype/frontend --force",
);
} else if (isBackend && !isFrontend) {
runProjectRootCommand(
"SENTRY=1 npx turbo lint test build --filter @monkeytype/backend --force",
"NODE_ENV=production SENTRY=1 npx turbo lint test build --filter @monkeytype/backend --force",
);
} else {
runProjectRootCommand(
"SENTRY=1 npx turbo lint test check-assets build --force",
"NODE_ENV=production SENTRY=1 npx turbo lint test check-assets build --force",
);
}
};
Expand Down
Loading