From 1be9f4ee9fdb03d4ed113f3e4549067b75ceadc5 Mon Sep 17 00:00:00 2001 From: joh42 <138504087+joh42@users.noreply.github.com> Date: Tue, 1 Aug 2023 23:52:55 +0200 Subject: [PATCH 1/6] implemented searchValue resetting when showing the country picker --- src/components/CountryPicker/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/CountryPicker/index.js b/src/components/CountryPicker/index.js index 20f9a981accb..7f746d6bb3f7 100644 --- a/src/components/CountryPicker/index.js +++ b/src/components/CountryPicker/index.js @@ -36,10 +36,11 @@ function CountryPicker({value, errorText, onInputChange, forwardedRef}) { const [searchValue, setSearchValue] = useState(lodashGet(allCountries, value, '')); useEffect(() => { - setSearchValue(lodashGet(allCountries, value, '')); + updateSearchValue(); }, [value, allCountries]); const showPickerModal = () => { + updateSearchValue(); setIsPickerVisible(true); }; @@ -52,6 +53,10 @@ function CountryPicker({value, errorText, onInputChange, forwardedRef}) { hidePickerModal(); }; + const updateSearchValue = () => { + setSearchValue(lodashGet(allCountries, value, '')); + } + const title = allCountries[value] || ''; const descStyle = title.length === 0 ? styles.textNormal : null; From 0dc553cd8532861d52a4dcf3204d0dc736722aa1 Mon Sep 17 00:00:00 2001 From: joh42 <138504087+joh42@users.noreply.github.com> Date: Tue, 1 Aug 2023 23:54:00 +0200 Subject: [PATCH 2/6] implemented searchValue resetting when showing the state picker --- src/components/StatePicker/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/StatePicker/index.js b/src/components/StatePicker/index.js index 7c8fbdae36bb..9c224dbb7729 100644 --- a/src/components/StatePicker/index.js +++ b/src/components/StatePicker/index.js @@ -36,10 +36,11 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) { const [searchValue, setSearchValue] = useState(lodashGet(allStates, `${value}.stateName`, '')); useEffect(() => { - setSearchValue(lodashGet(allStates, `${value}.stateName`, '')); + updateSearchValue(); }, [value, allStates]); const showPickerModal = () => { + updateSearchValue(); setIsPickerVisible(true); }; @@ -52,6 +53,10 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) { hidePickerModal(); }; + const updateSearchValue = () => { + setSearchValue(lodashGet(allStates, `${value}.stateName`, '')); + } + const title = allStates[value] ? allStates[value].stateName : ''; const descStyle = title.length === 0 ? styles.textNormal : null; From 5b9556b874ba73ab6ab196451240cd493dfcff0c Mon Sep 17 00:00:00 2001 From: joh42 <138504087+joh42@users.noreply.github.com> Date: Wed, 2 Aug 2023 01:01:10 +0200 Subject: [PATCH 3/6] made linter happy --- src/components/CountryPicker/index.js | 16 ++++++++-------- src/components/StatePicker/index.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/components/CountryPicker/index.js b/src/components/CountryPicker/index.js index 7f746d6bb3f7..f2e4f974d7e8 100644 --- a/src/components/CountryPicker/index.js +++ b/src/components/CountryPicker/index.js @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react'; +import React, {useCallback, useEffect, useState} from 'react'; import {View} from 'react-native'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; @@ -35,12 +35,16 @@ function CountryPicker({value, errorText, onInputChange, forwardedRef}) { const [isPickerVisible, setIsPickerVisible] = useState(false); const [searchValue, setSearchValue] = useState(lodashGet(allCountries, value, '')); + const updateSearchValue = useCallback((countries, currentValue) => { + setSearchValue(lodashGet(countries, currentValue, '')); + }, []); + useEffect(() => { - updateSearchValue(); - }, [value, allCountries]); + updateSearchValue(allCountries, value); + }, [value, allCountries, updateSearchValue]); const showPickerModal = () => { - updateSearchValue(); + updateSearchValue(allCountries, value); setIsPickerVisible(true); }; @@ -53,10 +57,6 @@ function CountryPicker({value, errorText, onInputChange, forwardedRef}) { hidePickerModal(); }; - const updateSearchValue = () => { - setSearchValue(lodashGet(allCountries, value, '')); - } - const title = allCountries[value] || ''; const descStyle = title.length === 0 ? styles.textNormal : null; diff --git a/src/components/StatePicker/index.js b/src/components/StatePicker/index.js index 9c224dbb7729..948112f28d3d 100644 --- a/src/components/StatePicker/index.js +++ b/src/components/StatePicker/index.js @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react'; +import React, {useCallback, useEffect, useState} from 'react'; import {View} from 'react-native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; @@ -35,12 +35,16 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) { const [isPickerVisible, setIsPickerVisible] = useState(false); const [searchValue, setSearchValue] = useState(lodashGet(allStates, `${value}.stateName`, '')); + const updateSearchValue = useCallback((states, currentValue) => { + setSearchValue(lodashGet(states, `${currentValue}.stateName`, '')); + }, []); + useEffect(() => { - updateSearchValue(); - }, [value, allStates]); + updateSearchValue(allStates, value); + }, [value, allStates, updateSearchValue]); const showPickerModal = () => { - updateSearchValue(); + updateSearchValue(allStates, value); setIsPickerVisible(true); }; @@ -53,10 +57,6 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) { hidePickerModal(); }; - const updateSearchValue = () => { - setSearchValue(lodashGet(allStates, `${value}.stateName`, '')); - } - const title = allStates[value] ? allStates[value].stateName : ''; const descStyle = title.length === 0 ? styles.textNormal : null; From f49c3369f1247eb9c792c5470af95f25b460a27a Mon Sep 17 00:00:00 2001 From: joh42 <138504087+joh42@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:22:55 +0200 Subject: [PATCH 4/6] removed updateSearchValue function from the state picker --- src/components/StatePicker/index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/StatePicker/index.js b/src/components/StatePicker/index.js index 948112f28d3d..4dcd27661104 100644 --- a/src/components/StatePicker/index.js +++ b/src/components/StatePicker/index.js @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useState} from 'react'; +import React, {useEffect, useState} from 'react'; import {View} from 'react-native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; @@ -35,16 +35,12 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) { const [isPickerVisible, setIsPickerVisible] = useState(false); const [searchValue, setSearchValue] = useState(lodashGet(allStates, `${value}.stateName`, '')); - const updateSearchValue = useCallback((states, currentValue) => { - setSearchValue(lodashGet(states, `${currentValue}.stateName`, '')); - }, []); - useEffect(() => { - updateSearchValue(allStates, value); - }, [value, allStates, updateSearchValue]); + setSearchValue(lodashGet(states, `${currentValue}.stateName`, '')); + }, [value, allStates]); const showPickerModal = () => { - updateSearchValue(allStates, value); + setSearchValue(lodashGet(states, `${currentValue}.stateName`, '')); setIsPickerVisible(true); }; From bd567043af2bcd5dffd356ff29208b6e6abf3722 Mon Sep 17 00:00:00 2001 From: joh42 <138504087+joh42@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:24:05 +0200 Subject: [PATCH 5/6] removed updateSearchValue function from the country picker --- src/components/CountryPicker/index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/CountryPicker/index.js b/src/components/CountryPicker/index.js index f2e4f974d7e8..69a8fbe4a9ea 100644 --- a/src/components/CountryPicker/index.js +++ b/src/components/CountryPicker/index.js @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useState} from 'react'; +import React, {useEffect, useState} from 'react'; import {View} from 'react-native'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; @@ -35,16 +35,12 @@ function CountryPicker({value, errorText, onInputChange, forwardedRef}) { const [isPickerVisible, setIsPickerVisible] = useState(false); const [searchValue, setSearchValue] = useState(lodashGet(allCountries, value, '')); - const updateSearchValue = useCallback((countries, currentValue) => { - setSearchValue(lodashGet(countries, currentValue, '')); - }, []); - useEffect(() => { - updateSearchValue(allCountries, value); - }, [value, allCountries, updateSearchValue]); + setSearchValue(lodashGet(countries, currentValue, '')); + }, [value, allCountries]); const showPickerModal = () => { - updateSearchValue(allCountries, value); + setSearchValue(lodashGet(countries, currentValue, '')); setIsPickerVisible(true); }; From d50af95ae1d749798ac3d61a18a8406421ff9eda Mon Sep 17 00:00:00 2001 From: joh42 <138504087+joh42@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:25:08 +0200 Subject: [PATCH 6/6] corrected variable names --- src/components/CountryPicker/index.js | 4 ++-- src/components/StatePicker/index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/CountryPicker/index.js b/src/components/CountryPicker/index.js index 69a8fbe4a9ea..6d1435dca796 100644 --- a/src/components/CountryPicker/index.js +++ b/src/components/CountryPicker/index.js @@ -36,11 +36,11 @@ function CountryPicker({value, errorText, onInputChange, forwardedRef}) { const [searchValue, setSearchValue] = useState(lodashGet(allCountries, value, '')); useEffect(() => { - setSearchValue(lodashGet(countries, currentValue, '')); + setSearchValue(lodashGet(allCountries, value, '')); }, [value, allCountries]); const showPickerModal = () => { - setSearchValue(lodashGet(countries, currentValue, '')); + setSearchValue(lodashGet(allCountries, value, '')); setIsPickerVisible(true); }; diff --git a/src/components/StatePicker/index.js b/src/components/StatePicker/index.js index 4dcd27661104..e9780e7a06b7 100644 --- a/src/components/StatePicker/index.js +++ b/src/components/StatePicker/index.js @@ -36,11 +36,11 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) { const [searchValue, setSearchValue] = useState(lodashGet(allStates, `${value}.stateName`, '')); useEffect(() => { - setSearchValue(lodashGet(states, `${currentValue}.stateName`, '')); + setSearchValue(lodashGet(allStates, `${value}.stateName`, '')); }, [value, allStates]); const showPickerModal = () => { - setSearchValue(lodashGet(states, `${currentValue}.stateName`, '')); + setSearchValue(lodashGet(allStates, `${value}.stateName`, '')); setIsPickerVisible(true); };