From d8bad156dd37afd1b97b07cc4f25f373e7de14c0 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Mon, 27 Mar 2023 00:27:47 +0300 Subject: [PATCH] language component refactoring --- .../components/language/LanguageComponent.js | 36 ++++++++++++---- .../components/language/LanguageContainer.js | 15 +++---- .../components/language/LanguageMenu.js | 42 ------------------- 3 files changed, 33 insertions(+), 60 deletions(-) delete mode 100644 src/features/settings/components/language/LanguageMenu.js diff --git a/src/features/settings/components/language/LanguageComponent.js b/src/features/settings/components/language/LanguageComponent.js index 9611e6c..7c04970 100644 --- a/src/features/settings/components/language/LanguageComponent.js +++ b/src/features/settings/components/language/LanguageComponent.js @@ -1,8 +1,8 @@ import React from "react"; import PropTypes from "prop-types"; import Flag from "react-flags"; -import { IconButton } from "@material-ui/core"; -import LanguageMenu from "./LanguageMenu"; +import { IconButton, Menu, MenuItem } from "@material-ui/core"; +import { useTranslation } from "react-i18next"; const LanguageComponent = ({ languageIsSet, @@ -11,8 +11,11 @@ const LanguageComponent = ({ onLanguageChange, onClose, flag, - getFlagsPath + flagsPath }) => { + const { t } = useTranslation(); + const open = Boolean(anchorEl); + return ( <> )} - + > + + {t("Language.Romanian")} + + + {t("Language.English")} + + ); }; @@ -48,7 +68,7 @@ LanguageComponent.propTypes = { onLanguageChange: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, flag: PropTypes.object.isRequired, - getFlagsPath: PropTypes.func.isRequired + flagsPath: PropTypes.string.isRequired }; export default LanguageComponent; diff --git a/src/features/settings/components/language/LanguageContainer.js b/src/features/settings/components/language/LanguageContainer.js index 56dab21..0fd9b42 100644 --- a/src/features/settings/components/language/LanguageContainer.js +++ b/src/features/settings/components/language/LanguageContainer.js @@ -2,6 +2,10 @@ import React, { useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import LanguageComponent from "./LanguageComponent"; +const flagsPath = process.env.PUBLIC_URL + ? `${process.env.PUBLIC_URL}/flags` + : "flags"; + const LanguageContainer = () => { const [anchorEl, setAnchorEl] = useState(null); @@ -34,15 +38,6 @@ const LanguageContainer = () => { setAnchorEl(null); }; - const getFlagsPath = () => { - const basePath = "flags"; - if (process.env.PUBLIC_URL) { - return `${process.env.PUBLIC_URL}/${basePath}`; - } else { - return basePath; - } - }; - return ( { onLanguageChange={handleLanguageChange} onClose={handleClose} flag={flag} - getFlagsPath={getFlagsPath} + flagsPath={flagsPath} /> ); }; diff --git a/src/features/settings/components/language/LanguageMenu.js b/src/features/settings/components/language/LanguageMenu.js deleted file mode 100644 index 4dbea52..0000000 --- a/src/features/settings/components/language/LanguageMenu.js +++ /dev/null @@ -1,42 +0,0 @@ -import React from "react"; -import PropTypes from "prop-types"; -import { useTranslation } from "react-i18next"; -import { Menu, MenuItem } from "@material-ui/core"; - -const LanguageMenu = ({ anchorEl, onLanguageChange, onClose }) => { - const { t } = useTranslation(); - const open = Boolean(anchorEl); - - return ( - - - {t("Language.Romanian")} - - - {t("Language.English")} - - - ); -}; - -LanguageMenu.propTypes = { - anchorEl: PropTypes.object, - onLanguageChange: PropTypes.func.isRequired, - onClose: PropTypes.func.isRequired -}; - -export default LanguageMenu;