Browse Source

fixes

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

13
src/components/languageChangeButton.ts

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

4
src/lib/langPack.ts

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

26
src/pages/pageSignIn.ts

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

Loading…
Cancel
Save