Browse Source

fixes

master
Eduard Kuzmenko 3 years ago
parent
commit
ec4cdcbb24
  1. 13
      src/components/languageChangeButton.ts
  2. 6
      src/lib/langPack.ts
  3. 30
      src/pages/pageSignIn.ts

13
src/components/languageChangeButton.ts

@ -14,15 +14,7 @@ import rootScope from "../lib/rootScope"; @@ -14,15 +14,7 @@ import rootScope from "../lib/rootScope";
import Button from "./button";
import { putPreloader } from "./misc";
let set = false, times = 0;
rootScope.addEventListener('language_change', () => {
if(++times < 2) {
return;
}
console.log('language_change');
set = true;
});
let set = false;
function getLang(): Promise<[Config.config, LangPackString[], LangPackDifference.langPackDifference]> {
if(cachedPromise) return cachedPromise;
@ -62,6 +54,7 @@ export default function getLanguageChangeButton(appendTo: HTMLElement) { @@ -62,6 +54,7 @@ export default function getLanguageChangeButton(appendTo: HTMLElement) {
});
const btnChangeLanguage = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: 'Login.ContinueOnLanguage'});
btnChangeLanguage.lastElementChild.classList.remove('i18n'); // prevent changing language
loadFonts().then(() => {
window.requestAnimationFrame(() => {
appendTo.append(btnChangeLanguage);
@ -79,6 +72,8 @@ export default function getLanguageChangeButton(appendTo: HTMLElement) { @@ -79,6 +72,8 @@ export default function getLanguageChangeButton(appendTo: HTMLElement) {
attachClickEvent(btnChangeLanguage, (e) => {
cancelEvent(e);
set = true;
btnChangeLanguage.disabled = true;
putPreloader(btnChangeLanguage);

6
src/lib/langPack.ts

@ -71,6 +71,7 @@ namespace I18n { @@ -71,6 +71,7 @@ namespace I18n {
let cacheLangPackPromise: Promise<LangPackDifference>;
export let lastRequestedLangCode: string;
export let lastAppliedLangCode: string;
export let requestedServerLanguage = false;
export function getCacheLangPack(): Promise<LangPackDifference> {
if(cacheLangPackPromise) return cacheLangPackPromise;
@ -247,7 +248,10 @@ namespace I18n { @@ -247,7 +248,10 @@ namespace I18n {
});
}
rootScope.dispatchEvent('language_change', langPack.lang_code);
if(lastAppliedLangCode !== langPack.lang_code) {
rootScope.dispatchEvent('language_change', langPack.lang_code);
lastAppliedLangCode = langPack.lang_code;
}
const elements = Array.from(document.querySelectorAll(`.i18n`)) as HTMLElement[];
elements.forEach(element => {

30
src/pages/pageSignIn.ts

@ -17,7 +17,6 @@ import { isAndroid, isApple, isAppleMobile } from "../helpers/userAgent"; @@ -17,7 +17,6 @@ import { isAndroid, isApple, isAppleMobile } from "../helpers/userAgent";
import fastSmoothScroll from "../helpers/fastSmoothScroll";
import { isTouchSupported } from "../helpers/touchSupport";
import App from "../config/app";
import Modes from "../config/modes";
import I18n, { _i18n, i18n } from "../lib/langPack";
import lottieLoader from "../lib/lottieLoader";
import { ripple } from "../components/ripple";
@ -40,6 +39,7 @@ import { HelpCountry, HelpCountryCode } from "../layer"; @@ -40,6 +39,7 @@ import { HelpCountry, HelpCountryCode } from "../layer";
import { getCountryEmoji } from "../vendor/emoji";
import simulateEvent from "../helpers/dom/dispatchEvent";
import stateStorage from "../lib/stateStorage";
import rootScope from "../lib/rootScope";
//import _countries from '../countries_pretty.json';
let btnNext: HTMLButtonElement = null, btnQr: HTMLButtonElement;
@ -63,9 +63,18 @@ let onFirstMount = () => { @@ -63,9 +63,18 @@ let onFirstMount = () => {
//const countries: Country[] = _countries.default.filter(c => c.emoji);
// const countries: Country[] = Countries.filter(c => c.emoji).sort((a, b) => a.name.localeCompare(b.name));
// const countries = I18n.countriesList.filter(country => !country.pFlags?.hidden);
const countries = I18n.countriesList
.filter(country => !country.pFlags?.hidden)
.sort((a, b) => (a.name || a.default_name).localeCompare(b.name || b.default_name));
const setCountries = () => {
countries = I18n.countriesList
.filter(country => !country.pFlags?.hidden)
.sort((a, b) => (a.name || a.default_name).localeCompare(b.name || b.default_name));
};
let countries: HelpCountry.helpCountry[];
setCountries();
rootScope.addEventListener('language_change', () => {
setCountries();
});
const liMap: Map<string, HTMLLIElement[]> = new Map();
@ -81,8 +90,8 @@ let onFirstMount = () => { @@ -81,8 +90,8 @@ let onFirstMount = () => {
countryInputField.container.classList.add('input-select');
const countryInput = countryInputField.input as HTMLInputElement;
countryInput.autocomplete = randomLong();
const countryInput = countryInputField.input;
// countryInput.autocomplete = randomLong();
const selectWrapper = document.createElement('div');
selectWrapper.classList.add('select-wrapper', 'z-depth-3', 'hide');
@ -147,10 +156,12 @@ let onFirstMount = () => { @@ -147,10 +156,12 @@ let onFirstMount = () => {
const selectCountryByTarget = (target: HTMLElement) => {
const defaultName = (target.childNodes[1] as HTMLElement).dataset.defaultName;
const phoneCode = target.querySelector<HTMLElement>('.phone-code').innerText;
const countryCode = phoneCode.replace(/\D/g, '');
replaceContent(countryInput, i18n(defaultName as any));
simulateEvent(countryInput, 'input');
lastCountrySelected = countries.find(c => c.default_name === defaultName);
lastCountryCodeSelected = lastCountrySelected.country_codes.find(_countryCode => _countryCode.country_code === countryCode);
telInputField.value = lastValue = phoneCode;
hidePicker();
@ -220,11 +231,11 @@ let onFirstMount = () => { @@ -220,11 +231,11 @@ let onFirstMount = () => {
e.cancelBubble = true;
}, {capture: true}); */
countryInput.addEventListener('keyup', function(this: typeof countryInput, e) {
countryInput.addEventListener('keyup', (e) => {
if(e.ctrlKey || e.key === 'Control') return false;
//let i = new RegExp('^' + this.value, 'i');
let _value = this.value.toLowerCase();
let _value = countryInputField.value.toLowerCase();
let matches: HelpCountry[] = [];
countries.forEach((c) => {
let good = !![c.name, c.default_name].filter(Boolean).find(str => str.toLowerCase().indexOf(_value) !== -1)/* === 0 */;//i.test(c.name);
@ -330,7 +341,8 @@ let onFirstMount = () => { @@ -330,7 +341,8 @@ let onFirstMount = () => {
let countryName = country ? country.name || country.default_name : ''/* 'Unknown' */;
if(countryName !== countryInputField.value && (
!lastCountrySelected ||
!country || (
!country ||
!countryCode || (
lastCountrySelected !== country &&
lastCountryCodeSelected.country_code !== countryCode.country_code
)

Loading…
Cancel
Save