Skip to content

Commit 31585bd

Browse files
authored
fix(quote-mode): broken all selection and visual highlighting issues (@byseif21) (monkeytypegame#6818)
### Description * fixed UI click handler to consistently map "all" quote mode selection (all) to [0, 1, 2, 3] `setQuoteLengthAll();`. * fix the mobile model to highlight the all selection when length is [0, 1, 2, 3]. * fix quote length options were not visually highlighted when refreshing from other mode then back to quote mode.
1 parent 3f72e31 commit 31585bd

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

frontend/src/html/pages/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</div>
6161

6262
<div class="quoteLength">
63-
<button class="textButton" quotelength="-1">all</button>
63+
<button class="textButton" quotelength="all">all</button>
6464
<button class="textButton" quotelength="0">short</button>
6565
<button class="textButton" quotelength="1">medium</button>
6666
<button class="textButton" quotelength="2">long</button>

frontend/src/html/popups.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
<button data-words="custom">custom</button>
287287
</div>
288288
<div class="group quoteGroup hidden">
289-
<button data-quoteLength="-1">all</button>
289+
<button data-quoteLength="all">all</button>
290290
<button data-quoteLength="0">short</button>
291291
<button data-quoteLength="1">medium</button>
292292
<button data-quoteLength="2">long</button>

frontend/src/ts/modals/mobile-test-config.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as CustomTextPopup from "./custom-text";
88
import AnimatedModal from "../utils/animated-modal";
99
import { QuoteLength, QuoteLengthConfig } from "@monkeytype/schemas/configs";
1010
import { Mode } from "@monkeytype/schemas/shared";
11+
import { areUnsortedArraysEqual } from "../utils/arrays";
1112

1213
function update(): void {
1314
const el = $("#mobileTestConfigModal");
@@ -43,10 +44,14 @@ function update(): void {
4344
el.find(".punctuation").removeClass("disabled");
4445
el.find(".numbers").removeClass("disabled");
4546
} else if (Config.mode === "quote") {
46-
for (const ql of Config.quoteLength) {
47-
el.find(`.quoteGroup button[data-quoteLength='${ql}']`).addClass(
48-
"active"
49-
);
47+
if (areUnsortedArraysEqual(Config.quoteLength, [0, 1, 2, 3])) {
48+
el.find(`.quoteGroup button[data-quoteLength='all']`).addClass("active");
49+
} else {
50+
for (const ql of Config.quoteLength) {
51+
el.find(`.quoteGroup button[data-quoteLength='${ql}']`).addClass(
52+
"active"
53+
);
54+
}
5055
}
5156
el.find(".punctuation").addClass("disabled");
5257
el.find(".numbers").addClass("disabled");
@@ -126,16 +131,19 @@ async function setup(modalEl: HTMLElement): Promise<void> {
126131
for (const button of quoteGroupButtons) {
127132
button.addEventListener("click", (e) => {
128133
const target = e.currentTarget as HTMLElement;
129-
const len = parseInt(
130-
target.getAttribute("data-quoteLength") ?? "0",
131-
10
132-
) as QuoteLength;
134+
const lenAttr = target.getAttribute("data-quoteLength") ?? "0";
133135

134-
if (len === -2) {
136+
if (lenAttr === "all") {
137+
if (UpdateConfig.setQuoteLengthAll()) {
138+
ManualRestart.set();
139+
TestLogic.restart();
140+
}
141+
} else if (lenAttr === "-2") {
135142
void QuoteSearchModal.show({
136143
modalChain: modal,
137144
});
138145
} else {
146+
const len = parseInt(lenAttr, 10) as QuoteLength;
139147
let arr: QuoteLengthConfig = [];
140148

141149
if ((e as MouseEvent).shiftKey) {
@@ -144,9 +152,10 @@ async function setup(modalEl: HTMLElement): Promise<void> {
144152
arr = [len];
145153
}
146154

147-
UpdateConfig.setQuoteLength(arr, false);
148-
ManualRestart.set();
149-
TestLogic.restart();
155+
if (UpdateConfig.setQuoteLength(arr, false)) {
156+
ManualRestart.set();
157+
TestLogic.restart();
158+
}
150159
}
151160
});
152161
}

frontend/src/ts/test/test-config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export async function instantUpdate(): Promise<void> {
5656
$("#testConfig .customText").removeClass("hidden");
5757
}
5858

59+
updateActiveExtraButtons("quoteLength", Config.quoteLength);
5960
updateActiveExtraButtons("numbers", Config.numbers);
6061
updateActiveExtraButtons("punctuation", Config.punctuation);
6162

@@ -245,7 +246,7 @@ function updateActiveExtraButtons(key: string, value: ConfigValue): void {
245246
$("#testConfig .quoteLength .textButton").removeClass("active");
246247

247248
if (areUnsortedArraysEqual(value as QuoteLength[], [0, 1, 2, 3])) {
248-
$("#testConfig .quoteLength .textButton[quoteLength='-1']").addClass(
249+
$("#testConfig .quoteLength .textButton[quotelength='all']").addClass(
249250
"active"
250251
);
251252
} else {

frontend/src/ts/test/test-logic.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,22 +1470,28 @@ $(".pageTest").on("click", "#testConfig .time .textButton", (e) => {
14701470

14711471
$(".pageTest").on("click", "#testConfig .quoteLength .textButton", (e) => {
14721472
if (TestUI.testRestarting) return;
1473-
const len = parseInt(
1474-
$(e.currentTarget).attr("quoteLength") ?? "1"
1475-
) as QuoteLength;
1473+
const lenAttr = $(e.currentTarget).attr("quoteLength");
1474+
if (lenAttr === "all") {
1475+
if (UpdateConfig.setQuoteLengthAll()) {
1476+
ManualRestart.set();
1477+
restart();
1478+
}
1479+
} else {
1480+
const len = parseInt(lenAttr ?? "1") as QuoteLength;
14761481

1477-
if (len !== -2) {
1478-
let arr: QuoteLengthConfig = [];
1482+
if (len !== -2) {
1483+
let arr: QuoteLengthConfig = [];
14791484

1480-
if (e.shiftKey) {
1481-
arr = [...Config.quoteLength, len];
1482-
} else {
1483-
arr = [len];
1484-
}
1485+
if (e.shiftKey) {
1486+
arr = [...Config.quoteLength, len];
1487+
} else {
1488+
arr = [len];
1489+
}
14851490

1486-
if (UpdateConfig.setQuoteLength(arr, false)) {
1487-
ManualRestart.set();
1488-
restart();
1491+
if (UpdateConfig.setQuoteLength(arr, false)) {
1492+
ManualRestart.set();
1493+
restart();
1494+
}
14891495
}
14901496
}
14911497
});

0 commit comments

Comments
 (0)