Skip to content

Commit 9a046e2

Browse files
committed
wip
1 parent 660f8ab commit 9a046e2

File tree

6 files changed

+162
-181
lines changed

6 files changed

+162
-181
lines changed

frontend/src/ts/commandline/lists.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ export const commands: CommandsSubgroup = {
146146
id: "changeCustomModeText",
147147
display: "Change custom text",
148148
icon: "fa-align-left",
149-
exec: (): void => {
150-
CustomTextPopup.show();
149+
exec: async (): Promise<void> => {
150+
await CustomTextPopup.show();
151151
},
152152
},
153153
{

frontend/src/ts/event-handlers/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ $(".pageTest").on("click", "#testConfig .quoteLength .textButton", (e) => {
8181
}
8282
});
8383

84-
$(".pageTest").on("click", "#testConfig .customText .textButton", () => {
85-
CustomTextModal.show();
84+
$(".pageTest").on("click", "#testConfig .customText .textButton", async () => {
85+
await CustomTextModal.show();
8686
});
8787

8888
$(".pageTest").on("click", "#practiseWordsButton", () => {

frontend/src/ts/modals/custom-text.ts

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ type State = {
3333
};
3434

3535
const state: State = {
36-
textarea: CustomText.getText().join(
37-
CustomText.getPipeDelimiter() ? "|" : " "
38-
),
36+
textarea: "",
3937
longCustomTextWarning: false,
4038
challengeWarning: false,
4139
customTextMode: "simple",
@@ -167,27 +165,29 @@ async function beforeAnimation(
167165
modalEl: HTMLElement,
168166
modalChainData?: IncomingData
169167
): Promise<void> {
170-
state.customTextMode = CustomText.getMode();
168+
const customText = await CustomText.getData();
169+
state.textarea = customText.text.join(customText.pipeDelimiter ? "|" : " ");
170+
state.customTextMode = customText.mode;
171171

172172
if (
173173
state.customTextMode === "repeat" &&
174-
CustomText.getLimitMode() === "word" &&
175-
CustomText.getLimitValue() === CustomText.getText().length
174+
customText.limit.mode === "word" &&
175+
customText.limit.value === customText.text.length
176176
) {
177177
state.customTextMode = "simple";
178178
}
179179

180180
state.customTextLimits.word = "";
181181
state.customTextLimits.time = "";
182182
state.customTextLimits.section = "";
183-
if (CustomText.getLimitMode() === "word") {
184-
state.customTextLimits.word = `${CustomText.getLimitValue()}`;
185-
} else if (CustomText.getLimitMode() === "time") {
186-
state.customTextLimits.time = `${CustomText.getLimitValue()}`;
187-
} else if (CustomText.getLimitMode() === "section") {
188-
state.customTextLimits.section = `${CustomText.getLimitValue()}`;
183+
if (customText.limit.mode === "word") {
184+
state.customTextLimits.word = `${customText.limit.value}`;
185+
} else if (customText.limit.mode === "time") {
186+
state.customTextLimits.time = `${customText.limit.value}`;
187+
} else if (customText.limit.mode === "section") {
188+
state.customTextLimits.section = `${customText.limit.value}`;
189189
}
190-
state.customTextPipeDelimiter = CustomText.getPipeDelimiter();
190+
state.customTextPipeDelimiter = customText.pipeDelimiter;
191191

192192
state.longCustomTextWarning = CustomTextState.isCustomTextLong() ?? false;
193193

@@ -220,9 +220,10 @@ async function afterAnimation(): Promise<void> {
220220
}
221221
}
222222

223-
export function show(showOptions?: ShowOptions): void {
224-
state.textarea = CustomText.getText()
225-
.join(CustomText.getPipeDelimiter() ? "|" : " ")
223+
export async function show(showOptions?: ShowOptions): Promise<void> {
224+
const customText = await CustomText.getData();
225+
state.textarea = customText.text
226+
.join(customText.pipeDelimiter ? "|" : " ")
226227
.replace(/^ +/gm, "");
227228
void modal.show({
228229
...(showOptions as ShowOptions<IncomingData>),
@@ -310,7 +311,7 @@ function cleanUpText(): string[] {
310311
return words;
311312
}
312313

313-
function apply(): void {
314+
async function apply(): Promise<void> {
314315
if (state.textarea === "") {
315316
Notifications.add("Text cannot be empty", 0);
316317
return;
@@ -363,29 +364,29 @@ function apply(): void {
363364
}
364365

365366
if (state.customTextMode === "simple") {
366-
CustomText.setMode("repeat");
367+
await CustomText.setMode("repeat");
367368
state.customTextLimits.word = `${text.length}`;
368369
state.customTextLimits.time = "";
369370
state.customTextLimits.section = "";
370371
} else {
371-
CustomText.setMode(state.customTextMode);
372+
await CustomText.setMode(state.customTextMode);
372373
}
373374

374-
CustomText.setPipeDelimiter(state.customTextPipeDelimiter);
375-
CustomText.setText(text);
375+
await CustomText.setPipeDelimiter(state.customTextPipeDelimiter);
376+
await CustomText.setText(text);
376377

377378
if (state.customTextMode === "simple" && state.customTextPipeDelimiter) {
378-
CustomText.setLimitMode("section");
379-
CustomText.setLimitValue(text.length);
379+
await CustomText.setLimitMode("section");
380+
await CustomText.setLimitValue(text.length);
380381
} else if (state.customTextLimits.word !== "") {
381-
CustomText.setLimitMode("word");
382-
CustomText.setLimitValue(parseInt(state.customTextLimits.word));
382+
await CustomText.setLimitMode("word");
383+
await CustomText.setLimitValue(parseInt(state.customTextLimits.word));
383384
} else if (state.customTextLimits.time !== "") {
384-
CustomText.setLimitMode("time");
385-
CustomText.setLimitValue(parseInt(state.customTextLimits.time));
385+
await CustomText.setLimitMode("time");
386+
await CustomText.setLimitValue(parseInt(state.customTextLimits.time));
386387
} else if (state.customTextLimits.section !== "") {
387-
CustomText.setLimitMode("section");
388-
CustomText.setLimitValue(parseInt(state.customTextLimits.section));
388+
await CustomText.setLimitMode("section");
389+
await CustomText.setLimitValue(parseInt(state.customTextLimits.section));
389390
}
390391

391392
ChallengeController.clearActive();
@@ -554,9 +555,11 @@ async function setup(modalEl: HTMLElement): Promise<void> {
554555
});
555556
}
556557
});
557-
modalEl.querySelector(".button.apply")?.addEventListener("click", () => {
558-
apply();
559-
});
558+
modalEl
559+
.querySelector(".button.apply")
560+
?.addEventListener("click", async () => {
561+
await apply();
562+
});
560563
modalEl.querySelector(".button.wordfilter")?.addEventListener("click", () => {
561564
void WordFilterPopup.show({
562565
modalChain: modal as AnimatedModal<unknown, unknown>,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ async function setup(modalEl: HTMLElement): Promise<void> {
148148
});
149149
}
150150

151-
modalEl.querySelector(".customChange")?.addEventListener("click", () => {
152-
CustomTextPopup.show({
153-
modalChain: modal,
151+
modalEl
152+
.querySelector(".customChange")
153+
?.addEventListener("click", async () => {
154+
await CustomTextPopup.show({
155+
modalChain: modal,
156+
});
154157
});
155-
});
156158

157159
modalEl.querySelector(".punctuation")?.addEventListener("click", () => {
158160
UpdateConfig.setPunctuation(!Config.punctuation);

0 commit comments

Comments
 (0)