dev #14384 Правка ошибок отображения WPA КофеЛайк: fix sms enter code on ios

This commit is contained in:
nikolay 2023-06-20 12:28:35 +04:00
parent 7b5200d9f8
commit 26b2e8eb13
2 changed files with 19 additions and 48 deletions

View File

@ -9,15 +9,19 @@ export class FocusNextInputDirective {
constructor(private renderer: Renderer2) { }
ngOnInit() {
this.eventEmitter.subscribe(elementId => {
try {
this.renderer.selectRootElement(elementId).focus();
this.renderer.selectRootElement(elementId).click();
} catch (ex) {
(document.activeElement as HTMLElement).blur();
// If the element doesn't exist or if the element disappears when this called then no need to do anything
}
});
// TODO: don't need to listen all events
this.eventEmitter.subscribe(elementId => {
try {
const element = this.renderer.selectRootElement(elementId)
setTimeout(() => {
element.focus();
element.click();
}, 0);
} catch (ex) {
(document.activeElement as HTMLElement).blur();
// If the element doesn't exist or if the element disappears when this called then no need to do anything
}
});
}
}

View File

@ -1,5 +1,3 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import {
AfterViewInit,
Component,
@ -43,47 +41,17 @@ export class LoginComponent implements OnInit, AfterViewInit {
private jsonRpcService: JsonrpcService
) {}
ngOnInit(): void {
if ('OTPCredential' in window) {
console.log('have otp credential');
window.addEventListener('DOMContentLoaded', e => {
const form = document.querySelector('.code-form');
const ac = new AbortController();
if (form) {
form.addEventListener('submit', e => {
ac.abort();
});
}
navigator.credentials.get({
otp: { transport:['sms'] },
signal: ac.signal
}).then(otp => {
console.log(otp)
const input1 = document.getById("field");
const input2 = document.getById("field1");
const input3 = document.getById("field2");
const input4 = document.getById("field3");
input1.value = otp.code[0];
input2.value = otp.code[1];
input3.value = otp.code[2];
input4.value = otp.code[3];
if (form) form.submit();
}).catch(err => {
console.log(err);
});
});
}
}
ngOnInit(): void {}
ngAfterViewInit() {
setTimeout(() => {
this.inputFocusEmitter.emit(`#${this.inputIds[0]}`);
}, 1000);
}
public inputFocusEmitter = new EventEmitter<string>();
@HostListener('window:keyup', ['$event'])
@HostListener('window:keydown', ['$event'])
HandlKeyEvents(event: any) {
if (!event.target.classList.contains('field')) return;
const key = event.key.toLocaleLowerCase();
@ -100,12 +68,11 @@ export class LoginComponent implements OnInit, AfterViewInit {
break;
default:
elementId = event.target.id;
elementId = event.target.id;
const index = this.inputIds.indexOf(elementId);
const nextInputIndex = index + 1;
if (event.target.value.length > 1) {
event.target.value = event.target.value.slice(-1);
}
event.target.value = event.key;
if (nextInputIndex > 0 && nextInputIndex <= this.inputIds.length) {
this.inputFocusEmitter.emit(`#${this.inputIds[nextInputIndex]}`);
}