Skip to content

Commit 3f72e31

Browse files
committed
fix(test config): sometimes showing too many elements at once
1 parent 7519931 commit 3f72e31

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

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

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function instantUpdate(): Promise<void> {
2323
);
2424

2525
$("#testConfig .puncAndNum").addClass("hidden");
26-
$("#testConfig .spacer").addClass("scrolled");
26+
$("#testConfig .spacer").css("transition", "none").addClass("scrolled");
2727
$("#testConfig .time").addClass("hidden");
2828
$("#testConfig .wordCount").addClass("hidden");
2929
$("#testConfig .customText").addClass("hidden");
@@ -36,34 +36,49 @@ export async function instantUpdate(): Promise<void> {
3636
$("#testConfig .rightSpacer").removeClass("scrolled");
3737
$("#testConfig .time").removeClass("hidden");
3838

39-
updateExtras("time", Config.time);
39+
updateActiveExtraButtons("time", Config.time);
4040
} else if (Config.mode === "words") {
4141
$("#testConfig .puncAndNum").removeClass("hidden");
4242
$("#testConfig .leftSpacer").removeClass("scrolled");
4343
$("#testConfig .rightSpacer").removeClass("scrolled");
4444
$("#testConfig .wordCount").removeClass("hidden");
4545

46-
updateExtras("words", Config.words);
46+
updateActiveExtraButtons("words", Config.words);
4747
} else if (Config.mode === "quote") {
4848
$("#testConfig .rightSpacer").removeClass("scrolled");
4949
$("#testConfig .quoteLength").removeClass("hidden");
5050

51-
updateExtras("quoteLength", Config.quoteLength);
51+
updateActiveExtraButtons("quoteLength", Config.quoteLength);
5252
} else if (Config.mode === "custom") {
5353
$("#testConfig .puncAndNum").removeClass("hidden");
5454
$("#testConfig .leftSpacer").removeClass("scrolled");
5555
$("#testConfig .rightSpacer").removeClass("scrolled");
5656
$("#testConfig .customText").removeClass("hidden");
5757
}
5858

59-
updateExtras("numbers", Config.numbers);
60-
updateExtras("punctuation", Config.punctuation);
59+
updateActiveExtraButtons("numbers", Config.numbers);
60+
updateActiveExtraButtons("punctuation", Config.punctuation);
61+
62+
setTimeout(() => {
63+
$("#testConfig .spacer").css("transition", "");
64+
}, 125);
6165
}
6266

63-
export async function update(previous: Mode, current: Mode): Promise<void> {
67+
async function update(previous: Mode, current: Mode): Promise<void> {
6468
if (previous === current) return;
65-
$("#testConfig .mode .textButton").removeClass("active");
66-
$("#testConfig .mode .textButton[mode='" + current + "']").addClass("active");
69+
updateActiveModeButtons(current);
70+
71+
let m2;
72+
73+
if (Config.mode === "time") {
74+
m2 = Config.time;
75+
} else if (Config.mode === "words") {
76+
m2 = Config.words;
77+
} else if (Config.mode === "quote") {
78+
m2 = Config.quoteLength;
79+
}
80+
81+
if (m2 !== undefined) updateActiveExtraButtons(Config.mode, m2);
6782

6883
const submenu = {
6984
time: "time",
@@ -202,7 +217,12 @@ export async function update(previous: Mode, current: Mode): Promise<void> {
202217
);
203218
}
204219

205-
export function updateExtras(key: string, value: ConfigValue): void {
220+
function updateActiveModeButtons(mode: Mode): void {
221+
$("#testConfig .mode .textButton").removeClass("active");
222+
$("#testConfig .mode .textButton[mode='" + mode + "']").addClass("active");
223+
}
224+
225+
function updateActiveExtraButtons(key: string, value: ConfigValue): void {
206226
if (key === "time") {
207227
$("#testConfig .time .textButton").removeClass("active");
208228
const timeCustom = ![15, 30, 60, 120].includes(value as number)
@@ -258,27 +278,31 @@ export function hideFavoriteQuoteLength(): void {
258278
$("#testConfig .quoteLength .favorite").addClass("hidden");
259279
}
260280

281+
let ignoreConfigEvent = false;
282+
261283
ConfigEvent.subscribe((eventKey, eventValue, _nosave, eventPreviousValue) => {
262-
if (ActivePage.get() !== "test") return;
263-
if (eventKey === "mode") {
264-
void update(eventPreviousValue as Mode, eventValue as Mode);
284+
if (eventKey === "fullConfigChange") {
285+
ignoreConfigEvent = true;
286+
}
287+
if (eventKey === "fullConfigChangeFinished") {
288+
ignoreConfigEvent = false;
265289

266-
let m2;
290+
void instantUpdate();
291+
}
267292

268-
if (Config.mode === "time") {
269-
m2 = Config.time;
270-
} else if (Config.mode === "words") {
271-
m2 = Config.words;
272-
} else if (Config.mode === "quote") {
273-
m2 = Config.quoteLength;
274-
}
293+
// this is here to prevent calling set / preview multiple times during a full config loading
294+
// once the full config is loaded, we can apply everything once
295+
if (ignoreConfigEvent) return;
275296

276-
if (m2 !== undefined) updateExtras(Config.mode, m2);
297+
if (ActivePage.get() !== "test") return;
298+
if (eventKey === "mode") {
299+
void update(eventPreviousValue as Mode, eventValue as Mode);
277300
} else if (
278301
["time", "quoteLength", "words", "numbers", "punctuation"].includes(
279302
eventKey
280303
)
281304
) {
282-
if (eventValue !== undefined) updateExtras(eventKey, eventValue);
305+
if (eventValue !== undefined)
306+
updateActiveExtraButtons(eventKey, eventValue);
283307
}
284308
});

0 commit comments

Comments
 (0)