From 9317b4ca9a9b12f51f17e218dc8692153887a78f Mon Sep 17 00:00:00 2001 From: Yousef Date: Mon, 30 Aug 2021 16:33:28 -0400 Subject: [PATCH] Bug/fix-language (#99) * Fixed language change on Login, register, and chat pages * Fixed language settings * Fixed language issues with searching * Ran formatting * Used optional chaining --- client/components/NavBar.jsx | 14 ++++++++++++-- client/pages/index.jsx | 20 +++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/client/components/NavBar.jsx b/client/components/NavBar.jsx index c7b16af..d43ccbd 100644 --- a/client/components/NavBar.jsx +++ b/client/components/NavBar.jsx @@ -146,6 +146,16 @@ const ColorModeButton = () => { const LocaleSelect = ({ mr }) => { const { formatMessage } = useIntl(); + const { pathname, query } = useRouter(); + + let currentPath = pathname; + if (query?.id) { + currentPath = `/chat/${query.id}`; + } else if (query?.iscommunity) { + currentPath = `?iscommunity=${query.iscommunity}`; + } else if (query?.q) { + currentPath = `?q=${query.q}`; + } return ( @@ -163,10 +173,10 @@ const LocaleSelect = ({ mr }) => { /> - + English - + French diff --git a/client/pages/index.jsx b/client/pages/index.jsx index de3abb3..a368c85 100644 --- a/client/pages/index.jsx +++ b/client/pages/index.jsx @@ -36,8 +36,6 @@ export default function Home() { const { isOpen, onOpen, onClose } = useDisclosure(); const { formatMessage } = useIntl(); const { - locale, - defaultLocale, push, query: { q, iscommunity }, } = useRouter(); @@ -113,11 +111,7 @@ export default function Home() { const handleSearch = async (e) => { e.preventDefault(); setCurrentPage(0); - push( - `${locale !== defaultLocale ? locale : ""}/?q=${curSearchQuery}`, - undefined, - { shallow: true } - ); + push(`/?q=${curSearchQuery}`, undefined, { shallow: true }); }; const displayMorePages = async () => { @@ -155,17 +149,13 @@ export default function Home() { const handleCommunityChange = (newIsCommunity) => { setCurrentPage(0); if (newIsCommunity === 0) { - push(`${locale !== defaultLocale ? locale : ""}/`, undefined, { + push(`/`, undefined, { shallow: true, }); } else { - push( - `${locale !== defaultLocale ? locale : ""}/?iscommunity=${ - newIsCommunity === 2 - }`, - undefined, - { shallow: true } - ); + push(`/?iscommunity=${newIsCommunity === 2}`, undefined, { + shallow: true, + }); } setSearchQuery(""); };