From d168b740dfecc6eae66cc9ca581e4d759a7c6cf1 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 29 May 2024 14:18:11 +0300 Subject: [PATCH 1/6] Improve props validation --- src/ui/LangMenu/LangMenu.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/LangMenu/LangMenu.js b/src/ui/LangMenu/LangMenu.js index b01f6e09d..a00941dbc 100644 --- a/src/ui/LangMenu/LangMenu.js +++ b/src/ui/LangMenu/LangMenu.js @@ -1,12 +1,11 @@ import React from 'react' +import PropTypes from 'prop-types' import _map from 'lodash/map' import _keys from 'lodash/keys' import Select from 'ui/Select' import { LANGUAGE_NAMES } from 'locales/i18n' -import { propTypes, defaultProps } from './LangMenu.props' - const items = _map(_keys(LANGUAGE_NAMES), (lang) => ({ value: lang, label: LANGUAGE_NAMES[lang] })) const LangMenu = (props) => { @@ -24,7 +23,9 @@ const LangMenu = (props) => { ) } -LangMenu.propTypes = propTypes -LangMenu.defaultProps = defaultProps +LangMenu.propTypes = { + value: PropTypes.string.isRequired, + setLang: PropTypes.func.isRequired, +} export default LangMenu From a88cebf713296f822011e1948824d76632d60cdc Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 29 May 2024 14:19:03 +0300 Subject: [PATCH 2/6] Redundant code cleanup --- src/ui/LangMenu/LangMenu.props.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/ui/LangMenu/LangMenu.props.js diff --git a/src/ui/LangMenu/LangMenu.props.js b/src/ui/LangMenu/LangMenu.props.js deleted file mode 100644 index 10cef93d3..000000000 --- a/src/ui/LangMenu/LangMenu.props.js +++ /dev/null @@ -1,8 +0,0 @@ -import PropTypes from 'prop-types' - -export const propTypes = { - value: PropTypes.string.isRequired, - setLang: PropTypes.func.isRequired, -} - -export const defaultProps = {} From 3e47e9c63feb2c96b538e9c3fef851a37b13379a Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 29 May 2024 14:20:20 +0300 Subject: [PATCH 3/6] Optimize exporting --- src/ui/LangMenu/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ui/LangMenu/index.js b/src/ui/LangMenu/index.js index 5a02526aa..11ecf8e62 100644 --- a/src/ui/LangMenu/index.js +++ b/src/ui/LangMenu/index.js @@ -1,3 +1 @@ -import LangMenu from './LangMenu.container' - -export default LangMenu +export { default } from './LangMenu.container' From 3ac89289b4bfa4bc8db9fcbf42c80f2e9e8fdbbf Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 29 May 2024 14:26:32 +0300 Subject: [PATCH 4/6] Rework and optimize lang selection flow --- src/ui/LangMenu/LangMenu.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/ui/LangMenu/LangMenu.js b/src/ui/LangMenu/LangMenu.js index a00941dbc..60f14e5d3 100644 --- a/src/ui/LangMenu/LangMenu.js +++ b/src/ui/LangMenu/LangMenu.js @@ -1,31 +1,33 @@ -import React from 'react' -import PropTypes from 'prop-types' +import React, { useCallback } from 'react' +import { useDispatch, useSelector } from 'react-redux' import _map from 'lodash/map' import _keys from 'lodash/keys' import Select from 'ui/Select' +import { setLang } from 'state/base/actions' import { LANGUAGE_NAMES } from 'locales/i18n' +import { getLocale } from 'state/base/selectors' const items = _map(_keys(LANGUAGE_NAMES), (lang) => ({ value: lang, label: LANGUAGE_NAMES[lang] })) -const LangMenu = (props) => { - const { setLang, value } = props +const LangMenu = () => { + const dispatch = useDispatch() + const currentValue = useSelector(getLocale) + + const handleChange = useCallback((value) => { + dispatch(setLang(value)) + }, [dispatch]) return (