mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-11 18:04:27 +08:00
refactor: remove jquery in modals/custom-generator
This commit is contained in:
parent
5d169e933a
commit
491e6ffcad
1 changed files with 30 additions and 11 deletions
|
|
@ -5,6 +5,7 @@ import AnimatedModal, {
|
|||
HideOptions,
|
||||
ShowOptions,
|
||||
} from "../utils/animated-modal";
|
||||
import { qs, qsr } from "../utils/dom";
|
||||
|
||||
type Preset = {
|
||||
display: string;
|
||||
|
|
@ -91,10 +92,15 @@ export async function show(showOptions?: ShowOptions): Promise<void> {
|
|||
}
|
||||
|
||||
function applyPreset(): void {
|
||||
const presetName = $("#customGeneratorModal .presetInput").val() as string;
|
||||
const presetName = qs<HTMLSelectElement>(
|
||||
"#customGeneratorModal .presetInput",
|
||||
)?.getValue();
|
||||
|
||||
if (presetName !== undefined && presetName !== "" && presets[presetName]) {
|
||||
const preset = presets[presetName];
|
||||
$("#customGeneratorModal .characterInput").val(preset.characters.join(" "));
|
||||
qsr<HTMLInputElement>("#customGeneratorModal .characterInput").setValue(
|
||||
preset.characters.join(" "),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,17 +111,30 @@ function hide(hideOptions?: HideOptions<OutgoingData>): void {
|
|||
}
|
||||
|
||||
function generateWords(): string[] {
|
||||
const characterInput = $(
|
||||
const characterInput = qs<HTMLInputElement>(
|
||||
"#customGeneratorModal .characterInput",
|
||||
).val() as string;
|
||||
const minLength =
|
||||
parseInt($("#customGeneratorModal .minLengthInput").val() as string) || 2;
|
||||
const maxLength =
|
||||
parseInt($("#customGeneratorModal .maxLengthInput").val() as string) || 5;
|
||||
const wordCount =
|
||||
parseInt($("#customGeneratorModal .wordCountInput").val() as string) || 100;
|
||||
)?.getValue();
|
||||
|
||||
if (!characterInput || characterInput.trim() === "") {
|
||||
const minLength =
|
||||
parseInt(
|
||||
qs<HTMLInputElement>(
|
||||
"#customGeneratorModal .minLengthInput",
|
||||
)?.getValue() as string,
|
||||
) || 2;
|
||||
const maxLength =
|
||||
parseInt(
|
||||
qs<HTMLInputElement>(
|
||||
"#customGeneratorModal .maxLengthInput",
|
||||
)?.getValue() as string,
|
||||
) || 5;
|
||||
const wordCount =
|
||||
parseInt(
|
||||
qs<HTMLInputElement>(
|
||||
"#customGeneratorModal .wordCountInput",
|
||||
)?.getValue() as string,
|
||||
) || 100;
|
||||
|
||||
if (characterInput === undefined || characterInput.trim() === "") {
|
||||
Notifications.add("Character set cannot be empty", 0);
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue