Skip to content

Commit

Permalink
refactor(animated modal): make setup async
Browse files Browse the repository at this point in the history
!nuf
  • Loading branch information
Miodec committed Mar 24, 2024
1 parent 5a6d2ec commit a8a78ec
Show file tree
Hide file tree
Showing 21 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions frontend/src/ts/commandline/commandline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ const modal = new AnimatedModal({
showOptionsWhenInChain: {
focusFirstInput: true,
},
setup: (modal): void => {
const input = modal.querySelector("input") as HTMLInputElement;
setup: async (modalEl): Promise<void> => {
const input = modalEl.querySelector("input") as HTMLInputElement;

input.addEventListener("input", async (e) => {
inputValue = (e.target as HTMLInputElement).value;
Expand Down Expand Up @@ -607,7 +607,7 @@ const modal = new AnimatedModal({
}
});

modal.addEventListener("mousemove", (e) => {
modalEl.addEventListener("mousemove", (e) => {
mouseMode = true;
});
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/elements/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ const modal = new AnimatedModal({
customWrapperClickHandler: (): void => {
hide();
},
setup: (): void => {
setup: async (): Promise<void> => {
$("#alertsPopup .accountAlerts").on("click", ".claimAll", () => {
for (const ie of accountAlerts) {
if (!ie.read && !mailToMarkRead.includes(ie.id)) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/custom-test-duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function apply(): void {
hide(true);
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
apply();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/custom-word-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function apply(): void {

const modal = new AnimatedModal({
dialogId: "customWordAmountModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
apply();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/edit-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async function apply(): Promise<void> {

const modal = new AnimatedModal({
dialogId: "editPresetModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
void apply();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/edit-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ async function updateProfile(): Promise<void> {

const modal = new AnimatedModal({
dialogId: "editProfileModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.addEventListener("submit", async (e) => {
e.preventDefault();
await updateProfile();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/edit-result-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function save(): Promise<void> {

const modal = new AnimatedModal({
dialogId: "editResultTagsModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl
.querySelector("button.saveButton")
?.addEventListener("click", (e) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/edit-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async function apply(): Promise<void> {

const modal = new AnimatedModal({
dialogId: "editTagModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
void apply();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/google-sign-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const checkNameDebounced = debounce(1000, async () => {
}
});

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
void apply();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/mobile-test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function hide(): void {
void modal.hide();
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
const wordsGroupButtons = modalEl.querySelectorAll(".wordsGroup button");
for (const button of wordsGroupButtons) {
button.addEventListener("click", (e) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/new-filter-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function apply(): void {
hide(true);
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
apply();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/quote-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async function editQuote(index: number, dbid: string): Promise<void> {
updateList();
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.querySelector("button.refreshList")?.addEventListener("click", () => {
$("#quoteApproveModal .quotes").empty();
void getQuotes();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/quote-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async function submit(): Promise<void> {
$(".pageTest #result #rateQuoteButton .icon").addClass("fas");
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.querySelector(".submitButton")?.addEventListener("click", () => {
void submit();
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/quote-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function submitReport(): Promise<void> {
void hide(true);
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.querySelector(".comment")?.addEventListener("input", () => {
const len = ($("#quoteReportModal .comment").val() as string).length;
$("#quoteReportModal .characterCount").text(len);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/quote-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async function toggleFavoriteForQuote(quoteId: string): Promise<void> {
}
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.querySelector(".searchBox")?.addEventListener("input", (e) => {
searchForQuotes();
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/quote-submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function hide(clearModalChain: boolean): void {
});
}

function setup(modalEl: HTMLElement): void {
async function setup(modalEl: HTMLElement): Promise<void> {
modalEl.querySelector("textarea")?.addEventListener("input", (e) => {
const len = (e.target as HTMLTextAreaElement).value.length;
$("#quoteSubmitModal .characterCount").text(len);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/ts/modals/share-custom-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ async function copy(): Promise<void> {

const modal = new AnimatedModal({
dialogId: "shareCustomThemeModal",
setup: (modal): void => {
modal.querySelector("button")?.addEventListener("click", copy);
modal
setup: async (modalEl): Promise<void> => {
modalEl.querySelector("button")?.addEventListener("click", copy);
modalEl
.querySelector("input[type='checkbox']")
?.addEventListener("change", (e) => {
state.includeBackground = (e.target as HTMLInputElement).checked;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/streak-hour-offset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function apply(): Promise<void> {

const modal = new AnimatedModal({
dialogId: "streakHourOffsetModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.querySelector("input")?.addEventListener("input", () => {
updatePreview();
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function show(): void {

const modal = new AnimatedModal({
dialogId: "supportModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.querySelector("button.ads")?.addEventListener("click", async () => {
const commandline = await getCommandline();
commandline.show(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/popups/simple-popups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type SimplePopupOptions = {

const modal = new AnimatedModal({
dialogId: "simpleModal",
setup: (modalEl): void => {
setup: async (modalEl): Promise<void> => {
modalEl.addEventListener("submit", (e) => {
e.preventDefault();
activePopup?.exec();
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/ts/utils/animated-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ConstructorParams = {
showOptionsWhenInChain?: ShowOptions;
customEscapeHandler?: (e: KeyboardEvent) => void;
customWrapperClickHandler?: (e: MouseEvent) => void;
setup?: (modal: HTMLElement) => void;
setup?: (modal: HTMLElement) => Promise<void>;
};

const DEFAULT_ANIMATION_DURATION = 125;
Expand All @@ -63,7 +63,7 @@ export default class AnimatedModal {

private customEscapeHandler: ((e: KeyboardEvent) => void) | undefined;
private customWrapperClickHandler: ((e: MouseEvent) => void) | undefined;
private setup: ((modal: HTMLElement) => void) | undefined;
private setup: ((modal: HTMLElement) => Promise<void>) | undefined;

constructor(constructorParams: ConstructorParams) {
if (constructorParams.dialogId.startsWith("#")) {
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class AnimatedModal {
Skeleton.save(this.dialogId);
}

runSetup(): void {
async runSetup(): Promise<void> {
this.wrapperEl.addEventListener("keydown", (e) => {
if (e.key === "Escape" && isPopupVisible(this.dialogId)) {
if (this.customEscapeHandler !== undefined) {
Expand All @@ -140,7 +140,7 @@ export default class AnimatedModal {
});

if (this.setup !== undefined) {
this.setup(this.modalEl);
await this.setup(this.modalEl);
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ export default class AnimatedModal {
Skeleton.append(this.dialogId, this.skeletonAppendParent);

if (!this.setupRan) {
this.runSetup();
await this.runSetup();
this.setupRan = true;
}

Expand Down

0 comments on commit a8a78ec

Please sign in to comment.