feat: focus back on passcode input after failure

This commit is contained in:
Baptiste Grob
2021-04-16 12:20:24 +02:00
parent 465a6b55a0
commit 729a1a8dfd
2 changed files with 18 additions and 11 deletions

View File

@@ -88,6 +88,8 @@ class AccountMenuCtrl extends PureViewCtrl<unknown, AccountMenuState> {
private removeSyncObserver?: IReactionDisposer; private removeSyncObserver?: IReactionDisposer;
private removeProtectionLengthObserver?: () => void; private removeProtectionLengthObserver?: () => void;
public passcodeInput!: JQLite;
/* @ngInject */ /* @ngInject */
constructor($timeout: ng.ITimeoutService, appVersion: string) { constructor($timeout: ng.ITimeoutService, appVersion: string) {
super($timeout); super($timeout);
@@ -148,7 +150,7 @@ class AccountMenuCtrl extends PureViewCtrl<unknown, AccountMenuState> {
async $onInit() { async $onInit() {
super.$onInit(); super.$onInit();
this.setState({ this.setState({
showSessions: await this.application.userCanManageSessions() showSessions: await this.application.userCanManageSessions(),
}); });
const sync = this.appState.sync; const sync = this.appState.sync;
@@ -516,17 +518,21 @@ class AccountMenuCtrl extends PureViewCtrl<unknown, AccountMenuState> {
async submitPasscodeForm() { async submitPasscodeForm() {
const passcode = this.getState().formData.passcode!; const passcode = this.getState().formData.passcode!;
if (passcode !== this.getState().formData.confirmPasscode!) { if (passcode !== this.getState().formData.confirmPasscode!) {
this.application!.alertService!.alert(STRING_NON_MATCHING_PASSCODES); await alertDialog({
text: STRING_NON_MATCHING_PASSCODES,
});
this.passcodeInput[0].focus();
return; return;
} }
await preventRefreshing( await preventRefreshing(
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE, STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE,
async () => { async () => {
if (this.application!.hasPasscode()) { const successful = this.application.hasPasscode()
await this.application!.changePasscode(passcode); ? await this.application.changePasscode(passcode)
} else { : await this.application.addPasscode(passcode);
await this.application!.addPasscode(passcode); if (!successful) {
this.passcodeInput[0].focus();
} }
} }
); );

View File

@@ -200,12 +200,13 @@
) )
.sk-panel-row .sk-panel-row
input.sk-input.contrast( input.sk-input.contrast(
ng-model='self.state.formData.passcode', ng-ref='self.passcodeInput'
placeholder='Passcode', ng-model='self.state.formData.passcode'
should-focus='true', placeholder='Passcode'
sn-autofocus='true', should-focus='true'
sn-autofocus='true'
type='password' type='password'
) )
input.sk-input.contrast( input.sk-input.contrast(
ng-model='self.state.formData.confirmPasscode', ng-model='self.state.formData.confirmPasscode',
placeholder='Confirm Passcode', placeholder='Confirm Passcode',