From 3f646f13dde68f0314936c26c8a1074ab616bb89 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 31 May 2019 21:25:13 -0600 Subject: [PATCH 1/3] Add option to change the default country code Fixes https://github.com/vector-im/riot-web/issues/9926 --- src/components/views/auth/CountryDropdown.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/views/auth/CountryDropdown.js b/src/components/views/auth/CountryDropdown.js index b29bf40625..99868fa910 100644 --- a/src/components/views/auth/CountryDropdown.js +++ b/src/components/views/auth/CountryDropdown.js @@ -20,6 +20,7 @@ import PropTypes from 'prop-types'; import sdk from '../../../index'; import { COUNTRIES } from '../../../phonenumber'; +import SdkConfig from "../../../SdkConfig"; const COUNTRIES_BY_ISO2 = {}; for (const c of COUNTRIES) { @@ -45,17 +46,25 @@ export default class CountryDropdown extends React.Component { this._onOptionChange = this._onOptionChange.bind(this); this._getShortOption = this._getShortOption.bind(this); + let defaultCountry = COUNTRIES[0]; + if (SdkConfig.get()["defaultCountryCode"]) { + const country = COUNTRIES.find(c => c.iso2 === SdkConfig.get()["defaultCountryCode"]); + if (country) defaultCountry = country; + } + console.log(defaultCountry); + console.log(props); this.state = { searchQuery: '', + defaultCountry, }; } componentWillMount() { if (!this.props.value) { - // If no value is given, we start with the first + // If no value is given, we start with the default // country selected, but our parent component // doesn't know this, therefore we do this. - this.props.onOptionChange(COUNTRIES[0]); + this.props.onOptionChange(this.state.defaultCountry); } } @@ -119,7 +128,7 @@ export default class CountryDropdown extends React.Component { // default value here too, otherwise we need to handle null / undefined // values between mounting and the initial value propgating - const value = this.props.value || COUNTRIES[0].iso2; + const value = this.props.value || this.state.defaultCountry.iso2; return Date: Fri, 31 May 2019 21:26:22 -0600 Subject: [PATCH 2/3] Remove debugging --- src/components/views/auth/CountryDropdown.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/views/auth/CountryDropdown.js b/src/components/views/auth/CountryDropdown.js index 99868fa910..63914319c8 100644 --- a/src/components/views/auth/CountryDropdown.js +++ b/src/components/views/auth/CountryDropdown.js @@ -51,8 +51,7 @@ export default class CountryDropdown extends React.Component { const country = COUNTRIES.find(c => c.iso2 === SdkConfig.get()["defaultCountryCode"]); if (country) defaultCountry = country; } - console.log(defaultCountry); - console.log(props); + this.state = { searchQuery: '', defaultCountry, From ecc0552e89fdf9802014c94d30cdd1fe69d38451 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 1 Jun 2019 09:12:09 -0600 Subject: [PATCH 3/3] ToUpper the country code --- src/components/views/auth/CountryDropdown.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/views/auth/CountryDropdown.js b/src/components/views/auth/CountryDropdown.js index 63914319c8..d8aa88c798 100644 --- a/src/components/views/auth/CountryDropdown.js +++ b/src/components/views/auth/CountryDropdown.js @@ -47,8 +47,9 @@ export default class CountryDropdown extends React.Component { this._getShortOption = this._getShortOption.bind(this); let defaultCountry = COUNTRIES[0]; - if (SdkConfig.get()["defaultCountryCode"]) { - const country = COUNTRIES.find(c => c.iso2 === SdkConfig.get()["defaultCountryCode"]); + const defaultCountryCode = SdkConfig.get()["defaultCountryCode"]; + if (defaultCountryCode) { + const country = COUNTRIES.find(c => c.iso2 === defaultCountryCode.toUpperCase()); if (country) defaultCountry = country; }