fixed 1 circular dependency

part of #2462
This commit is contained in:
Miodec 2022-02-11 19:42:30 +01:00
parent 66194e6220
commit baf45b00bd
2 changed files with 22 additions and 15 deletions

View file

@ -2,7 +2,6 @@ import * as Misc from "../misc";
import * as Notifications from "../elements/notifications";
import Config, * as UpdateConfig from "../config";
import * as ManualRestart from "../test/manual-restart-tracker";
import * as TestLogic from "../test/test-logic";
import * as QuoteSubmitPopup from "./quote-submit-popup";
import * as QuoteApprovePopup from "./quote-approve-popup";
import * as QuoteReportPopup from "./quote-report-popup";
@ -11,6 +10,10 @@ import * as TestUI from "../test/test-ui";
export let selectedId = 1;
export function setSelectedId(val) {
selectedId = val;
}
async function updateResults(searchText) {
let quotes = await Misc.getQuotes(Config.language);
let reg = new RegExp(searchText, "i");
@ -135,19 +138,22 @@ export function hide(noAnim = false, focusWords = true) {
}
}
function apply(val) {
export function apply(val) {
if (isNaN(val)) {
val = document.getElementById("searchBox").value;
}
let ret;
if (val !== null && !isNaN(val) && val >= 0) {
UpdateConfig.setQuoteLength(-2, false);
selectedId = val;
ManualRestart.set();
TestLogic.restart();
ret = true;
} else {
Notifications.add("Quote ID must be at least 1", 0);
ret = false;
}
hide();
return ret;
}
$("#quoteSearchPopup .searchBox").keydown((e) => {
@ -168,18 +174,6 @@ $("#quoteSearchPopupWrapper").click((e) => {
}
});
$(document).on(
"click",
"#quoteSearchPopup #quoteSearchResults .searchResult",
(e) => {
if (e.target.classList.contains("report")) {
return;
}
selectedId = parseInt($(e.currentTarget).attr("id"));
apply(selectedId);
}
);
$(document).on("click", "#quoteSearchPopup #gotoSubmitQuoteButton", (e) => {
hide(true);
QuoteSubmitPopup.show(true);

View file

@ -1667,6 +1667,19 @@ $("#practiseWordsPopup .button.both").click(() => {
restart(false, false, false, true);
});
$(document).on(
"click",
"#quoteSearchPopup #quoteSearchResults .searchResult",
(e) => {
if (e.target.classList.contains("report")) {
return;
}
let sid = parseInt($(e.currentTarget).attr("id"));
QuoteSearchPopup.setSelectedId(sid);
if (QuoteSearchPopup.apply(sid) === true) restart();
}
);
ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
if (eventKey === "difficulty" && !nosave) restart(false, nosave);
if (eventKey === "showAllLines" && !nosave) restart();