Skip to content

Commit

Permalink
Bug/fix-language (#99)
Browse files Browse the repository at this point in the history
* Fixed language change on Login, register, and chat pages

* Fixed language settings

* Fixed language issues with searching

* Ran formatting

* Used optional chaining
  • Loading branch information
Yousef-Bulbulia authored Aug 30, 2021
1 parent 92de2c8 commit 9317b4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 12 additions & 2 deletions client/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Menu>
Expand All @@ -163,10 +173,10 @@ const LocaleSelect = ({ mr }) => {
/>
</Tooltip>
<MenuList size="sm">
<NextLink href="/" locale="en">
<NextLink href={currentPath} locale="en">
<MenuItem>English</MenuItem>
</NextLink>
<NextLink href="/" locale="fr">
<NextLink href={currentPath} locale="fr">
<MenuItem>French</MenuItem>
</NextLink>
</MenuList>
Expand Down
20 changes: 5 additions & 15 deletions client/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export default function Home() {
const { isOpen, onOpen, onClose } = useDisclosure();
const { formatMessage } = useIntl();
const {
locale,
defaultLocale,
push,
query: { q, iscommunity },
} = useRouter();
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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("");
};
Expand Down

0 comments on commit 9317b4c

Please sign in to comment.