refactor: update to latest snjs
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
SNAlertService,
|
||||
platformFromString,
|
||||
Challenge,
|
||||
ChallengeOrchestrator,
|
||||
ProtectedAction
|
||||
} from 'snjs';
|
||||
import angular from 'angular';
|
||||
@@ -160,14 +159,13 @@ export class WebApplication extends SNApplication {
|
||||
angular.element(document.body).append(el);
|
||||
}
|
||||
|
||||
promptForChallenge(challenge: Challenge, orchestrator: ChallengeOrchestrator) {
|
||||
promptForChallenge(challenge: Challenge) {
|
||||
const scope: any = this.scope!.$new(true);
|
||||
scope.challenge = challenge;
|
||||
scope.orchestrator = orchestrator;
|
||||
scope.application = this;
|
||||
const el = this.$compile!(
|
||||
"<challenge-modal " +
|
||||
"class='sk-modal' application='application' challenge='challenge' orchestrator='orchestrator'>" +
|
||||
"class='sk-modal' application='application' challenge='challenge'>" +
|
||||
"</challenge-modal>"
|
||||
)(scope);
|
||||
angular.element(document.body).append(el);
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
ChallengeValue,
|
||||
removeFromArray,
|
||||
Challenge,
|
||||
ChallengeOrchestrator
|
||||
} from 'snjs';
|
||||
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
|
||||
import { WebDirective } from '@/types';
|
||||
@@ -14,11 +13,6 @@ type InputValue = {
|
||||
value: string
|
||||
invalid: boolean
|
||||
}
|
||||
type ChallengeModalScope = {
|
||||
application: WebApplication
|
||||
challenge: Challenge
|
||||
orchestrator: ChallengeOrchestrator
|
||||
}
|
||||
|
||||
type Values = Record<ChallengeType, InputValue>
|
||||
|
||||
@@ -28,12 +22,11 @@ type ChallengeModalState = {
|
||||
processing: boolean
|
||||
}
|
||||
|
||||
class ChallengeModalCtrl extends PureViewCtrl implements ChallengeModalScope {
|
||||
class ChallengeModalCtrl extends PureViewCtrl {
|
||||
private $element: JQLite
|
||||
private processingTypes: ChallengeType[] = []
|
||||
application!: WebApplication
|
||||
challenge!: Challenge
|
||||
orchestrator!: ChallengeOrchestrator
|
||||
|
||||
/* @ngInject */
|
||||
constructor(
|
||||
@@ -63,26 +56,26 @@ class ChallengeModalCtrl extends PureViewCtrl implements ChallengeModalScope {
|
||||
values: values,
|
||||
processing: false
|
||||
});
|
||||
this.orchestrator.setCallbacks(
|
||||
(value) => {
|
||||
this.application.setChallengeCallbacks({
|
||||
challenge: this.challenge,
|
||||
onValidValue: (value) => {
|
||||
this.getState().values[value.type]!.invalid = false;
|
||||
removeFromArray(this.processingTypes, value.type);
|
||||
this.reloadProcessingStatus();
|
||||
},
|
||||
(value) => {
|
||||
onInvalidValue: (value) => {
|
||||
this.getState().values[value.type]!.invalid = true;
|
||||
removeFromArray(this.processingTypes, value.type);
|
||||
this.reloadProcessingStatus();
|
||||
},
|
||||
() => {
|
||||
onComplete: () => {
|
||||
this.dismiss();
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
deinit() {
|
||||
(this.application as any) = undefined;
|
||||
(this.orchestrator as any) = undefined;
|
||||
(this.challenge as any) = undefined;
|
||||
super.deinit();
|
||||
}
|
||||
@@ -141,7 +134,11 @@ class ChallengeModalCtrl extends PureViewCtrl implements ChallengeModalScope {
|
||||
values.push(value);
|
||||
}
|
||||
this.processingTypes = values.map((v) => v.type);
|
||||
this.orchestrator.submitValues(values);
|
||||
if (values.length > 0) {
|
||||
this.application.submitValuesForChallenge(this.challenge, values);
|
||||
} else {
|
||||
this.setState({ processing: false });
|
||||
}
|
||||
}
|
||||
|
||||
dismiss() {
|
||||
@@ -162,7 +159,6 @@ export class ChallengeModal extends WebDirective {
|
||||
this.bindToController = true;
|
||||
this.scope = {
|
||||
challenge: '=',
|
||||
orchestrator: '=',
|
||||
application: '='
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user