Skip to content

Commit

Permalink
fix holding enter spam
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLolz committed Jan 23, 2025
1 parent 14614eb commit f52e69b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
40 changes: 21 additions & 19 deletions src/ui/login-form-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,29 @@ export default class LoginFormUiHandler extends FormModalUiHandler {
this.processExternalProvider(config);
const originalLoginAction = this.submitAction;
this.submitAction = (_) => {
// Prevent overlapping overrides on action modification
this.submitAction = originalLoginAction;
this.sanitizeInputs();
globalScene.ui.setMode(Mode.LOADING, { buttonActions: []});
const onFail = error => {
globalScene.ui.setMode(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError();
};
if (!this.inputs[0].text) {
return onFail(i18next.t("menu:emptyUsername"));
}
if (globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
// Prevent overlapping overrides on action modification
this.submitAction = originalLoginAction;
this.sanitizeInputs();
globalScene.ui.setMode(Mode.LOADING, { buttonActions: []});
const onFail = error => {
globalScene.ui.setMode(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError();
};
if (!this.inputs[0].text) {
return onFail(i18next.t("menu:emptyUsername"));
}

const [ usernameInput, passwordInput ] = this.inputs;
const [ usernameInput, passwordInput ] = this.inputs;

pokerogueApi.account.login({ username: usernameInput.text, password: passwordInput.text }).then(error => {
if (!error) {
originalLoginAction && originalLoginAction();
} else {
onFail(error);
}
});
pokerogueApi.account.login({ username: usernameInput.text, password: passwordInput.text }).then(error => {
if (!error) {
originalLoginAction && originalLoginAction();
} else {
onFail(error);
}
});
}
};

return true;
Expand Down
72 changes: 37 additions & 35 deletions src/ui/registration-form-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,43 +91,45 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {

const originalRegistrationAction = this.submitAction;
this.submitAction = (_) => {
// Prevent overlapping overrides on action modification
this.submitAction = originalRegistrationAction;
this.sanitizeInputs();
globalScene.ui.setMode(Mode.LOADING, { buttonActions: []});
const onFail = error => {
globalScene.ui.setMode(Mode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError();
const errorMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.errorMessageFontSize;
if (errorMessageFontSize) {
this.errorMessage.setFontSize(errorMessageFontSize);
if (globalScene.tweens.getTweensOf(this.modalContainer).length === 0) {
// Prevent overlapping overrides on action modification
this.submitAction = originalRegistrationAction;
this.sanitizeInputs();
globalScene.ui.setMode(Mode.LOADING, { buttonActions: []});
const onFail = error => {
globalScene.ui.setMode(Mode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError();
const errorMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.errorMessageFontSize;
if (errorMessageFontSize) {
this.errorMessage.setFontSize(errorMessageFontSize);
}
};
if (!this.inputs[0].text) {
return onFail(i18next.t("menu:emptyUsername"));
}
};
if (!this.inputs[0].text) {
return onFail(i18next.t("menu:emptyUsername"));
}
if (!this.inputs[1].text) {
return onFail(this.getReadableErrorMessage("invalid password"));
}
if (this.inputs[1].text !== this.inputs[2].text) {
return onFail(i18next.t("menu:passwordNotMatchingConfirmPassword"));
if (!this.inputs[1].text) {
return onFail(this.getReadableErrorMessage("invalid password"));
}
if (this.inputs[1].text !== this.inputs[2].text) {
return onFail(i18next.t("menu:passwordNotMatchingConfirmPassword"));
}
const [ usernameInput, passwordInput ] = this.inputs;
pokerogueApi.account.register({ username: usernameInput.text, password: passwordInput.text })
.then(registerError => {
if (!registerError) {
pokerogueApi.account.login({ username: usernameInput.text, password: passwordInput.text })
.then(loginError => {
if (!loginError) {
originalRegistrationAction && originalRegistrationAction();
} else {
onFail(loginError);
}
});
} else {
onFail(registerError);
}
});
}
const [ usernameInput, passwordInput ] = this.inputs;
pokerogueApi.account.register({ username: usernameInput.text, password: passwordInput.text })
.then(registerError => {
if (!registerError) {
pokerogueApi.account.login({ username: usernameInput.text, password: passwordInput.text })
.then(loginError => {
if (!loginError) {
originalRegistrationAction && originalRegistrationAction();
} else {
onFail(loginError);
}
});
} else {
onFail(registerError);
}
});
};

return true;
Expand Down

0 comments on commit f52e69b

Please sign in to comment.