mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-09-28 09:36:40 +08:00
refactor(test): extract selected quote id to the test state module
This commit is contained in:
parent
b4259b7b4d
commit
ecfbe3a290
5 changed files with 13 additions and 14 deletions
|
@ -20,15 +20,10 @@ import * as Loader from "../elements/loader";
|
|||
import * as Skeleton from "../utils/skeleton";
|
||||
import { isPopupVisible } from "../utils/misc";
|
||||
import SlimSelect from "slim-select";
|
||||
import * as TestState from "../test/test-state";
|
||||
|
||||
const wrapperId = "quoteSearchPopupWrapper";
|
||||
|
||||
export let selectedId = 1;
|
||||
|
||||
export function setSelectedId(val: number): void {
|
||||
selectedId = val;
|
||||
}
|
||||
|
||||
const searchServiceCache: Record<string, SearchService<MonkeyTypes.Quote>> = {};
|
||||
|
||||
const pageSize = 100;
|
||||
|
@ -298,7 +293,6 @@ function hide(noAnim = false, focusWords = true): void {
|
|||
if (focusWords) {
|
||||
TestUI.focusWords();
|
||||
$("#quoteSearchPopup .quoteLengthFilter").val([]);
|
||||
$("#quoteSearchPopup .quoteLengthFilter").trigger("change");
|
||||
Skeleton.remove(wrapperId);
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +309,7 @@ export function apply(val: number): boolean {
|
|||
let ret;
|
||||
if (val !== null && !isNaN(val) && val >= 0) {
|
||||
UpdateConfig.setQuoteLength(-2 as SharedTypes.Config.QuoteLength, false);
|
||||
selectedId = val;
|
||||
TestState.setSelectedQuoteId(val);
|
||||
ManualRestart.set();
|
||||
ret = true;
|
||||
} else {
|
||||
|
|
|
@ -1457,7 +1457,7 @@ $("#popups").on(
|
|||
return;
|
||||
}
|
||||
const sid = parseInt($(e.currentTarget).attr("id") ?? "");
|
||||
QuoteSearchPopup.setSelectedId(sid);
|
||||
TestState.setSelectedQuoteId(sid);
|
||||
if (QuoteSearchPopup.apply(sid)) restart();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -4,6 +4,7 @@ export let isActive = false;
|
|||
export let activeChallenge: null | MonkeyTypes.Challenge = null;
|
||||
export let savingEnabled = true;
|
||||
export let bailedOut = false;
|
||||
export let selectedQuoteId = 1;
|
||||
|
||||
export function setRepeated(tf: boolean): void {
|
||||
isRepeated = tf;
|
||||
|
@ -28,3 +29,7 @@ export function setSaving(val: boolean): void {
|
|||
export function setBailedOut(tf: boolean): void {
|
||||
bailedOut = tf;
|
||||
}
|
||||
|
||||
export function setSelectedQuoteId(id: number): void {
|
||||
selectedQuoteId = id;
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ import * as FunboxList from "./funbox/funbox-list";
|
|||
import * as CustomText from "./custom-text";
|
||||
import * as Wordset from "./wordset";
|
||||
import QuotesController from "../controllers/quotes-controller";
|
||||
import * as QuoteSearchPopup from "../popups/quote-search-popup";
|
||||
import * as TestWords from "./test-words";
|
||||
import * as BritishEnglish from "./british-english";
|
||||
import * as LazyMode from "./lazy-mode";
|
||||
import * as EnglishPunctuation from "./english-punctuation";
|
||||
import * as PractiseWords from "./practise-words";
|
||||
import * as Misc from "../utils/misc";
|
||||
import * as TestState from "../test/test-state";
|
||||
|
||||
function shouldCapitalize(lastChar: string): boolean {
|
||||
return /[?!.؟]/.test(lastChar);
|
||||
|
@ -576,12 +576,12 @@ async function generateQuoteWords(
|
|||
let rq: MonkeyTypes.Quote;
|
||||
if (Config.quoteLength.includes(-2) && Config.quoteLength.length === 1) {
|
||||
const targetQuote = QuotesController.getQuoteById(
|
||||
QuoteSearchPopup.selectedId
|
||||
TestState.selectedQuoteId
|
||||
);
|
||||
if (targetQuote === undefined) {
|
||||
UpdateConfig.setQuoteLength(-1);
|
||||
throw new WordGenError(
|
||||
`Quote ${QuoteSearchPopup.selectedId} does not exist`
|
||||
`Quote ${TestState.selectedQuoteId} does not exist`
|
||||
);
|
||||
}
|
||||
rq = targetQuote;
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as Misc from "./misc";
|
|||
import Config, * as UpdateConfig from "../config";
|
||||
import * as Notifications from "../elements/notifications";
|
||||
import { decompressFromURI } from "lz-ts";
|
||||
import * as QuoteSearchPopup from "../popups/quote-search-popup";
|
||||
import * as TestState from "../test/test-state";
|
||||
import * as ManualRestart from "../test/manual-restart-tracker";
|
||||
import * as CustomText from "../test/custom-text";
|
||||
import Ape from "../ape";
|
||||
|
@ -138,7 +138,7 @@ export function loadTestSettingsFromUrl(getOverride?: string): void {
|
|||
UpdateConfig.setWordCount(parseInt(de[1], 10), true);
|
||||
} else if (Config.mode === "quote") {
|
||||
UpdateConfig.setQuoteLength(-2, false);
|
||||
QuoteSearchPopup.setSelectedId(parseInt(de[1], 10));
|
||||
TestState.setSelectedQuoteId(parseInt(de[1], 10));
|
||||
ManualRestart.set();
|
||||
}
|
||||
applied["mode2"] = de[1];
|
||||
|
|
Loading…
Add table
Reference in a new issue