refactor: use button and form elements instead of classes

This commit is contained in:
Miodec 2023-11-22 15:02:23 +00:00
parent f2ef439dfd
commit ff80d6eea8
2 changed files with 14 additions and 11 deletions

View file

@ -24,12 +24,12 @@ const searchIndicator = new InputIndicator(
);
function disableInputs(): void {
$(".page.pageProfileSearch .search .button").addClass("disabled");
$(".page.pageProfileSearch .search button").addClass("disabled");
$(".page.pageProfileSearch .search input").attr("disabled", "disabled");
}
function enableInputs(): void {
$(".page.pageProfileSearch .search .button").removeClass("disabled");
$(".page.pageProfileSearch .search button").removeClass("disabled");
$(".page.pageProfileSearch .search input").removeAttr("disabled");
}
@ -39,6 +39,10 @@ function areInputsDisabled(): boolean {
);
}
function focusInput(): void {
$(".page.pageProfileSearch .search input").trigger("focus");
}
async function lookupProfile(): Promise<void> {
searchIndicator.hide();
const name = $(".page.pageProfileSearch .search input").val() as string;
@ -52,9 +56,11 @@ async function lookupProfile(): Promise<void> {
const response = await Ape.users.getProfileByName(name);
enableInputs();
if (response.status === 404) {
focusInput();
searchIndicator.show("notFound", "User not found");
return;
} else if (response.status !== 200) {
focusInput();
searchIndicator.show("error", `Error: ${response.message}`);
return;
}
@ -64,11 +70,8 @@ async function lookupProfile(): Promise<void> {
});
}
$(".page.pageProfileSearch .search input").on("keyup", (e) => {
if (e.key === "Enter" && !areInputsDisabled()) lookupProfile();
});
$(".page.pageProfileSearch .search .button").on("click", () => {
$(".page.pageProfileSearch form").on("submit", (e) => {
e.preventDefault();
if (areInputsDisabled()) return;
lookupProfile();
});

View file

@ -1,11 +1,11 @@
<div class="page pageProfileSearch hidden" id="pageProfileSearch">
<div class="search">
<form class="search">
<div class="title">Profile lookup</div>
<input class="username" type="text" placeholder="username" />
<div class="button">
<button type="submit">
<i class="fas fa-fw fa-chevron-right"></i>
</div>
</div>
</button>
</form>
</div>
<div class="page pageProfile hidden" id="pageProfile">