Skip to content

Commit

Permalink
feat: focus back on passcode input after failure
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Apr 16, 2021
1 parent 465a6b5 commit 729a1a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
18 changes: 12 additions & 6 deletions app/assets/javascripts/directives/views/accountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class AccountMenuCtrl extends PureViewCtrl<unknown, AccountMenuState> {
private removeSyncObserver?: IReactionDisposer;
private removeProtectionLengthObserver?: () => void;

public passcodeInput!: JQLite;

/* @ngInject */
constructor($timeout: ng.ITimeoutService, appVersion: string) {
super($timeout);
Expand Down Expand Up @@ -148,7 +150,7 @@ class AccountMenuCtrl extends PureViewCtrl<unknown, AccountMenuState> {
async $onInit() {
super.$onInit();
this.setState({
showSessions: await this.application.userCanManageSessions()
showSessions: await this.application.userCanManageSessions(),
});

const sync = this.appState.sync;
Expand Down Expand Up @@ -516,17 +518,21 @@ class AccountMenuCtrl extends PureViewCtrl<unknown, AccountMenuState> {
async submitPasscodeForm() {
const passcode = this.getState().formData.passcode!;
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;
}

await preventRefreshing(
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE,
async () => {
if (this.application!.hasPasscode()) {
await this.application!.changePasscode(passcode);
} else {
await this.application!.addPasscode(passcode);
const successful = this.application.hasPasscode()
? await this.application.changePasscode(passcode)
: await this.application.addPasscode(passcode);
if (!successful) {
this.passcodeInput[0].focus();
}
}
);
Expand Down
11 changes: 6 additions & 5 deletions app/assets/templates/directives/account-menu.pug
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@
)
.sk-panel-row
input.sk-input.contrast(
ng-model='self.state.formData.passcode',
placeholder='Passcode',
should-focus='true',
sn-autofocus='true',
ng-ref='self.passcodeInput'
ng-model='self.state.formData.passcode'
placeholder='Passcode'
should-focus='true'
sn-autofocus='true'
type='password'
)
)
input.sk-input.contrast(
ng-model='self.state.formData.confirmPasscode',
placeholder='Confirm Passcode',
Expand Down

0 comments on commit 729a1a8

Please sign in to comment.