mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-17 19:15:59 +08:00
moved test active to a state module
fixes 3 circular dependencies part of #2462
This commit is contained in:
parent
beac92f399
commit
a8d0d807f2
14 changed files with 46 additions and 35 deletions
|
@ -687,8 +687,6 @@ export function setHighlightMode(mode, nosave) {
|
|||
mode = "letter";
|
||||
}
|
||||
config.highlightMode = mode;
|
||||
// if(TestLogic.active){
|
||||
// }
|
||||
if (!nosave) saveToLocalStorage();
|
||||
dispatchEvent("highlightMode", config.highlightMode);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import * as MonkeyPower from "../elements/monkey-power";
|
|||
import * as WeakSpot from "../test/weak-spot";
|
||||
import * as Leaderboards from "../elements/leaderboards";
|
||||
import * as ActivePage from "./../states/active-page";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
let dontInsertSpace = false;
|
||||
let correctShiftUsed = true;
|
||||
|
@ -56,7 +57,7 @@ function updateUI() {
|
|||
}
|
||||
|
||||
function backspaceToPrevious() {
|
||||
if (!TestLogic.active) return;
|
||||
if (!TestActive.get()) return;
|
||||
|
||||
if (
|
||||
TestLogic.input.history.length == 0 ||
|
||||
|
@ -93,7 +94,7 @@ function backspaceToPrevious() {
|
|||
}
|
||||
|
||||
function handleSpace() {
|
||||
if (!TestLogic.active) return;
|
||||
if (!TestActive.get()) return;
|
||||
|
||||
if (TestLogic.input.current === "") return;
|
||||
|
||||
|
@ -395,7 +396,7 @@ function handleChar(char, charIndex) {
|
|||
}
|
||||
|
||||
//start the test
|
||||
if (!TestLogic.active && !TestLogic.startTest()) {
|
||||
if (!TestActive.get() && !TestLogic.startTest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -622,7 +623,7 @@ function handleTab(event) {
|
|||
}
|
||||
event.preventDefault();
|
||||
if (
|
||||
TestLogic.active &&
|
||||
TestActive.get() &&
|
||||
Config.repeatQuotes === "typing" &&
|
||||
Config.mode === "quote"
|
||||
) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import * as SignOutButton from "../account/sign-out-button";
|
|||
import axiosInstance from "../axios-instance";
|
||||
import * as TodayTracker from "./../test/today-tracker";
|
||||
import * as ActivePage from "../states/active-page";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
let filterDebug = false;
|
||||
//toggle filterdebug
|
||||
|
@ -224,7 +225,7 @@ export async function getDataAndInit() {
|
|||
AccountButton.loading(false);
|
||||
}
|
||||
if (Config.paceCaret === "pb" || Config.paceCaret === "average") {
|
||||
if (!TestLogic.active) {
|
||||
if (!TestActive.get()) {
|
||||
PaceCaret.init(true);
|
||||
}
|
||||
}
|
||||
|
|
9
frontend/src/js/states/test-active.js
Normal file
9
frontend/src/js/states/test-active.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
let testActive = false;
|
||||
|
||||
export function get() {
|
||||
return testActive;
|
||||
}
|
||||
|
||||
export function set(active) {
|
||||
testActive = active;
|
||||
}
|
|
@ -2,6 +2,7 @@ import * as Misc from "../misc";
|
|||
import Config from "../config";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as SlowTimer from "../states/slow-timer";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
export let caretAnimating = true;
|
||||
|
||||
|
@ -112,7 +113,7 @@ export async function updatePosition() {
|
|||
if (
|
||||
newTop >= middlePos &&
|
||||
contentHeight > browserHeight &&
|
||||
TestLogic.active
|
||||
TestActive.get()
|
||||
) {
|
||||
let newscrolltop = newTop - middlePos / 2;
|
||||
// console.log('---------');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Config, * as UpdateConfig from "../config";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
export function update(acc) {
|
||||
let number = Math.floor(acc);
|
||||
|
@ -12,7 +12,7 @@ export function update(acc) {
|
|||
|
||||
export function show() {
|
||||
if (!Config.showLiveAcc) return;
|
||||
if (!TestLogic.active) return;
|
||||
if (!TestActive.get()) return;
|
||||
if (Config.timerStyle === "mini") {
|
||||
// $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity);
|
||||
if (!$("#miniTimerAndLiveWpm .acc").hasClass("hidden")) return;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Config, * as UpdateConfig from "../config";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
export function update(burst) {
|
||||
let number = burst;
|
||||
|
@ -12,7 +12,7 @@ export function update(burst) {
|
|||
|
||||
export function show() {
|
||||
if (!Config.showLiveBurst) return;
|
||||
if (!TestLogic.active) return;
|
||||
if (!TestActive.get()) return;
|
||||
if (Config.timerStyle === "mini") {
|
||||
if (!$("#miniTimerAndLiveWpm .burst").hasClass("hidden")) return;
|
||||
$("#miniTimerAndLiveWpm .burst")
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import Config, * as UpdateConfig from "../config";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
let liveWpmElement = document.querySelector("#liveWpm");
|
||||
let miniLiveWpmElement = document.querySelector("#miniTimerAndLiveWpm .wpm");
|
||||
|
||||
export function update(wpm, raw) {
|
||||
// if (!TestLogic.active || !Config.showLiveWpm) {
|
||||
// if (!TestActive.get() || !Config.showLiveWpm) {
|
||||
// hideLiveWpm();
|
||||
// } else {
|
||||
// showLiveWpm();
|
||||
|
@ -23,7 +23,7 @@ export function update(wpm, raw) {
|
|||
|
||||
export function show() {
|
||||
if (!Config.showLiveWpm) return;
|
||||
if (!TestLogic.active) return;
|
||||
if (!TestActive.get()) return;
|
||||
if (Config.timerStyle === "mini") {
|
||||
// $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity);
|
||||
if (!$("#miniTimerAndLiveWpm .wpm").hasClass("hidden")) return;
|
||||
|
|
|
@ -2,8 +2,9 @@ import * as TestLogic from "./test-logic";
|
|||
import * as TestUI from "./test-ui";
|
||||
import Config, * as UpdateConfig from "../config";
|
||||
import * as DB from "../db";
|
||||
import * as SlowTimer from "../states/slow-timer";
|
||||
import * as SlowTimer from "./../states/slow-timer";
|
||||
import * as Misc from "./../misc";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
export let settings = null;
|
||||
|
||||
|
@ -86,7 +87,7 @@ export async function init() {
|
|||
}
|
||||
|
||||
export function update(expectedStepEnd) {
|
||||
if (settings === null || !TestLogic.active || TestUI.resultVisible) {
|
||||
if (settings === null || !TestActive.get() || TestUI.resultVisible) {
|
||||
return;
|
||||
}
|
||||
if ($("#paceCaret").hasClass("hidden")) {
|
||||
|
|
|
@ -39,6 +39,7 @@ import * as LazyMode from "./lazy-mode";
|
|||
import * as Result from "./result";
|
||||
import * as MonkeyPower from "./../elements/monkey-power";
|
||||
import * as ActivePage from "../states/active-page";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
const objecthash = require("node-object-hash")().hash;
|
||||
|
||||
|
@ -220,7 +221,6 @@ class Corrected {
|
|||
}
|
||||
}
|
||||
|
||||
export let active = false;
|
||||
export let words = new Words();
|
||||
export let input = new Input();
|
||||
export let corrected = new Corrected();
|
||||
|
@ -232,10 +232,6 @@ export let hasTab = false;
|
|||
export let randomQuote = null;
|
||||
export let bailout = false;
|
||||
|
||||
export function setActive(tf) {
|
||||
active = tf;
|
||||
}
|
||||
|
||||
export function setRepeated(tf) {
|
||||
isRepeated = tf;
|
||||
}
|
||||
|
@ -432,7 +428,7 @@ export function startTest() {
|
|||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
setActive(true);
|
||||
TestActive.set(true);
|
||||
Replay.startReplayRecording();
|
||||
Replay.replayGetWordsList(words.list);
|
||||
TestStats.resetKeypressTimings();
|
||||
|
@ -501,7 +497,7 @@ export function restart(
|
|||
// }
|
||||
}
|
||||
}
|
||||
if (active) {
|
||||
if (TestActive.get()) {
|
||||
TestStats.pushKeypressesToHistory();
|
||||
let testSeconds = TestStats.calculateTestSeconds(performance.now());
|
||||
let afkseconds = TestStats.calculateAfkSeconds(testSeconds);
|
||||
|
@ -551,7 +547,7 @@ export function restart(
|
|||
corrected.reset();
|
||||
ShiftTracker.reset();
|
||||
Caret.hide();
|
||||
setActive(false);
|
||||
TestActive.set(false);
|
||||
Replay.stopReplayRecording();
|
||||
LiveWpm.hide();
|
||||
LiveAcc.hide();
|
||||
|
@ -635,7 +631,7 @@ export function restart(
|
|||
} else {
|
||||
setRepeated(true);
|
||||
setPaceRepeat(repeatWithPace);
|
||||
setActive(false);
|
||||
TestActive.set(false);
|
||||
Replay.stopReplayRecording();
|
||||
words.resetCurrentIndex();
|
||||
input.reset();
|
||||
|
@ -840,7 +836,7 @@ async function getNextWord(wordset, language, wordsBound) {
|
|||
}
|
||||
|
||||
export async function init() {
|
||||
setActive(false);
|
||||
TestActive.set(false);
|
||||
MonkeyPower.reset();
|
||||
Replay.stopReplayRecording();
|
||||
words.reset();
|
||||
|
@ -1497,7 +1493,7 @@ function buildCompletedEvent(difficultyFailed) {
|
|||
}
|
||||
|
||||
export async function finish(difficultyFailed = false) {
|
||||
if (!active) return;
|
||||
if (!TestActive.get()) return;
|
||||
if (Config.mode == "zen" && input.current.length != 0) {
|
||||
input.pushHistory();
|
||||
corrected.pushHistory();
|
||||
|
@ -1509,7 +1505,7 @@ export async function finish(difficultyFailed = false) {
|
|||
TestUI.setResultCalculating(true);
|
||||
TestUI.setResultVisible(true);
|
||||
TestStats.setEnd(performance.now());
|
||||
setActive(false);
|
||||
TestActive.set(false);
|
||||
Replay.stopReplayRecording();
|
||||
Focus.set(false);
|
||||
Caret.hide();
|
||||
|
|
|
@ -12,6 +12,7 @@ import * as Notifications from "../elements/notifications";
|
|||
import * as TestLogic from "./test-logic";
|
||||
import * as Caret from "./caret";
|
||||
import * as SlowTimer from "../states/slow-timer";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
let slowTimerCount = 0;
|
||||
export let time = 0;
|
||||
|
@ -225,7 +226,7 @@ export async function start() {
|
|||
timer = setTimeout(function () {
|
||||
// time++;
|
||||
|
||||
if (!TestLogic.active) {
|
||||
if (!TestActive.get()) {
|
||||
clearTimeout(timer);
|
||||
SlowTimer.clear();
|
||||
slowTimerCount = 0;
|
||||
|
|
|
@ -21,6 +21,7 @@ import * as QuoteRatePopup from "../popups/quote-rate-popup";
|
|||
import * as UI from "../ui";
|
||||
import * as SlowTimer from "../states/slow-timer";
|
||||
import * as ReportQuotePopup from "../popups/quote-report-popup";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
$(document).ready(() => {
|
||||
UpdateConfig.subscribeToEvent((eventKey, eventValue) => {
|
||||
|
@ -1115,7 +1116,7 @@ $(document).on("keypress", "#restartTestButton", (event) => {
|
|||
if (event.key == "Enter") {
|
||||
ManualRestart.reset();
|
||||
if (
|
||||
TestLogic.active &&
|
||||
TestActive.get() &&
|
||||
Config.repeatQuotes === "typing" &&
|
||||
Config.mode === "quote"
|
||||
) {
|
||||
|
@ -1130,7 +1131,7 @@ $(document.body).on("click", "#restartTestButton", () => {
|
|||
ManualRestart.set();
|
||||
if (resultCalculating) return;
|
||||
if (
|
||||
TestLogic.active &&
|
||||
TestActive.get() &&
|
||||
Config.repeatQuotes === "typing" &&
|
||||
Config.mode === "quote"
|
||||
) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as Misc from "../misc";
|
|||
import * as TestLogic from "./test-logic";
|
||||
import * as TestTimer from "./test-timer";
|
||||
import * as SlowTimer from "../states/slow-timer";
|
||||
import * as TestActive from "./../states/test-active";
|
||||
|
||||
export function show() {
|
||||
let op = Config.showTimerProgress ? Config.timerOpacity : 0;
|
||||
|
@ -182,7 +183,7 @@ export function update() {
|
|||
}
|
||||
|
||||
export function updateStyle() {
|
||||
if (!TestLogic.active) return;
|
||||
if (!TestActive.get()) return;
|
||||
hide();
|
||||
update();
|
||||
setTimeout(() => {
|
||||
|
@ -193,7 +194,7 @@ export function updateStyle() {
|
|||
$(document).ready(() => {
|
||||
UpdateConfig.subscribeToEvent((eventKey, eventValue) => {
|
||||
if (eventKey === "showTimerProgress") {
|
||||
if (eventValue === true && TestLogic.active) {
|
||||
if (eventValue === true && TestActive.get()) {
|
||||
show();
|
||||
} else {
|
||||
hide();
|
||||
|
|
|
@ -17,6 +17,7 @@ import * as Funbox from "./test/funbox";
|
|||
import * as About from "./pages/about";
|
||||
import * as Misc from "./misc";
|
||||
import * as ActivePage from "./states/active-page";
|
||||
import * as TestActive from "./states/test-active";
|
||||
|
||||
export let pageTransition = true;
|
||||
|
||||
|
@ -244,7 +245,7 @@ window.addEventListener("beforeunload", (event) => {
|
|||
) {
|
||||
//ignore
|
||||
} else {
|
||||
if (TestLogic.active) {
|
||||
if (TestActive.get()) {
|
||||
event.preventDefault();
|
||||
// Chrome requires returnValue to be set.
|
||||
event.returnValue = "";
|
||||
|
|
Loading…
Add table
Reference in a new issue