Browse Source

Fix countries with same phone codes by main

master
morethanwords 4 years ago
parent
commit
526ad72267
  1. 3
      src/components/chat/contextMenu.ts
  2. 3
      src/components/dialogsContextMenu.ts
  3. 32
      src/components/misc.ts
  4. 25
      src/components/popup.ts
  5. 27
      src/components/popupPeer.ts
  6. 44
      src/countries.ts
  7. 7
      src/lib/config.ts
  8. 14
      src/pages/pageSignIn.ts

3
src/components/chat/contextMenu.ts

@ -7,7 +7,8 @@ import $rootScope from "../../lib/rootScope";
import { findUpClassName } from "../../lib/utils"; import { findUpClassName } from "../../lib/utils";
import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu"; import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu";
import { attachContextMenuListener, openBtnMenu, positionMenu } from "../misc"; import { attachContextMenuListener, openBtnMenu, positionMenu } from "../misc";
import { PopupButton, PopupPeer } from "../popup"; import { PopupButton } from "../popup";
import PopupPeer from "../popupPeer";
import appSidebarRight from "../sidebarRight"; import appSidebarRight from "../sidebarRight";
export class ChatContextMenu { export class ChatContextMenu {

3
src/components/dialogsContextMenu.ts

@ -6,7 +6,8 @@ import appPeersManager from "../lib/appManagers/appPeersManager";
import $rootScope from "../lib/rootScope"; import $rootScope from "../lib/rootScope";
import { findUpTag } from "../lib/utils"; import { findUpTag } from "../lib/utils";
import { parseMenuButtonsTo, positionMenu, openBtnMenu } from "./misc"; import { parseMenuButtonsTo, positionMenu, openBtnMenu } from "./misc";
import { PopupButton, PopupPeer } from "./popup"; import { PopupButton } from "./popup";
import PopupPeer from "./popupPeer";
export default class DialogsContextMenu { export default class DialogsContextMenu {
private element = document.getElementById('dialogs-contextmenu') as HTMLDivElement; private element = document.getElementById('dialogs-contextmenu') as HTMLDivElement;

32
src/components/misc.ts

@ -1,7 +1,7 @@
import Countries, { Country, PhoneCodesMain } from "../countries";
import mediaSizes from "../helpers/mediaSizes"; import mediaSizes from "../helpers/mediaSizes";
import { isTouchSupported } from "../helpers/touchSupport"; import { isTouchSupported } from "../helpers/touchSupport";
import { isApple } from "../helpers/userAgent"; import { isApple } from "../helpers/userAgent";
import Config from "../lib/config";
export const loadedURLs: {[url: string]: boolean} = {}; export const loadedURLs: {[url: string]: boolean} = {};
const set = (elem: HTMLElement | HTMLImageElement | SVGImageElement | HTMLVideoElement, url: string) => { const set = (elem: HTMLElement | HTMLImageElement | SVGImageElement | HTMLVideoElement, url: string) => {
@ -61,30 +61,34 @@ export function putPreloader(elem: Element, returnDiv = false) {
elem.innerHTML += html; elem.innerHTML += html;
} }
let sortedCountries: Country[];
export function formatPhoneNumber(str: string) { export function formatPhoneNumber(str: string) {
str = str.replace(/\D/g, ''); str = str.replace(/\D/g, '');
let phoneCode = str.slice(0, 6); let phoneCode = str.slice(0, 6);
////console.log('str', str, phoneCode); ////console.log('str', str, phoneCode);
if(!sortedCountries) {
let sortedCountries = Config.Countries.slice().sort((a, b) => b.phoneCode.length - a.phoneCode.length); sortedCountries = Countries.slice().sort((a, b) => b.phoneCode.length - a.phoneCode.length);
}
let country = sortedCountries.find((c) => { let country = sortedCountries.find((c) => {
return c.phoneCode.split(' and ').find((c) => phoneCode.indexOf(c.replace(/\D/g, '')) == 0); return c.phoneCode.split(' and ').find((c) => phoneCode.indexOf(c.replace(/\D/g, '')) == 0);
}); });
let pattern = country ? country.pattern || country.phoneCode : ''; if(!country) return {formatted: str, country};
if(country) {
pattern.split('').forEach((symbol, idx) => {
if(symbol == ' ' && str[idx] != ' ' && str.length > idx) {
str = str.slice(0, idx) + ' ' + str.slice(idx);
}
});
/* if(country.pattern) { country = PhoneCodesMain[country.phoneCode] || country;
str = str.slice(0, country.pattern.length);
} */ let pattern = country.pattern || country.phoneCode;
} pattern.split('').forEach((symbol, idx) => {
if(symbol == ' ' && str[idx] != ' ' && str.length > idx) {
str = str.slice(0, idx) + ' ' + str.slice(idx);
}
});
/* if(country.pattern) {
str = str.slice(0, country.pattern.length);
} */
return {formatted: str, country}; return {formatted: str, country};
} }

25
src/components/popup.ts

@ -118,28 +118,3 @@ export type PopupButton = {
isDanger?: true, isDanger?: true,
isCancel?: true isCancel?: true
}; };
export class PopupPeer extends PopupElement {
constructor(private className: string, options: Partial<{
peerID: number,
title: string,
description: string,
buttons: Array<PopupButton>
}> = {}) {
super('popup-peer' + (className ? ' ' + className : ''), options.buttons);
let avatarEl = new AvatarElement();
avatarEl.setAttribute('dialog', '1');
avatarEl.setAttribute('peer', '' + options.peerID);
avatarEl.classList.add('peer-avatar');
this.title.innerText = options.title || '';
this.header.prepend(avatarEl);
let p = document.createElement('p');
p.classList.add('popup-description');
p.innerHTML = options.description;
this.container.insertBefore(p, this.header.nextElementSibling);
}
}

27
src/components/popupPeer.ts

@ -0,0 +1,27 @@
import AvatarElement from "./avatar";
import { PopupElement, PopupButton } from "./popup";
export default class PopupPeer extends PopupElement {
constructor(private className: string, options: Partial<{
peerID: number,
title: string,
description: string,
buttons: Array<PopupButton>
}> = {}) {
super('popup-peer' + (className ? ' ' + className : ''), options.buttons);
let avatarEl = new AvatarElement();
avatarEl.setAttribute('dialog', '1');
avatarEl.setAttribute('peer', '' + options.peerID);
avatarEl.classList.add('peer-avatar');
this.title.innerText = options.title || '';
this.header.prepend(avatarEl);
let p = document.createElement('p');
p.classList.add('popup-description');
p.innerHTML = options.description;
this.container.insertBefore(p, this.header.nextElementSibling);
}
}

44
src/countries.ts

File diff suppressed because one or more lines are too long

7
src/lib/config.ts

File diff suppressed because one or more lines are too long

14
src/pages/pageSignIn.ts

@ -1,6 +1,6 @@
import { formatPhoneNumber, putPreloader } from "../components/misc"; import { formatPhoneNumber, putPreloader } from "../components/misc";
import Scrollable from '../components/scrollable'; import Scrollable from '../components/scrollable';
import Config from '../lib/config'; import Countries, { Country as _Country } from "../countries";
import apiManager from "../lib/mtproto/mtprotoworker"; import apiManager from "../lib/mtproto/mtprotoworker";
import { App, Modes } from "../lib/mtproto/mtproto_config"; import { App, Modes } from "../lib/mtproto/mtproto_config";
import { RichTextProcessor } from '../lib/richtextprocessor'; import { RichTextProcessor } from '../lib/richtextprocessor';
@ -9,13 +9,7 @@ import Page from "./page";
import pageAuthCode from "./pageAuthCode"; import pageAuthCode from "./pageAuthCode";
import pageSignQR from './pageSignQR'; import pageSignQR from './pageSignQR';
type Country = _Country & {
type Country = {
name: string,
code: string,
phoneCode: string,
pattern: string,
emoji: string,
li?: HTMLLIElement[] li?: HTMLLIElement[]
}; };
@ -24,7 +18,7 @@ let btnNext: HTMLButtonElement = null;
let onFirstMount = () => { let onFirstMount = () => {
if(Modes.test) { if(Modes.test) {
Config.Countries.push({ Countries.push({
name: 'Test Country', name: 'Test Country',
phoneCode: '999 66', phoneCode: '999 66',
code: 'TC', code: 'TC',
@ -36,7 +30,7 @@ let onFirstMount = () => {
} }
//const countries: Country[] = _countries.default.filter(c => c.emoji); //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)); const countries: Country[] = Countries.filter(c => c.emoji).sort((a, b) => a.name.localeCompare(b.name));
let lastCountrySelected: Country = null; let lastCountrySelected: Country = null;

Loading…
Cancel
Save