morethanwords
4 years ago
18 changed files with 1465 additions and 1413 deletions
@ -1,194 +0,0 @@ |
|||||||
//import { appImManager, appMessagesManager, appDialogsManager, apiUpdatesManager, appUsersManager } from "../lib/services";
|
|
||||||
import { openBtnMenu } from "./misc"; |
|
||||||
//import {stackBlurImage} from '../lib/StackBlur';
|
|
||||||
import appSidebarLeft from "../lib/appManagers/appSidebarLeft"; |
|
||||||
|
|
||||||
export default () => import('../lib/services').then(services => { |
|
||||||
//console.log('included services', services);
|
|
||||||
|
|
||||||
let {appImManager, appMessagesManager, appDialogsManager, apiUpdatesManager, appUsersManager} = services; |
|
||||||
//export default () => {
|
|
||||||
|
|
||||||
let pageEl = document.body.getElementsByClassName('page-chats')[0] as HTMLDivElement; |
|
||||||
pageEl.style.display = ''; |
|
||||||
|
|
||||||
apiUpdatesManager.attach(); |
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
document.addEventListener('user_update', (e: CustomEvent) => { |
|
||||||
let userID = e.detail; |
|
||||||
|
|
||||||
let user = appUsersManager.getUser(userID); |
|
||||||
|
|
||||||
let dialog = appMessagesManager.getDialogByPeerID(user.id)[0]; |
|
||||||
//console.log('updating user:', user, dialog);
|
|
||||||
|
|
||||||
if(dialog && !appUsersManager.isBot(dialog.peerID) && dialog.peerID != appImManager.myID) { |
|
||||||
let online = user.status && user.status._ == 'userStatusOnline'; |
|
||||||
let dom = appDialogsManager.getDialogDom(dialog.peerID); |
|
||||||
|
|
||||||
if(dom) { |
|
||||||
if(online) { |
|
||||||
dom.avatarDiv.classList.add('is-online'); |
|
||||||
} else { |
|
||||||
dom.avatarDiv.classList.remove('is-online'); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if(appImManager.peerID == user.id) { |
|
||||||
appImManager.setPeerStatus(); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
document.addEventListener('dialog_top', (e: CustomEvent) => { |
|
||||||
let dialog: any = e.detail; |
|
||||||
|
|
||||||
appDialogsManager.setLastMessage(dialog); |
|
||||||
appDialogsManager.sortDom(); |
|
||||||
}); |
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
document.addEventListener('dialogs_multiupdate', (e: CustomEvent) => { |
|
||||||
let dialogs = e.detail; |
|
||||||
|
|
||||||
let performed = 0; |
|
||||||
for(let id in dialogs) { |
|
||||||
let dialog = dialogs[id]; |
|
||||||
|
|
||||||
/////console.log('updating dialog:', dialog);
|
|
||||||
|
|
||||||
++performed; |
|
||||||
|
|
||||||
if(!(dialog.peerID in appDialogsManager.doms)) { |
|
||||||
appDialogsManager.addDialog(dialog); |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
appDialogsManager.setLastMessage(dialog); |
|
||||||
} |
|
||||||
|
|
||||||
if(performed/* && false */) { |
|
||||||
/////////console.log('will sortDom');
|
|
||||||
appDialogsManager.sortDom(); |
|
||||||
appDialogsManager.sortDom(true); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
document.addEventListener('dialog_unread', (e: CustomEvent) => { |
|
||||||
let info: { |
|
||||||
peerID: number, |
|
||||||
count: number |
|
||||||
} = e.detail; |
|
||||||
|
|
||||||
let dialog = appMessagesManager.getDialogByPeerID(info.peerID)[0]; |
|
||||||
if(dialog) { |
|
||||||
appDialogsManager.setUnreadMessages(dialog); |
|
||||||
|
|
||||||
if(dialog.peerID == appImManager.peerID) { |
|
||||||
appImManager.updateUnreadByDialog(dialog); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
/* |
|
||||||
loadDialogs().then(result => { |
|
||||||
//appImManager.setScroll(chatScroll);
|
|
||||||
}); |
|
||||||
return; |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/* function placeCaretAfterNode(node: HTMLElement) { |
|
||||||
if (typeof window.getSelection != "undefined") { |
|
||||||
var range = document.createRange(); |
|
||||||
range.setStartAfter(node); |
|
||||||
range.collapse(true); |
|
||||||
var selection = window.getSelection(); |
|
||||||
selection.removeAllRanges(); |
|
||||||
selection.addRange(range); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
messageInput.onclick = (e) => { |
|
||||||
let target = e.target as HTMLElement; |
|
||||||
if(target.classList.contains('emoji-inner')) { |
|
||||||
placeCaretAfterNode(target.parentElement); |
|
||||||
} else if(target.classList.contains('emoji-sizer')) { |
|
||||||
placeCaretAfterNode(target); |
|
||||||
} |
|
||||||
console.log('lol', target); |
|
||||||
}; */ |
|
||||||
|
|
||||||
/* window.addEventListener('click', function(this, e) { |
|
||||||
// @ts-ignore
|
|
||||||
let isInput = e.target.tagName == 'INPUT'; |
|
||||||
if(!isInput && !window.getSelection().toString()) { |
|
||||||
console.log('click'); |
|
||||||
messageInput.focus(); |
|
||||||
} |
|
||||||
}); */ |
|
||||||
|
|
||||||
/* fetch('assets/img/camomile.jpg') |
|
||||||
.then(res => res.blob()) |
|
||||||
.then(blob => { |
|
||||||
let img = new Image(); |
|
||||||
let url = URL.createObjectURL(blob); |
|
||||||
img.src = url; |
|
||||||
img.onload = () => { |
|
||||||
let id = 'chat-background-canvas'; |
|
||||||
var canvas = document.getElementById(id) as HTMLCanvasElement; |
|
||||||
//URL.revokeObjectURL(url);
|
|
||||||
|
|
||||||
let elements = ['.chat-container'].map(selector => { |
|
||||||
return document.querySelector(selector) as HTMLDivElement; |
|
||||||
}); |
|
||||||
|
|
||||||
stackBlurImage(img, id, 15, 0); |
|
||||||
|
|
||||||
canvas.toBlob(blob => { |
|
||||||
//let dataUrl = canvas.toDataURL('image/jpeg', 1);
|
|
||||||
let dataUrl = URL.createObjectURL(blob); |
|
||||||
|
|
||||||
elements.forEach(el => { |
|
||||||
el.style.backgroundImage = 'url(' + dataUrl + ')'; |
|
||||||
}); |
|
||||||
}, 'image/jpeg', 1); |
|
||||||
}; |
|
||||||
}); */ |
|
||||||
|
|
||||||
/* toggleEmoticons.onclick = (e) => { |
|
||||||
if(!emoticonsDropdown) { |
|
||||||
emoticonsDropdown = initEmoticonsDropdown(pageEl, appImManager, |
|
||||||
appMessagesManager, messageInput, toggleEmoticons); |
|
||||||
} else { |
|
||||||
emoticonsDropdown.classList.toggle('active'); |
|
||||||
} |
|
||||||
|
|
||||||
toggleEmoticons.classList.toggle('active'); |
|
||||||
}; */ |
|
||||||
|
|
||||||
Array.from(document.getElementsByClassName('btn-menu-toggle')).forEach((el) => { |
|
||||||
el.addEventListener('click', (e) => { |
|
||||||
//console.log('click pageIm');
|
|
||||||
if(!el.classList.contains('btn-menu-toggle')) return false; |
|
||||||
|
|
||||||
//window.removeEventListener('mousemove', onMouseMove);
|
|
||||||
let openedMenu = el.querySelector('.btn-menu') as HTMLDivElement; |
|
||||||
e.cancelBubble = true; |
|
||||||
|
|
||||||
if(el.classList.contains('menu-open')) { |
|
||||||
el.classList.remove('menu-open'); |
|
||||||
openedMenu.classList.remove('active'); |
|
||||||
} else { |
|
||||||
openBtnMenu(openedMenu); |
|
||||||
} |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
appSidebarLeft.loadDialogs().then(result => { |
|
||||||
//appSidebarLeft.onChatsScroll();
|
|
||||||
appSidebarLeft.loadDialogs(true); |
|
||||||
}); |
|
||||||
}); |
|
@ -0,0 +1,28 @@ |
|||||||
|
import pagesManager from "./pagesManager"; |
||||||
|
|
||||||
|
export default class Page { |
||||||
|
public pageEl: HTMLDivElement; |
||||||
|
private installed = false; |
||||||
|
|
||||||
|
constructor(className: string, public isAuthPage: boolean, private onFirstMount?: (...args: any[]) => void, private onMount?: (...args: any[]) => void) { |
||||||
|
this.pageEl = document.body.getElementsByClassName(className)[0] as HTMLDivElement; |
||||||
|
} |
||||||
|
|
||||||
|
public mount(...args: any[]) { |
||||||
|
//this.pageEl.style.display = '';
|
||||||
|
|
||||||
|
if(this.onMount) { |
||||||
|
this.onMount(...args); |
||||||
|
} |
||||||
|
|
||||||
|
if(!this.installed) { |
||||||
|
if(this.onFirstMount) { |
||||||
|
this.onFirstMount(...args); |
||||||
|
} |
||||||
|
|
||||||
|
this.installed = true; |
||||||
|
} |
||||||
|
|
||||||
|
pagesManager.setPage(this); |
||||||
|
} |
||||||
|
} |
@ -1,276 +1,274 @@ |
|||||||
import pageSignIn from './pageSignIn'; |
import pageSignIn from './pageSignIn'; |
||||||
import pageSignUp from './pageSignUp'; |
import pageSignUp from './pageSignUp'; |
||||||
import pageIm from './pageIm'; |
import pageIm from './pageIm'; |
||||||
import pagePassword from './pagePassword'; |
import pagePassword from './pagePassword'; |
||||||
import CryptoWorker from '../lib/crypto/cryptoworker'; |
import CryptoWorker from '../lib/crypto/cryptoworker'; |
||||||
import LottieLoader from '../lib/lottieLoader'; |
import LottieLoader from '../lib/lottieLoader'; |
||||||
import apiManager from '../lib/mtproto/apiManager'; |
import apiManager from '../lib/mtproto/apiManager'; |
||||||
|
import Page from './page'; |
||||||
let installed = false; |
|
||||||
let authCode: { |
let authCode: { |
||||||
_: string, // 'auth.sentCode'
|
_: string, // 'auth.sentCode'
|
||||||
pFlags: any, // {}
|
pFlags: any, // {}
|
||||||
flags: number, |
flags: number, |
||||||
type: { |
type: { |
||||||
_: string, // 'auth.sentCodeTypeSms',
|
_: string, // 'auth.sentCodeTypeSms',
|
||||||
length: number |
length: number |
||||||
}, |
}, |
||||||
phone_code_hash: string, |
phone_code_hash: string, |
||||||
phone_number: string |
phone_number: string |
||||||
} = null; |
} = null; |
||||||
|
|
||||||
const EDITONSAMEPAGE = false; |
const EDITONSAMEPAGE = false; |
||||||
|
|
||||||
export default async(_authCode: typeof authCode) => { |
let headerElement: HTMLHeadElement = null; |
||||||
authCode = _authCode; |
let sentTypeElement: HTMLParagraphElement = null; |
||||||
|
|
||||||
//let LottieLoader = (await import('../lib/lottieLoader')).default;
|
let onFirstMount = () => { |
||||||
|
let needFrame = 0, lastLength = 0; |
||||||
let pageElement = document.body.getElementsByClassName('page-authCode')[0] as HTMLDivElement; |
let animation: /* AnimationItem */any = undefined; |
||||||
pageElement.style.display = ''; |
|
||||||
|
const CODELENGTH = authCode.type.length; |
||||||
let headerElement = pageElement.getElementsByClassName('phone')[0] as HTMLHeadElement; |
|
||||||
headerElement.innerText = authCode.phone_number; |
fetch('assets/img/TwoFactorSetupMonkeyTracking.tgs') |
||||||
|
.then(res => res.arrayBuffer()) |
||||||
let sentTypeElement = pageElement.getElementsByClassName('sent-type')[0] as HTMLParagraphElement; |
.then(async(data) => { |
||||||
|
let str = await CryptoWorker.gzipUncompress<string>(data, true); |
||||||
switch(authCode.type._) { |
|
||||||
case 'auth.sentCodeTypeSms': |
animation = await LottieLoader.loadAnimation({ |
||||||
sentTypeElement.innerHTML = 'We have sent you an SMS<br>with the code.'; |
container: page.pageEl.querySelector('.auth-image'), |
||||||
break; |
renderer: 'svg', |
||||||
case 'auth.sentCodeTypeApp': |
loop: false, |
||||||
sentTypeElement.innerHTML = 'We have sent you a message in Telegram<br>with the code.'; |
autoplay: false, |
||||||
break; |
animationData: JSON.parse(str) |
||||||
case 'auth.sentCodeTypeCall': |
}); |
||||||
sentTypeElement.innerHTML = 'We will call you and voice<br>the code.'; |
|
||||||
break; |
animation.setSpeed(1); |
||||||
default: |
//console.log(animation.getDuration(), animation.getDuration(true));
|
||||||
sentTypeElement.innerHTML = `Please check everything<br>for a code (type: ${authCode.type._})`; |
|
||||||
break; |
animation.addEventListener('enterFrame', (e: any) => { |
||||||
} |
//console.log('enterFrame', e, needFrame);
|
||||||
|
let currentFrame = Math.round(e.currentTime); |
||||||
if(installed) return; |
|
||||||
installed = true; |
if((e.direction == 1 && currentFrame >= needFrame) || |
||||||
|
(e.direction == -1 && currentFrame <= needFrame)) { |
||||||
let needFrame = 0, lastLength = 0; |
animation.setSpeed(1); |
||||||
let animation: /* AnimationItem */any = undefined; |
animation.pause(); |
||||||
|
} |
||||||
const CODELENGTH = authCode.type.length; |
}); |
||||||
|
}); |
||||||
fetch('assets/img/TwoFactorSetupMonkeyTracking.tgs') |
|
||||||
.then(res => res.arrayBuffer()) |
const codeInput = page.pageEl.querySelector('#code') as HTMLInputElement; |
||||||
.then(async(data) => { |
const codeInputLabel = codeInput.nextElementSibling as HTMLLabelElement; |
||||||
let str = await CryptoWorker.gzipUncompress<string>(data, true); |
const editButton = page.pageEl.querySelector('.phone-edit') as HTMLElement; |
||||||
|
|
||||||
animation = await LottieLoader.loadAnimation({ |
if(EDITONSAMEPAGE) { |
||||||
container: document.body.querySelector('.page-authCode .auth-image'), |
let editable = false; |
||||||
renderer: 'svg', |
let changePhonePromise: Promise<unknown>; |
||||||
loop: false, |
|
||||||
autoplay: false, |
let changePhone = () => { |
||||||
animationData: JSON.parse(str) |
if(changePhonePromise) return; |
||||||
}); |
|
||||||
|
let phone_number = '+' + headerElement.innerText.replace(/\D/g, ''); |
||||||
animation.setSpeed(1); |
if(authCode.phone_number == phone_number) return; |
||||||
//console.log(animation.getDuration(), animation.getDuration(true));
|
|
||||||
|
codeInput.setAttribute('disabled', 'true'); |
||||||
animation.addEventListener('enterFrame', (e: any) => { |
|
||||||
//console.log('enterFrame', e, needFrame);
|
changePhonePromise = apiManager.invokeApi('auth.sendCode', { |
||||||
let currentFrame = Math.round(e.currentTime); |
/* flags: 0, */ |
||||||
|
phone_number: phone_number, |
||||||
if((e.direction == 1 && currentFrame >= needFrame) || |
api_id: Config.App.id, |
||||||
(e.direction == -1 && currentFrame <= needFrame)) { |
api_hash: Config.App.hash, |
||||||
animation.setSpeed(1); |
settings: { |
||||||
animation.pause(); |
_: 'codeSettings', // that's how we sending Type
|
||||||
} |
flags: 0 |
||||||
}); |
} |
||||||
}); |
/* lang_code: navigator.language || 'en' */ |
||||||
|
}).then((code: any) => { |
||||||
const codeInput = document.getElementById('code') as HTMLInputElement; |
console.log('got code 2', code); |
||||||
const codeInputLabel = codeInput.nextElementSibling as HTMLLabelElement; |
|
||||||
const editButton = document.querySelector('.phone-edit') as HTMLElement; |
authCode = Object.assign(code, {phone_number}); |
||||||
|
|
||||||
if(EDITONSAMEPAGE) { |
changePhonePromise = undefined; |
||||||
let editable = false; |
codeInput.removeAttribute('disabled'); |
||||||
let changePhonePromise: Promise<unknown>; |
codeInput.focus(); |
||||||
|
}).catch(err => { |
||||||
let changePhone = () => { |
switch(err.type) { |
||||||
if(changePhonePromise) return; |
case 'PHONE_NUMBER_INVALID': |
||||||
|
headerElement.classList.add('error'); |
||||||
let phone_number = '+' + headerElement.innerText.replace(/\D/g, ''); |
editable = true; |
||||||
if(authCode.phone_number == phone_number) return; |
headerElement.setAttribute('contenteditable', '' + editable); |
||||||
|
headerElement.focus(); |
||||||
codeInput.setAttribute('disabled', 'true'); |
break; |
||||||
|
default: |
||||||
changePhonePromise = apiManager.invokeApi('auth.sendCode', { |
codeInputLabel.innerText = err.type; |
||||||
/* flags: 0, */ |
break; |
||||||
phone_number: phone_number, |
} |
||||||
api_id: Config.App.id, |
|
||||||
api_hash: Config.App.hash, |
changePhonePromise = undefined; |
||||||
settings: { |
codeInput.removeAttribute('disabled'); |
||||||
_: 'codeSettings', // that's how we sending Type
|
}); |
||||||
flags: 0 |
}; |
||||||
} |
|
||||||
/* lang_code: navigator.language || 'en' */ |
headerElement.addEventListener('keypress', function(this, e) { |
||||||
}).then((code: any) => { |
if(e.key == 'Enter') { |
||||||
console.log('got code 2', code); |
editable = false; |
||||||
|
headerElement.setAttribute('contenteditable', '' + editable); |
||||||
authCode = Object.assign(code, {phone_number}); |
changePhone(); |
||||||
|
} |
||||||
changePhonePromise = undefined; |
|
||||||
codeInput.removeAttribute('disabled'); |
if(/\D/.test(e.key)) { |
||||||
codeInput.focus(); |
e.preventDefault(); |
||||||
}).catch(err => { |
return false; |
||||||
switch(err.type) { |
} |
||||||
case 'PHONE_NUMBER_INVALID': |
|
||||||
headerElement.classList.add('error'); |
this.classList.remove('error'); |
||||||
editable = true; |
}); |
||||||
headerElement.setAttribute('contenteditable', '' + editable); |
|
||||||
headerElement.focus(); |
editButton.addEventListener('click', function() { |
||||||
break; |
if(changePhonePromise) return; |
||||||
default: |
|
||||||
codeInputLabel.innerText = err.type; |
editable = !editable; |
||||||
break; |
headerElement.setAttribute('contenteditable', '' + editable); |
||||||
} |
|
||||||
|
if(!editable) changePhone(); |
||||||
changePhonePromise = undefined; |
}); |
||||||
codeInput.removeAttribute('disabled'); |
} else { |
||||||
}); |
editButton.addEventListener('click', function() { |
||||||
}; |
return pageSignIn.mount(); |
||||||
|
}); |
||||||
headerElement.addEventListener('keypress', function(this, e) { |
} |
||||||
if(e.key == 'Enter') { |
|
||||||
editable = false; |
let submitCode = (code: string) => { |
||||||
headerElement.setAttribute('contenteditable', '' + editable); |
codeInput.setAttribute('disabled', 'true'); |
||||||
changePhone(); |
|
||||||
} |
let params = { |
||||||
|
phone_number: authCode.phone_number, |
||||||
if(/\D/.test(e.key)) { |
phone_code_hash: authCode.phone_code_hash, |
||||||
e.preventDefault(); |
phone_code: code |
||||||
return false; |
}; |
||||||
} |
|
||||||
|
console.log('invoking auth.signIn with params:', params); |
||||||
this.classList.remove('error'); |
|
||||||
}); |
apiManager.invokeApi('auth.signIn', params) |
||||||
|
.then((response: any) => { |
||||||
editButton.addEventListener('click', function() { |
console.log('auth.signIn response:', response); |
||||||
if(changePhonePromise) return; |
|
||||||
|
switch(response._) { |
||||||
editable = !editable; |
case 'auth.authorization': |
||||||
headerElement.setAttribute('contenteditable', '' + editable); |
apiManager.setUserAuth({ |
||||||
|
id: response.user.id |
||||||
if(!editable) changePhone(); |
}); |
||||||
}); |
|
||||||
} else { |
pageIm.mount(); |
||||||
editButton.addEventListener('click', function() { |
if(animation) animation.destroy(); |
||||||
pageElement.style.display = 'none'; |
break; |
||||||
return pageSignIn(); |
case 'auth.authorizationSignUpRequired': |
||||||
}); |
console.log('Registration needed!'); |
||||||
} |
|
||||||
|
pageSignUp.mount({ |
||||||
let submitCode = (code: string) => { |
'phone_number': authCode.phone_number, |
||||||
codeInput.setAttribute('disabled', 'true'); |
'phone_code_hash': authCode.phone_code_hash |
||||||
|
}); |
||||||
let params = { |
|
||||||
phone_number: authCode.phone_number, |
if(animation) animation.destroy(); |
||||||
phone_code_hash: authCode.phone_code_hash, |
break; |
||||||
phone_code: code |
default: |
||||||
}; |
codeInput.innerText = response._; |
||||||
|
break; |
||||||
console.log('invoking auth.signIn with params:', params); |
} |
||||||
|
}).catch(err => { |
||||||
apiManager.invokeApi('auth.signIn', params) |
codeInput.removeAttribute('disabled'); |
||||||
.then((response: any) => { |
|
||||||
console.log('auth.signIn response:', response); |
switch(err.type) { |
||||||
|
case 'SESSION_PASSWORD_NEEDED': |
||||||
switch(response._) { |
console.warn('pageAuthCode: SESSION_PASSWORD_NEEDED'); |
||||||
case 'auth.authorization': |
err.handled = true; |
||||||
apiManager.setUserAuth({ |
if(animation) animation.destroy(); |
||||||
id: response.user.id |
pagePassword.mount(); |
||||||
}); |
break; |
||||||
|
case 'PHONE_CODE_EMPTY': |
||||||
pageElement.style.display = 'none'; |
case 'PHONE_CODE_INVALID': |
||||||
pageIm(); |
codeInput.classList.add('error'); |
||||||
if(animation) animation.destroy(); |
codeInputLabel.innerText = 'Invalid Code'; |
||||||
break; |
break; |
||||||
case 'auth.authorizationSignUpRequired': |
default: |
||||||
console.log('Registration needed!'); |
codeInputLabel.innerText = err.type; |
||||||
|
break; |
||||||
pageElement.style.display = 'none'; |
} |
||||||
pageSignUp({ |
}); |
||||||
'phone_number': authCode.phone_number, |
}; |
||||||
'phone_code_hash': authCode.phone_code_hash |
|
||||||
}); |
const max = 45; |
||||||
|
// 1st symbol = frame 15
|
||||||
if(animation) animation.destroy(); |
// end symbol = frame 165
|
||||||
break; |
codeInput.addEventListener('input', function(this: typeof codeInput, e) { |
||||||
default: |
this.classList.remove('error'); |
||||||
codeInput.innerText = response._; |
|
||||||
break; |
this.value = this.value.replace(/\D/g, ''); |
||||||
} |
if(this.value.length > CODELENGTH) { |
||||||
}).catch(err => { |
this.value = this.value.slice(0, CODELENGTH); |
||||||
codeInput.removeAttribute('disabled'); |
} |
||||||
|
|
||||||
switch(err.type) { |
let length = this.value.length; |
||||||
case 'SESSION_PASSWORD_NEEDED': |
if(length == CODELENGTH) { // submit code
|
||||||
console.warn('pageAuthCode: SESSION_PASSWORD_NEEDED'); |
submitCode(this.value); |
||||||
err.handled = true; |
} else if(length == lastLength) { |
||||||
pageElement.style.display = 'none'; |
return; |
||||||
if(animation) animation.destroy(); |
} |
||||||
pagePassword(); |
|
||||||
break; |
lastLength = length; |
||||||
case 'PHONE_CODE_EMPTY': |
|
||||||
case 'PHONE_CODE_INVALID': |
if(!animation) return; |
||||||
codeInput.classList.add('error'); |
|
||||||
codeInputLabel.innerText = 'Invalid Code'; |
let frame: number; |
||||||
break; |
if(length) frame = Math.round((length > max ? max : length) * (165 / max) + 11.33); |
||||||
default: |
else frame = 0; |
||||||
codeInputLabel.innerText = err.type; |
//animation.playSegments([1, 2]);
|
||||||
break; |
|
||||||
} |
let direction = needFrame > frame ? -1 : 1; |
||||||
}); |
//console.log('keydown', length, frame, direction);
|
||||||
}; |
|
||||||
|
animation.setDirection(direction); |
||||||
const max = 45; |
if(needFrame != 0 && frame == 0) { |
||||||
// 1st symbol = frame 15
|
animation.setSpeed(7); |
||||||
// end symbol = frame 165
|
} |
||||||
codeInput.addEventListener('input', function(this: typeof codeInput, e) { |
/* let diff = Math.abs(needFrame - frame * direction); |
||||||
this.classList.remove('error'); |
if((diff / 20) > 1) animation.setSpeed(diff / 20 | 0); */ |
||||||
|
needFrame = frame; |
||||||
this.value = this.value.replace(/\D/g, ''); |
|
||||||
if(this.value.length > CODELENGTH) { |
animation.play(); |
||||||
this.value = this.value.slice(0, CODELENGTH); |
|
||||||
} |
/* animation.goToAndStop(15, true); */ |
||||||
|
//animation.goToAndStop(length / max * );
|
||||||
let length = this.value.length; |
}); |
||||||
if(length == CODELENGTH) { // submit code
|
}; |
||||||
submitCode(this.value); |
|
||||||
} else if(length == lastLength) { |
const page = new Page('page-authCode', true, onFirstMount, (_authCode: typeof authCode) => { |
||||||
return; |
authCode = _authCode; |
||||||
} |
|
||||||
|
if(!headerElement) { |
||||||
lastLength = length; |
headerElement = page.pageEl.getElementsByClassName('phone')[0] as HTMLHeadElement; |
||||||
|
sentTypeElement = page.pageEl.getElementsByClassName('sent-type')[0] as HTMLParagraphElement; |
||||||
if(!animation) return; |
} |
||||||
|
|
||||||
let frame: number; |
//let LottieLoader = (await import('../lib/lottieLoader')).default;
|
||||||
if(length) frame = Math.round((length > max ? max : length) * (165 / max) + 11.33); |
|
||||||
else frame = 0; |
headerElement.innerText = authCode.phone_number; |
||||||
//animation.playSegments([1, 2]);
|
switch(authCode.type._) { |
||||||
|
case 'auth.sentCodeTypeSms': |
||||||
let direction = needFrame > frame ? -1 : 1; |
sentTypeElement.innerHTML = 'We have sent you an SMS<br>with the code.'; |
||||||
//console.log('keydown', length, frame, direction);
|
break; |
||||||
// @ts-ignore
|
case 'auth.sentCodeTypeApp': |
||||||
animation.setDirection(direction); |
sentTypeElement.innerHTML = 'We have sent you a message in Telegram<br>with the code.'; |
||||||
if(needFrame != 0 && frame == 0) { |
break; |
||||||
animation.setSpeed(7); |
case 'auth.sentCodeTypeCall': |
||||||
} |
sentTypeElement.innerHTML = 'We will call you and voice<br>the code.'; |
||||||
/* let diff = Math.abs(needFrame - frame * direction); |
break; |
||||||
if((diff / 20) > 1) animation.setSpeed(diff / 20 | 0); */ |
default: |
||||||
needFrame = frame; |
sentTypeElement.innerHTML = `Please check everything<br>for a code (type: ${authCode.type._})`; |
||||||
|
break; |
||||||
animation.play(); |
} |
||||||
|
}); |
||||||
/* animation.goToAndStop(15, true); */ |
|
||||||
//animation.goToAndStop(length / max * );
|
export default page; |
||||||
}); |
|
||||||
}; |
|
@ -0,0 +1,111 @@ |
|||||||
|
import { openBtnMenu, ripple } from "../components/misc"; |
||||||
|
//import {stackBlurImage} from '../lib/StackBlur';
|
||||||
|
import Page from "./page"; |
||||||
|
//import appImManager from '../lib/appManagers/appImManager';
|
||||||
|
|
||||||
|
let onFirstMount = () => import('../lib/appManagers/appImManager').then(() => {//import('../lib/services').then(services => {
|
||||||
|
//console.log('included services', services);
|
||||||
|
|
||||||
|
//export default () => {
|
||||||
|
|
||||||
|
|
||||||
|
/* |
||||||
|
loadDialogs().then(result => { |
||||||
|
//appImManager.setScroll(chatScroll);
|
||||||
|
}); |
||||||
|
return; |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
/* function placeCaretAfterNode(node: HTMLElement) { |
||||||
|
if (typeof window.getSelection != "undefined") { |
||||||
|
var range = document.createRange(); |
||||||
|
range.setStartAfter(node); |
||||||
|
range.collapse(true); |
||||||
|
var selection = window.getSelection(); |
||||||
|
selection.removeAllRanges(); |
||||||
|
selection.addRange(range); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
messageInput.onclick = (e) => { |
||||||
|
let target = e.target as HTMLElement; |
||||||
|
if(target.classList.contains('emoji-inner')) { |
||||||
|
placeCaretAfterNode(target.parentElement); |
||||||
|
} else if(target.classList.contains('emoji-sizer')) { |
||||||
|
placeCaretAfterNode(target); |
||||||
|
} |
||||||
|
console.log('lol', target); |
||||||
|
}; */ |
||||||
|
|
||||||
|
/* window.addEventListener('click', function(this, e) { |
||||||
|
// @ts-ignore
|
||||||
|
let isInput = e.target.tagName == 'INPUT'; |
||||||
|
if(!isInput && !window.getSelection().toString()) { |
||||||
|
console.log('click'); |
||||||
|
messageInput.focus(); |
||||||
|
} |
||||||
|
}); */ |
||||||
|
|
||||||
|
/* fetch('assets/img/camomile.jpg') |
||||||
|
.then(res => res.blob()) |
||||||
|
.then(blob => { |
||||||
|
let img = new Image(); |
||||||
|
let url = URL.createObjectURL(blob); |
||||||
|
img.src = url; |
||||||
|
img.onload = () => { |
||||||
|
let id = 'chat-background-canvas'; |
||||||
|
var canvas = document.getElementById(id) as HTMLCanvasElement; |
||||||
|
//URL.revokeObjectURL(url);
|
||||||
|
|
||||||
|
let elements = ['.chat-container'].map(selector => { |
||||||
|
return document.querySelector(selector) as HTMLDivElement; |
||||||
|
}); |
||||||
|
|
||||||
|
stackBlurImage(img, id, 15, 0); |
||||||
|
|
||||||
|
canvas.toBlob(blob => { |
||||||
|
//let dataUrl = canvas.toDataURL('image/jpeg', 1);
|
||||||
|
let dataUrl = URL.createObjectURL(blob); |
||||||
|
|
||||||
|
elements.forEach(el => { |
||||||
|
el.style.backgroundImage = 'url(' + dataUrl + ')'; |
||||||
|
}); |
||||||
|
}, 'image/jpeg', 1); |
||||||
|
}; |
||||||
|
}); */ |
||||||
|
|
||||||
|
/* toggleEmoticons.onclick = (e) => { |
||||||
|
if(!emoticonsDropdown) { |
||||||
|
emoticonsDropdown = initEmoticonsDropdown(pageEl, appImManager, |
||||||
|
appMessagesManager, messageInput, toggleEmoticons); |
||||||
|
} else { |
||||||
|
emoticonsDropdown.classList.toggle('active'); |
||||||
|
} |
||||||
|
|
||||||
|
toggleEmoticons.classList.toggle('active'); |
||||||
|
}; */ |
||||||
|
|
||||||
|
(Array.from(document.getElementsByClassName('rp')) as HTMLElement[]).forEach(el => ripple(el)); |
||||||
|
|
||||||
|
Array.from(document.getElementsByClassName('btn-menu-toggle')).forEach((el) => { |
||||||
|
el.addEventListener('click', (e) => { |
||||||
|
//console.log('click pageIm');
|
||||||
|
if(!el.classList.contains('btn-menu-toggle')) return false; |
||||||
|
|
||||||
|
//window.removeEventListener('mousemove', onMouseMove);
|
||||||
|
let openedMenu = el.querySelector('.btn-menu') as HTMLDivElement; |
||||||
|
e.cancelBubble = true; |
||||||
|
|
||||||
|
if(el.classList.contains('menu-open')) { |
||||||
|
el.classList.remove('menu-open'); |
||||||
|
openedMenu.classList.remove('active'); |
||||||
|
} else { |
||||||
|
openBtnMenu(openedMenu); |
||||||
|
} |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
const page = new Page('page-chats', false, onFirstMount); |
||||||
|
export default page; |
@ -1,136 +1,131 @@ |
|||||||
import pageIm from './pageIm'; |
import pageIm from './pageIm'; |
||||||
import CryptoWorker from '../lib/crypto/cryptoworker'; |
import CryptoWorker from '../lib/crypto/cryptoworker'; |
||||||
import { putPreloader } from './misc'; |
import { putPreloader } from '../components/misc'; |
||||||
|
|
||||||
import LottieLoader from '../lib/lottieLoader'; |
import LottieLoader from '../lib/lottieLoader'; |
||||||
import passwordManager from '../lib/mtproto/passwordManager'; |
import passwordManager from '../lib/mtproto/passwordManager'; |
||||||
import apiManager from '../lib/mtproto/apiManager'; |
import apiManager from '../lib/mtproto/apiManager'; |
||||||
|
import Page from './page'; |
||||||
let installed = false; |
|
||||||
|
let onFirstMount = () => { |
||||||
export default async() => { |
let needFrame = 0; |
||||||
//let LottieLoader = (await import('../lib/lottieLoader')).default;
|
let animation: /* AnimationItem */any = undefined; |
||||||
|
|
||||||
if(installed) return; |
let passwordVisible = false; |
||||||
installed = true; |
|
||||||
|
fetch('assets/img/TwoFactorSetupMonkeyClose.tgs') |
||||||
let needFrame = 0; |
.then(res => res.arrayBuffer()) |
||||||
let animation: /* AnimationItem */any = undefined; |
.then(async(data) => { |
||||||
|
let str = await CryptoWorker.gzipUncompress<string>(data, true); |
||||||
let passwordVisible = false; |
|
||||||
let pageElement = document.body.getElementsByClassName('page-password')[0] as HTMLDivElement; |
animation = await LottieLoader.loadAnimation({ |
||||||
pageElement.style.display = ''; |
container: page.pageEl.querySelector('.auth-image'), |
||||||
|
renderer: 'svg', |
||||||
fetch('assets/img/TwoFactorSetupMonkeyClose.tgs') |
loop: false, |
||||||
.then(res => res.arrayBuffer()) |
autoplay: false, |
||||||
.then(async(data) => { |
animationData: JSON.parse(str) |
||||||
let str = await CryptoWorker.gzipUncompress<string>(data, true); |
}); |
||||||
|
|
||||||
animation = await LottieLoader.loadAnimation({ |
console.log(animation.getDuration(true)); |
||||||
container: pageElement.querySelector('.auth-image'), |
//animation.goToAndStop(822);
|
||||||
renderer: 'svg', |
|
||||||
loop: false, |
animation.addEventListener('enterFrame', (e: any) => { |
||||||
autoplay: false, |
//console.log('enterFrame', e, needFrame);
|
||||||
animationData: JSON.parse(str) |
let currentFrame = Math.round(e.currentTime); |
||||||
}); |
|
||||||
|
if((e.direction == 1 && currentFrame >= needFrame) || |
||||||
console.log(animation.getDuration(true)); |
(e.direction == -1 && currentFrame <= needFrame)) { |
||||||
//animation.goToAndStop(822);
|
animation.setSpeed(1); |
||||||
|
animation.pause(); |
||||||
animation.addEventListener('enterFrame', (e: any) => { |
} |
||||||
//console.log('enterFrame', e, needFrame);
|
}); |
||||||
let currentFrame = Math.round(e.currentTime); |
|
||||||
|
needFrame = 49; |
||||||
if((e.direction == 1 && currentFrame >= needFrame) || |
animation.play(); |
||||||
(e.direction == -1 && currentFrame <= needFrame)) { |
}); |
||||||
animation.setSpeed(1); |
|
||||||
animation.pause(); |
const btnNext = page.pageEl.querySelector('button') as HTMLButtonElement; |
||||||
} |
const passwordInput = document.getElementById('password') as HTMLInputElement; |
||||||
}); |
//const passwordInputLabel = passwordInput.nextElementSibling as HTMLLabelElement;
|
||||||
|
const toggleVisible = page.pageEl.querySelector('.toggle-visible') as HTMLSpanElement; |
||||||
needFrame = 49; |
|
||||||
animation.play(); |
let handleError = (err: any) => { |
||||||
}); |
btnNext.removeAttribute('disabled'); |
||||||
|
|
||||||
const btnNext = pageElement.querySelector('button') as HTMLButtonElement; |
switch(err.type) { |
||||||
const passwordInput = document.getElementById('password') as HTMLInputElement; |
default: |
||||||
//const passwordInputLabel = passwordInput.nextElementSibling as HTMLLabelElement;
|
btnNext.innerText = err.type; |
||||||
const toggleVisible = pageElement.querySelector('.toggle-visible') as HTMLSpanElement; |
break; |
||||||
|
} |
||||||
let handleError = (err: any) => { |
}; |
||||||
btnNext.removeAttribute('disabled'); |
|
||||||
|
toggleVisible.addEventListener('click', function(this, e) { |
||||||
switch(err.type) { |
if(!passwordVisible) { |
||||||
default: |
this.classList.add('tgico-eye2'); |
||||||
btnNext.innerText = err.type; |
passwordInput.setAttribute('type', 'text'); |
||||||
break; |
animation.setDirection(-1); |
||||||
} |
needFrame = 0; |
||||||
}; |
animation.play(); |
||||||
|
} else { |
||||||
toggleVisible.addEventListener('click', function(this, e) { |
this.classList.remove('tgico-eye2'); |
||||||
if(!passwordVisible) { |
passwordInput.setAttribute('type', 'password'); |
||||||
this.classList.add('tgico-eye2'); |
animation.setDirection(1); |
||||||
passwordInput.setAttribute('type', 'text'); |
needFrame = 49; |
||||||
animation.setDirection(-1); |
animation.play(); |
||||||
needFrame = 0; |
} |
||||||
animation.play(); |
|
||||||
} else { |
passwordVisible = !passwordVisible; |
||||||
this.classList.remove('tgico-eye2'); |
}); |
||||||
passwordInput.setAttribute('type', 'password'); |
|
||||||
animation.setDirection(1); |
btnNext.addEventListener('click', function(this, e) { |
||||||
needFrame = 49; |
if(!passwordInput.value.length) { |
||||||
animation.play(); |
passwordInput.classList.add('error'); |
||||||
} |
return; |
||||||
|
} |
||||||
passwordVisible = !passwordVisible; |
|
||||||
}); |
this.setAttribute('disabled', 'true'); |
||||||
|
let value = passwordInput.value; |
||||||
btnNext.addEventListener('click', function(this, e) { |
|
||||||
if(!passwordInput.value.length) { |
this.textContent = 'PLEASE WAIT...'; |
||||||
passwordInput.classList.add('error'); |
putPreloader(this); |
||||||
return; |
|
||||||
} |
passwordManager.getState() |
||||||
|
.then(state => { |
||||||
this.setAttribute('disabled', 'true'); |
console.log(state); |
||||||
let value = passwordInput.value; |
passwordManager.check(state, value).then((response: any) => { |
||||||
|
console.log('passwordManager response:', response); |
||||||
this.textContent = 'PLEASE WAIT...'; |
|
||||||
putPreloader(this); |
switch(response._) { |
||||||
|
case 'auth.authorization': |
||||||
passwordManager.getState() |
apiManager.setUserAuth({ |
||||||
.then(state => { |
id: response.user.id |
||||||
console.log(state); |
}); |
||||||
passwordManager.check(state, value).then((response: any) => { |
|
||||||
console.log('passwordManager response:', response); |
pageIm.mount(); |
||||||
|
if(animation) animation.destroy(); |
||||||
switch(response._) { |
break; |
||||||
case 'auth.authorization': |
default: |
||||||
apiManager.setUserAuth({ |
btnNext.removeAttribute('disabled'); |
||||||
id: response.user.id |
btnNext.innerText = response._; |
||||||
}); |
break; |
||||||
|
} |
||||||
pageElement.style.display = 'none'; |
}).catch(handleError); |
||||||
pageIm(); |
}).catch(handleError); |
||||||
if(animation) animation.destroy(); |
}); |
||||||
break; |
|
||||||
default: |
passwordInput.addEventListener('keypress', function(this, e) { |
||||||
btnNext.removeAttribute('disabled'); |
this.classList.remove('error'); |
||||||
btnNext.innerText = response._; |
|
||||||
break; |
if(e.key == 'Enter') { |
||||||
} |
return btnNext.click(); |
||||||
}).catch(handleError); |
} |
||||||
}).catch(handleError); |
}); |
||||||
}); |
|
||||||
|
/* passwordInput.addEventListener('input', function(this, e) { |
||||||
passwordInput.addEventListener('keypress', function(this, e) { |
|
||||||
this.classList.remove('error'); |
}); */ |
||||||
|
}; |
||||||
if(e.key == 'Enter') { |
|
||||||
return btnNext.click(); |
const page = new Page('page-password', true, onFirstMount); |
||||||
} |
|
||||||
}); |
export default page; |
||||||
|
|
||||||
/* passwordInput.addEventListener('input', function(this, e) { |
|
||||||
|
|
||||||
}); */ |
|
||||||
}; |
|
@ -1,263 +1,255 @@ |
|||||||
import { putPreloader, formatPhoneNumber } from "./misc"; |
import { putPreloader, formatPhoneNumber } from "../components/misc"; |
||||||
import Scrollable from './scrollable'; |
import Scrollable from '../components/scrollable'; |
||||||
import {RichTextProcessor} from '../lib/richtextprocessor'; |
import {RichTextProcessor} from '../lib/richtextprocessor'; |
||||||
import * as Config from '../lib/config'; |
import * as Config from '../lib/config'; |
||||||
|
|
||||||
import { findUpTag } from "../lib/utils"; |
import { findUpTag } from "../lib/utils"; |
||||||
import pageAuthCode from "./pageAuthCode"; |
import pageAuthCode from "./pageAuthCode"; |
||||||
import apiManager from "../lib/mtproto/apiManager"; |
import apiManager from "../lib/mtproto/apiManager"; |
||||||
|
import Page from "./page"; |
||||||
let installed = false; |
|
||||||
|
type Country = { |
||||||
type Country = { |
name: string, |
||||||
name: string, |
code: string, |
||||||
code: string, |
phoneCode: string, |
||||||
phoneCode: string, |
pattern: string, |
||||||
pattern: string, |
emoji: string, |
||||||
emoji: string, |
li?: HTMLLIElement[] |
||||||
li?: HTMLLIElement[] |
}; |
||||||
}; |
|
||||||
|
//import _countries from '../countries_pretty.json';
|
||||||
//import _countries from '../countries_pretty.json';
|
let btnNext: HTMLButtonElement = null; |
||||||
|
|
||||||
export default () => { |
let onFirstMount = () => { |
||||||
//export default () => import('../countries.json').then(_countries => {
|
//const countries: Country[] = _countries.default.filter(c => c.emoji);
|
||||||
//let pageAuthCode = await import('./pageAuthCode');
|
const countries: Country[] = Config.Countries.filter(c => c.emoji).sort((a, b) => a.name.localeCompare(b.name)); |
||||||
//Array.from(document.querySelectorAll('body > .whole:not(.page-authCode)')).forEach(div => div.style.display = 'none');
|
|
||||||
const pageEl = document.body.getElementsByClassName('page-sign')[0] as HTMLDivElement; |
let lastCountrySelected = ''; |
||||||
pageEl.style.display = ''; |
|
||||||
|
var selectCountryCode = page.pageEl.querySelector('input[name="countryCode"]')! as HTMLInputElement; |
||||||
let btnNext = pageEl.querySelector('button'); |
var parent = selectCountryCode.parentElement; |
||||||
|
|
||||||
if(installed) { |
var wrapper = document.createElement('div'); |
||||||
btnNext.textContent = 'NEXT'; |
wrapper.classList.add('select-wrapper', 'z-depth-4'); |
||||||
btnNext.removeAttribute('disabled'); |
|
||||||
return; |
var list = document.createElement('ul'); |
||||||
} |
wrapper.appendChild(list); |
||||||
|
|
||||||
installed = true; |
//let wrapperScroll = OverlayScrollbars(wrapper, (window as any).scrollbarOptions);
|
||||||
|
let scroll = new Scrollable(wrapper); |
||||||
//const countries: Country[] = _countries.default.filter(c => c.emoji);
|
|
||||||
const countries: Country[] = Config.Countries.filter(c => c.emoji).sort((a, b) => a.name.localeCompare(b.name)); |
let initedSelect = false; |
||||||
|
|
||||||
let lastCountrySelected = ''; |
selectCountryCode.addEventListener('focus', function(this: typeof selectCountryCode, e) { |
||||||
|
/* this.removeAttribute('readonly'); */ |
||||||
var selectCountryCode = pageEl.querySelector('input[name="countryCode"]')! as HTMLInputElement; |
if(!initedSelect) { |
||||||
var parent = selectCountryCode.parentElement; |
countries.forEach((c) => { |
||||||
|
initedSelect = true; |
||||||
var wrapper = document.createElement('div'); |
|
||||||
wrapper.classList.add('select-wrapper', 'z-depth-4'); |
/* let unified = unifiedCountryCodeEmoji(c.code); |
||||||
|
let emoji = unified.split('-').reduce((prev, curr) => prev + String.fromCodePoint(parseInt(curr, 16)), ''); */ |
||||||
var list = document.createElement('ul'); |
//let emoji = countryCodeEmoji(c.code);
|
||||||
wrapper.appendChild(list); |
let emoji = c.emoji; |
||||||
|
|
||||||
//let wrapperScroll = OverlayScrollbars(wrapper, (window as any).scrollbarOptions);
|
let liArr: Array<HTMLLIElement> = []; |
||||||
let scroll = new Scrollable(wrapper); |
c.phoneCode.split(' and ').forEach((phoneCode: string) => { |
||||||
|
let li = document.createElement('li'); |
||||||
let initedSelect = false; |
var spanEmoji = document.createElement('span'); |
||||||
|
/* spanEmoji.innerHTML = countryCodeEmoji(c.code); */ |
||||||
selectCountryCode.addEventListener('focus', function(this: typeof selectCountryCode, e) { |
//spanEmoji.classList.add('emoji-outer', 'emoji-sizer');
|
||||||
/* this.removeAttribute('readonly'); */ |
//spanEmoji.innerHTML = `<span class="emoji-inner" style="background: url(${sheetUrl}${sheetNo}.png);background-position:${xPos}% ${yPos}%;background-size:${sizeX}% ${sizeY}%" data-codepoints="${unified}"></span>`;
|
||||||
if(!initedSelect) { |
|
||||||
countries.forEach((c) => { |
|
||||||
initedSelect = true; |
|
||||||
|
let kek = RichTextProcessor.wrapRichText(emoji); |
||||||
/* let unified = unifiedCountryCodeEmoji(c.code); |
//console.log(c.name, emoji, kek, spanEmoji.innerHTML);
|
||||||
let emoji = unified.split('-').reduce((prev, curr) => prev + String.fromCodePoint(parseInt(curr, 16)), ''); */ |
|
||||||
//let emoji = countryCodeEmoji(c.code);
|
li.appendChild(spanEmoji); |
||||||
let emoji = c.emoji; |
spanEmoji.outerHTML = kek; |
||||||
|
|
||||||
let liArr: Array<HTMLLIElement> = []; |
li.append(c.name); |
||||||
c.phoneCode.split(' and ').forEach((phoneCode: string) => { |
|
||||||
let li = document.createElement('li'); |
var span = document.createElement('span'); |
||||||
var spanEmoji = document.createElement('span'); |
span.classList.add('phone-code'); |
||||||
/* spanEmoji.innerHTML = countryCodeEmoji(c.code); */ |
span.innerText = '+' + phoneCode; |
||||||
//spanEmoji.classList.add('emoji-outer', 'emoji-sizer');
|
li.appendChild(span); |
||||||
//spanEmoji.innerHTML = `<span class="emoji-inner" style="background: url(${sheetUrl}${sheetNo}.png);background-position:${xPos}% ${yPos}%;background-size:${sizeX}% ${sizeY}%" data-codepoints="${unified}"></span>`;
|
|
||||||
|
liArr.push(li); |
||||||
|
list.append(li); |
||||||
|
}); |
||||||
let kek = RichTextProcessor.wrapRichText(emoji); |
|
||||||
//console.log(c.name, emoji, kek, spanEmoji.innerHTML);
|
c.li = liArr; |
||||||
|
}); |
||||||
li.appendChild(spanEmoji); |
|
||||||
spanEmoji.outerHTML = kek; |
list.addEventListener('mousedown', function(e) { |
||||||
|
let target = e.target as HTMLElement; |
||||||
li.append(c.name); |
if(target.tagName != 'LI') target = findUpTag(target, 'LI'); |
||||||
|
|
||||||
var span = document.createElement('span'); |
let countryName = target.childNodes[1].textContent;//target.innerText.split('\n').shift();
|
||||||
span.classList.add('phone-code'); |
let phoneCode = target.querySelector<HTMLElement>('.phone-code').innerText; |
||||||
span.innerText = '+' + phoneCode; |
|
||||||
li.appendChild(span); |
selectCountryCode.value = countryName; |
||||||
|
lastCountrySelected = countryName; |
||||||
liArr.push(li); |
|
||||||
list.append(li); |
telEl.value = phoneCode; |
||||||
}); |
setTimeout(() => telEl.focus(), 0); |
||||||
|
console.log('clicked', e, countryName, phoneCode); |
||||||
c.li = liArr; |
}); |
||||||
}); |
} |
||||||
|
|
||||||
list.addEventListener('mousedown', function(e) { |
parent.appendChild(wrapper); |
||||||
let target = e.target as HTMLElement; |
}/* , {once: true} */); |
||||||
if(target.tagName != 'LI') target = findUpTag(target, 'LI'); |
selectCountryCode.addEventListener('blur', function(this: typeof selectCountryCode, e) { |
||||||
|
parent.removeChild(wrapper); |
||||||
let countryName = target.childNodes[1].textContent;//target.innerText.split('\n').shift();
|
e.cancelBubble = true; |
||||||
let phoneCode = target.querySelector<HTMLElement>('.phone-code').innerText; |
}, {capture: true}); |
||||||
|
|
||||||
selectCountryCode.value = countryName; |
selectCountryCode.addEventListener('keyup', function(this: typeof selectCountryCode, e) { |
||||||
lastCountrySelected = countryName; |
if(e.ctrlKey || e.key == 'Control') return false; |
||||||
|
|
||||||
telEl.value = phoneCode; |
//let i = new RegExp('^' + this.value, 'i');
|
||||||
setTimeout(() => telEl.focus(), 0); |
let _value = this.value.toLowerCase(); |
||||||
console.log('clicked', e, countryName, phoneCode); |
let matches: Country[] = []; |
||||||
}); |
countries.forEach((c) => { |
||||||
} |
let good = c.name.toLowerCase().indexOf(_value) !== -1/* == 0 */;//i.test(c.name);
|
||||||
|
|
||||||
parent.appendChild(wrapper); |
c.li.forEach(li => li.style.display = good ? '' : 'none'); |
||||||
}/* , {once: true} */); |
if(good) matches.push(c); |
||||||
selectCountryCode.addEventListener('blur', function(this: typeof selectCountryCode, e) { |
}); |
||||||
parent.removeChild(wrapper); |
|
||||||
e.cancelBubble = true; |
if(matches.length == 1 && matches[0].li.length == 1) { |
||||||
}, {capture: true}); |
if(matches[0].name == lastCountrySelected) return false; |
||||||
|
console.log('clicking', matches[0]); |
||||||
selectCountryCode.addEventListener('keyup', function(this: typeof selectCountryCode, e) { |
|
||||||
if(e.ctrlKey || e.key == 'Control') return false; |
var clickEvent = document.createEvent('MouseEvents'); |
||||||
|
clickEvent.initEvent('mousedown', true, true); |
||||||
//let i = new RegExp('^' + this.value, 'i');
|
matches[0].li[0].dispatchEvent(clickEvent); |
||||||
let _value = this.value.toLowerCase(); |
return false; |
||||||
let matches: Country[] = []; |
} else if(matches.length == 0) { |
||||||
countries.forEach((c) => { |
countries.forEach((c) => { |
||||||
let good = c.name.toLowerCase().indexOf(_value) !== -1/* == 0 */;//i.test(c.name);
|
c.li.forEach(li => li.style.display = ''); |
||||||
|
}); |
||||||
c.li.forEach(li => li.style.display = good ? '' : 'none'); |
} |
||||||
if(good) matches.push(c); |
}); |
||||||
}); |
|
||||||
|
let arrowDown = page.pageEl.querySelector('.arrow-down') as HTMLSpanElement; |
||||||
if(matches.length == 1 && matches[0].li.length == 1) { |
arrowDown.addEventListener('mousedown', function(this: typeof arrowDown, e) { |
||||||
if(matches[0].name == lastCountrySelected) return false; |
e.cancelBubble = true; |
||||||
console.log('clicking', matches[0]); |
e.preventDefault(); |
||||||
|
if(selectCountryCode.matches(':focus')) selectCountryCode.blur(); |
||||||
var clickEvent = document.createEvent('MouseEvents'); |
else selectCountryCode.focus(); |
||||||
clickEvent.initEvent('mousedown', true, true); |
}); |
||||||
matches[0].li[0].dispatchEvent(clickEvent); |
|
||||||
return false; |
let sortedCountries = countries.slice().sort((a, b) => b.phoneCode.length - a.phoneCode.length); |
||||||
} else if(matches.length == 0) { |
|
||||||
countries.forEach((c) => { |
let telEl = page.pageEl.querySelector('input[name="phone"]') as HTMLInputElement; |
||||||
c.li.forEach(li => li.style.display = ''); |
telEl.addEventListener('input', function(this: typeof telEl, e) { |
||||||
}); |
this.classList.remove('error'); |
||||||
} |
|
||||||
}); |
let {formatted, country} = formatPhoneNumber(this.value); |
||||||
|
this.value = formatted ? '+' + formatted : ''; |
||||||
let arrowDown = pageEl.querySelector('.arrow-down') as HTMLSpanElement; |
|
||||||
arrowDown.addEventListener('mousedown', function(this: typeof arrowDown, e) { |
console.log(formatted, country); |
||||||
e.cancelBubble = true; |
|
||||||
e.preventDefault(); |
let countryName = country ? country.name : ''/* 'Unknown' */; |
||||||
if(selectCountryCode.matches(':focus')) selectCountryCode.blur(); |
if(countryName != selectCountryCode.value) { |
||||||
else selectCountryCode.focus(); |
selectCountryCode.value = countryName; |
||||||
}); |
lastCountrySelected = countryName; |
||||||
|
} |
||||||
let sortedCountries = countries.slice().sort((a, b) => b.phoneCode.length - a.phoneCode.length); |
|
||||||
|
if(country && (this.value.length - 1) >= (country.pattern ? country.pattern.length : 9)) { |
||||||
let telEl = pageEl.querySelector('input[name="phone"]') as HTMLInputElement; |
btnNext.style.visibility = ''; |
||||||
telEl.addEventListener('input', function(this: typeof telEl, e) { |
} else { |
||||||
this.classList.remove('error'); |
btnNext.style.visibility = 'hidden'; |
||||||
|
} |
||||||
let {formatted, country} = formatPhoneNumber(this.value); |
}); |
||||||
this.value = formatted ? '+' + formatted : ''; |
|
||||||
|
telEl.addEventListener('keypress', function(this: typeof telEl, e) { |
||||||
console.log(formatted, country); |
if(this.value.length >= 9 && e.key == 'Enter') { |
||||||
|
return btnNext.click(); |
||||||
let countryName = country ? country.name : ''/* 'Unknown' */; |
} else if(/\D/.test(e.key)) { |
||||||
if(countryName != selectCountryCode.value) { |
e.preventDefault(); |
||||||
selectCountryCode.value = countryName; |
return false; |
||||||
lastCountrySelected = countryName; |
} |
||||||
} |
}); |
||||||
|
|
||||||
if(country && (this.value.length - 1) >= (country.pattern ? country.pattern.length : 9)) { |
/* telEl.addEventListener('focus', function(this: typeof telEl, e) { |
||||||
btnNext.style.visibility = ''; |
this.removeAttribute('readonly'); // fix autocomplete
|
||||||
} else { |
});*/ |
||||||
btnNext.style.visibility = 'hidden'; |
|
||||||
} |
/* authorizer.auth(2); |
||||||
}); |
networkerFactory.startAll(); */ |
||||||
|
|
||||||
telEl.addEventListener('keypress', function(this: typeof telEl, e) { |
btnNext.addEventListener('click', function(this: HTMLElement, e) { |
||||||
if(this.value.length >= 9 && e.key == 'Enter') { |
this.setAttribute('disabled', 'true'); |
||||||
return btnNext.click(); |
|
||||||
} else if(/\D/.test(e.key)) { |
this.textContent = 'PLEASE WAIT...'; |
||||||
e.preventDefault(); |
putPreloader(this); |
||||||
return false; |
//this.innerHTML = 'PLEASE WAIT...';
|
||||||
} |
|
||||||
}); |
let phone_number = telEl.value; |
||||||
|
apiManager.invokeApi('auth.sendCode', { |
||||||
/* telEl.addEventListener('focus', function(this: typeof telEl, e) { |
/* flags: 0, */ |
||||||
this.removeAttribute('readonly'); // fix autocomplete
|
phone_number: phone_number, |
||||||
});*/ |
api_id: Config.App.id, |
||||||
|
api_hash: Config.App.hash, |
||||||
/* authorizer.auth(2); |
settings: { |
||||||
networkerFactory.startAll(); */ |
_: 'codeSettings', // that's how we sending Type
|
||||||
|
flags: 0 |
||||||
btnNext.addEventListener('click', function(this: HTMLElement, e) { |
} |
||||||
this.setAttribute('disabled', 'true'); |
/* lang_code: navigator.language || 'en' */ |
||||||
|
}).then((code: any) => { |
||||||
this.textContent = 'PLEASE WAIT...'; |
console.log('got code', code); |
||||||
putPreloader(this); |
|
||||||
//this.innerHTML = 'PLEASE WAIT...';
|
pageAuthCode.mount(Object.assign(code, {phone_number: phone_number})); |
||||||
|
}).catch(err => { |
||||||
let phone_number = telEl.value; |
this.removeAttribute('disabled'); |
||||||
apiManager.invokeApi('auth.sendCode', { |
|
||||||
/* flags: 0, */ |
this.innerText = 'NEXT'; |
||||||
phone_number: phone_number, |
switch(err.type) { |
||||||
api_id: Config.App.id, |
case 'PHONE_NUMBER_INVALID': |
||||||
api_hash: Config.App.hash, |
telEl.classList.add('error'); |
||||||
settings: { |
break; |
||||||
_: 'codeSettings', // that's how we sending Type
|
default: |
||||||
flags: 0 |
console.error('auth.sendCode error:', err); |
||||||
} |
this.innerText = err.type; |
||||||
/* lang_code: navigator.language || 'en' */ |
break; |
||||||
}).then((code: any) => { |
} |
||||||
console.log('got code', code); |
}); |
||||||
|
}); |
||||||
pageEl.style.display = 'none'; |
|
||||||
|
let tryAgain = () => { |
||||||
// @ts-ignore
|
apiManager.invokeApi('help.getNearestDc').then((nearestDcResult: any) => { |
||||||
pageAuthCode(Object.assign(code, {phone_number: phone_number})); |
if(nearestDcResult.nearest_dc != nearestDcResult.this_dc) { |
||||||
}).catch(err => { |
//MTProto.apiManager.baseDcID = nearestDcResult.nearest_dc;
|
||||||
this.removeAttribute('disabled'); |
apiManager.getNetworker(nearestDcResult.nearest_dc); |
||||||
|
} |
||||||
this.innerText = 'NEXT'; |
|
||||||
switch(err.type) { |
return nearestDcResult; |
||||||
case 'PHONE_NUMBER_INVALID': |
}).then((nearestDcResult: any) => { |
||||||
telEl.classList.add('error'); |
let country = countries.find((c) => c.code == nearestDcResult.country); |
||||||
break; |
if(country) { |
||||||
default: |
if(!selectCountryCode.value.length && !telEl.value.length) { |
||||||
this.innerText = err.type; |
selectCountryCode.value = country.name; |
||||||
break; |
lastCountrySelected = country.name; |
||||||
} |
telEl.value = '+' + country.phoneCode.split(' and ').shift(); |
||||||
}); |
} |
||||||
}); |
} |
||||||
|
|
||||||
let tryAgain = () => { |
return console.log('woohoo', nearestDcResult, country); |
||||||
apiManager.invokeApi('help.getNearestDc').then((nearestDcResult: any) => { |
})//.catch(tryAgain);
|
||||||
if(nearestDcResult.nearest_dc != nearestDcResult.this_dc) { |
}; |
||||||
//MTProto.apiManager.baseDcID = nearestDcResult.nearest_dc;
|
|
||||||
apiManager.getNetworker(nearestDcResult.nearest_dc); |
tryAgain(); |
||||||
} |
}; |
||||||
|
|
||||||
return nearestDcResult; |
const page = new Page('page-sign', true, onFirstMount, () => { |
||||||
}).then((nearestDcResult: any) => { |
if(!btnNext) { |
||||||
let country = countries.find((c) => c.code == nearestDcResult.country); |
btnNext = page.pageEl.querySelector('button'); |
||||||
if(country) { |
} |
||||||
if(!selectCountryCode.value.length && !telEl.value.length) { |
|
||||||
selectCountryCode.value = country.name; |
btnNext.textContent = 'NEXT'; |
||||||
lastCountrySelected = country.name; |
btnNext.removeAttribute('disabled'); |
||||||
telEl.value = '+' + country.phoneCode.split(' and ').shift(); |
}); |
||||||
} |
|
||||||
} |
export default page; |
||||||
|
|
||||||
return console.log('woohoo', nearestDcResult, country); |
|
||||||
})//.catch(tryAgain);
|
|
||||||
}; |
|
||||||
|
|
||||||
tryAgain(); |
|
||||||
|
|
||||||
}; |
|
@ -1,198 +1,195 @@ |
|||||||
import {putPreloader} from './misc'; |
import {putPreloader} from '../components/misc'; |
||||||
|
import resizeableImage from '../lib/cropper'; |
||||||
let installed = false; |
import pageIm from './pageIm'; |
||||||
let authCode: { |
import apiManager from '../lib/mtproto/apiManager'; |
||||||
'phone_number': string, |
import apiFileManager from '../lib/mtproto/apiFileManager'; |
||||||
'phone_code_hash': string |
import Page from './page'; |
||||||
} = null; |
|
||||||
|
let authCode: { |
||||||
import resizeableImage from '../lib/cropper'; |
'phone_number': string, |
||||||
import pageIm from './pageIm'; |
'phone_code_hash': string |
||||||
import apiManager from '../lib/mtproto/apiManager'; |
} = null; |
||||||
import apiFileManager from '../lib/mtproto/apiFileManager'; |
|
||||||
|
let onFirstMount = () => { |
||||||
export default (_authCode: typeof authCode) => { |
const pageElement = page.pageEl; |
||||||
authCode = _authCode; |
const avatarInput = document.getElementById('avatar-input') as HTMLInputElement; |
||||||
if(installed) return; |
const avatarPopup = pageElement.getElementsByClassName('popup-avatar')[0]; |
||||||
installed = true; |
const avatarPreview = pageElement.querySelector('#canvas-avatar') as HTMLCanvasElement; |
||||||
|
const cropContainer = avatarPopup.getElementsByClassName('crop')[0]; |
||||||
let pageElement = document.body.getElementsByClassName('page-signUp')[0] as HTMLDivElement; |
let avatarImage = new Image(); |
||||||
pageElement.style.display = ''; |
cropContainer.append(avatarImage); |
||||||
|
|
||||||
const avatarInput = document.getElementById('avatar-input') as HTMLInputElement; |
let avatarBlob: Blob; |
||||||
const avatarPopup = pageElement.getElementsByClassName('popup-avatar')[0]; |
|
||||||
const avatarPreview = pageElement.querySelector('#canvas-avatar') as HTMLCanvasElement; |
(avatarPopup.getElementsByClassName('popup-close')[0] as HTMLButtonElement) |
||||||
const cropContainer = avatarPopup.getElementsByClassName('crop')[0]; |
.addEventListener('click', function(this, e) { |
||||||
let avatarImage = new Image(); |
/* let popup = findUpClassName(this, 'popup'); |
||||||
cropContainer.append(avatarImage); |
popup.classList.remove('active'); */ |
||||||
|
|
||||||
let avatarBlob: Blob; |
setTimeout(() => { |
||||||
|
cropper.removeHandlers(); |
||||||
(avatarPopup.getElementsByClassName('popup-close')[0] as HTMLButtonElement) |
if(avatarImage) { |
||||||
.addEventListener('click', function(this, e) { |
avatarImage.remove(); |
||||||
/* let popup = findUpClassName(this, 'popup'); |
} |
||||||
popup.classList.remove('active'); */ |
}, 200); |
||||||
|
|
||||||
setTimeout(() => { |
/* e.cancelBubble = true; |
||||||
cropper.removeHandlers(); |
return false; */ |
||||||
if(avatarImage) { |
}); |
||||||
avatarImage.remove(); |
|
||||||
} |
let cropper = { |
||||||
}, 200); |
crop: () => {}, |
||||||
|
removeHandlers: () => {} |
||||||
/* e.cancelBubble = true; |
}; |
||||||
return false; */ |
|
||||||
}); |
// apply
|
||||||
|
avatarPopup.getElementsByClassName('btn-crop')[0].addEventListener('click', () => { |
||||||
let cropper = { |
cropper.crop(); |
||||||
crop: () => {}, |
avatarPopup.classList.remove('active'); |
||||||
removeHandlers: () => {} |
cropper.removeHandlers(); |
||||||
}; |
|
||||||
|
avatarPreview.toBlob(blob => { |
||||||
// apply
|
avatarBlob = blob; // save blob to send after reg
|
||||||
avatarPopup.getElementsByClassName('btn-crop')[0].addEventListener('click', () => { |
|
||||||
cropper.crop(); |
// darken
|
||||||
avatarPopup.classList.remove('active'); |
let ctx = avatarPreview.getContext('2d'); |
||||||
cropper.removeHandlers(); |
ctx.fillStyle = "rgba(0, 0, 0, 0.3)"; |
||||||
|
ctx.fillRect(0, 0, avatarPreview.width, avatarPreview.height); |
||||||
avatarPreview.toBlob(blob => { |
}, 'image/jpeg', 1); |
||||||
avatarBlob = blob; // save blob to send after reg
|
|
||||||
|
avatarImage.remove(); |
||||||
// darken
|
}); |
||||||
let ctx = avatarPreview.getContext('2d'); |
|
||||||
ctx.fillStyle = "rgba(0, 0, 0, 0.3)"; |
avatarInput.addEventListener('change', (e: any) => { |
||||||
ctx.fillRect(0, 0, avatarPreview.width, avatarPreview.height); |
var file = e.target.files[0]; |
||||||
}, 'image/jpeg', 1); |
if(!file) { |
||||||
|
return; |
||||||
avatarImage.remove(); |
} |
||||||
}); |
|
||||||
|
var reader = new FileReader(); |
||||||
avatarInput.addEventListener('change', (e: any) => { |
reader.onload = (e) => { |
||||||
var file = e.target.files[0]; |
var contents = e.target.result as string; |
||||||
if(!file) { |
|
||||||
return; |
avatarImage = new Image(); |
||||||
} |
cropContainer.append(avatarImage); |
||||||
|
avatarImage.src = contents; |
||||||
var reader = new FileReader(); |
|
||||||
reader.onload = (e) => { |
avatarImage.onload = () => { |
||||||
var contents = e.target.result as string; |
cropper = resizeableImage(avatarImage, avatarPreview); |
||||||
|
avatarInput.value = ''; |
||||||
avatarImage = new Image(); |
}; |
||||||
cropContainer.append(avatarImage); |
|
||||||
avatarImage.src = contents; |
avatarPopup.classList.add('active'); |
||||||
|
}; |
||||||
avatarImage.onload = () => { |
|
||||||
cropper = resizeableImage(avatarImage, avatarPreview); |
reader.readAsDataURL(file); |
||||||
avatarInput.value = ''; |
}, false); |
||||||
}; |
|
||||||
|
pageElement.querySelector('.auth-image').addEventListener('click', () => { |
||||||
avatarPopup.classList.add('active'); |
avatarInput.click(); |
||||||
}; |
}); |
||||||
|
|
||||||
reader.readAsDataURL(file); |
const headerName = pageElement.getElementsByClassName('fullName')[0] as HTMLHeadingElement; |
||||||
}, false); |
|
||||||
|
let handleInput = function(this: typeof fieldName, e: Event) { |
||||||
pageElement.querySelector('.auth-image').addEventListener('click', () => { |
let name = fieldName.value || ''; |
||||||
avatarInput.click(); |
let lastName = fieldLastName.value || ''; |
||||||
}); |
|
||||||
|
let fullName = name || lastName |
||||||
const headerName = pageElement.getElementsByClassName('fullName')[0] as HTMLHeadingElement; |
? (name + ' ' + lastName).trim() |
||||||
|
: 'Your Name'; |
||||||
let handleInput = function(this: typeof fieldName, e: Event) { |
|
||||||
let name = fieldName.value || ''; |
if(headerName.innerText != fullName) headerName.innerText = fullName; |
||||||
let lastName = fieldLastName.value || ''; |
this.classList.remove('error'); |
||||||
|
}; |
||||||
let fullName = name || lastName |
|
||||||
? (name + ' ' + lastName).trim() |
let sendAvatar = () => new Promise((resolve, reject) => { |
||||||
: 'Your Name'; |
if(!avatarBlob) { |
||||||
|
console.log('User has not selected avatar'); |
||||||
if(headerName.innerText != fullName) headerName.innerText = fullName; |
return resolve(); |
||||||
this.classList.remove('error'); |
} |
||||||
}; |
|
||||||
|
console.log('invoking uploadFile...'); |
||||||
let sendAvatar = () => new Promise((resolve, reject) => { |
apiFileManager.uploadFile(avatarBlob).then((inputFile: any) => { |
||||||
if(!avatarBlob) { |
console.log('uploaded smthn', inputFile); |
||||||
console.log('User has not selected avatar'); |
|
||||||
return resolve(); |
apiManager.invokeApi('photos.uploadProfilePhoto', { |
||||||
} |
file: inputFile |
||||||
|
}).then((updateResult) => { |
||||||
console.log('invoking uploadFile...'); |
console.log('updated photo!'); |
||||||
apiFileManager.uploadFile(avatarBlob).then((inputFile: any) => { |
resolve(); |
||||||
console.log('uploaded smthn', inputFile); |
}, reject); |
||||||
|
}, reject); |
||||||
apiManager.invokeApi('photos.uploadProfilePhoto', { |
}); |
||||||
file: inputFile |
|
||||||
}).then((updateResult) => { |
const fieldName = document.getElementById('name') as HTMLInputElement; |
||||||
console.log('updated photo!'); |
fieldName.addEventListener('input', handleInput); |
||||||
resolve(); |
|
||||||
}, reject); |
const fieldLastName = document.getElementById('lastName') as HTMLInputElement; |
||||||
}, reject); |
fieldLastName.addEventListener('input', handleInput); |
||||||
}); |
|
||||||
|
const signUpButton = document.getElementById('signUp') as HTMLButtonElement; |
||||||
const fieldName = document.getElementById('name') as HTMLInputElement; |
signUpButton.addEventListener('click', function(this: typeof signUpButton, e) { |
||||||
fieldName.addEventListener('input', handleInput); |
this.setAttribute('disabled', 'true'); |
||||||
|
|
||||||
const fieldLastName = document.getElementById('lastName') as HTMLInputElement; |
if(!fieldName.value.length) { |
||||||
fieldLastName.addEventListener('input', handleInput); |
fieldName.classList.add('error'); |
||||||
|
return false; |
||||||
const signUpButton = document.getElementById('signUp') as HTMLButtonElement; |
} |
||||||
signUpButton.addEventListener('click', function(this: typeof signUpButton, e) { |
|
||||||
this.setAttribute('disabled', 'true'); |
let name = fieldName.value; |
||||||
|
let lastName = fieldLastName.value; |
||||||
if(!fieldName.value.length) { |
|
||||||
fieldName.classList.add('error'); |
let params = { |
||||||
return false; |
'phone_number': authCode.phone_number, |
||||||
} |
'phone_code_hash': authCode.phone_code_hash, |
||||||
|
'first_name': name, |
||||||
let name = fieldName.value; |
'last_name': lastName |
||||||
let lastName = fieldLastName.value; |
}; |
||||||
|
|
||||||
let params = { |
console.log('invoking auth.signUp with params:', params); |
||||||
'phone_number': authCode.phone_number, |
|
||||||
'phone_code_hash': authCode.phone_code_hash, |
this.textContent = 'PLEASE WAIT...'; |
||||||
'first_name': name, |
putPreloader(this); |
||||||
'last_name': lastName |
|
||||||
}; |
apiManager.invokeApi('auth.signUp', params) |
||||||
|
.then((response: any) => { |
||||||
console.log('invoking auth.signUp with params:', params); |
console.log('auth.signUp response:', response); |
||||||
|
|
||||||
this.textContent = 'PLEASE WAIT...'; |
switch(response._) { |
||||||
putPreloader(this); |
case 'auth.authorization': // success
|
||||||
|
apiManager.setUserAuth({ // warning
|
||||||
apiManager.invokeApi('auth.signUp', params) |
id: response.user.id |
||||||
.then((response: any) => { |
}); |
||||||
console.log('auth.signUp response:', response); |
|
||||||
|
sendAvatar().then(() => { |
||||||
switch(response._) { |
pageIm.mount(); |
||||||
case 'auth.authorization': // success
|
}, () => { |
||||||
apiManager.setUserAuth({ // warning
|
pageIm.mount(); |
||||||
id: response.user.id |
}); |
||||||
}); |
|
||||||
|
break; |
||||||
sendAvatar().then(() => { |
default: |
||||||
pageElement.style.display = 'none'; |
this.innerText = response._; |
||||||
pageIm(); |
break; |
||||||
}, () => { |
} |
||||||
pageElement.style.display = 'none'; |
|
||||||
pageIm(); |
/* (document.body.getElementsByClassName('page-sign')[0] as HTMLDivElement).style.display = 'none'; |
||||||
}); |
pageAuthCode(Object.assign(code, {phoneNumber})); */ |
||||||
|
}).catch(err => { |
||||||
break; |
this.removeAttribute('disabled'); |
||||||
default: |
|
||||||
this.innerText = response._; |
switch(err.type) { |
||||||
break; |
default: |
||||||
} |
this.innerText = err.type; |
||||||
|
break; |
||||||
/* (document.body.getElementsByClassName('page-sign')[0] as HTMLDivElement).style.display = 'none'; |
} |
||||||
pageAuthCode(Object.assign(code, {phoneNumber})); */ |
}); |
||||||
}).catch(err => { |
}); |
||||||
this.removeAttribute('disabled'); |
}; |
||||||
|
|
||||||
switch(err.type) { |
const page = new Page('page-signUp', true, onFirstMount, (_authCode: typeof authCode) => { |
||||||
default: |
authCode = _authCode; |
||||||
this.innerText = err.type; |
}); |
||||||
break; |
|
||||||
} |
export default page; |
||||||
}); |
|
||||||
}); |
|
||||||
}; |
|
@ -0,0 +1,37 @@ |
|||||||
|
import Page from "./page"; |
||||||
|
import { whichChild } from "../lib/utils"; |
||||||
|
import { horizontalMenu } from "../components/misc"; |
||||||
|
|
||||||
|
class PagesManager { |
||||||
|
private pageID = -1; |
||||||
|
|
||||||
|
private selectTab: ReturnType<typeof horizontalMenu>; |
||||||
|
public pagesDiv: HTMLDivElement; |
||||||
|
|
||||||
|
constructor() { |
||||||
|
this.pagesDiv = document.getElementById('auth-pages') as HTMLDivElement; |
||||||
|
this.selectTab = horizontalMenu(null, this.pagesDiv.firstElementChild as HTMLDivElement, null, null, 420); |
||||||
|
} |
||||||
|
|
||||||
|
public setPage(page: Page) { |
||||||
|
if(page.isAuthPage) { |
||||||
|
this.pagesDiv.style.display = ''; |
||||||
|
|
||||||
|
let id = whichChild(page.pageEl); |
||||||
|
if(this.pageID == id) return; |
||||||
|
|
||||||
|
this.selectTab(id); |
||||||
|
|
||||||
|
this.pageID = id; |
||||||
|
} else { |
||||||
|
this.pagesDiv.style.display = 'none'; |
||||||
|
page.pageEl.style.display = ''; |
||||||
|
|
||||||
|
this.pageID = -1; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
const pagesManager = new PagesManager(); |
||||||
|
(window as any).pagesManager = pagesManager; |
||||||
|
export default pagesManager; |
Loading…
Reference in new issue