Skip to content

Commit cb3f0ec

Browse files
committed
Add locale picker to app header
1 parent 0244187 commit cb3f0ec

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

frontend/src/components/LocalePicker.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Box,
44
Menu,
55
MenuButton,
6+
MenuButtonProps,
67
MenuList,
78
MenuItem,
89
} from "@chakra-ui/react";
@@ -16,29 +17,30 @@ import {
1617
} from "locale";
1718

1819
interface LocalPickerProps {
19-
/**
20-
* On change handler
21-
*/
2220
onChange?: any;
23-
/**
24-
* Class
25-
*/
2621
className?: string;
22+
background?: "normal" | "transparent";
2723
}
2824

29-
function LocalePicker({ onChange, className }: LocalPickerProps) {
25+
function LocalePicker({ onChange, className, background }: LocalPickerProps) {
3026
const { locale, setLocale } = useLocaleState();
3127

28+
const additionalProps: Partial<MenuButtonProps> = {};
29+
if (background === "transparent") {
30+
additionalProps["backgroundColor"] = "transparent";
31+
}
32+
3233
const changeTo = (lang: string) => {
3334
changeLocale(lang);
3435
setLocale(lang);
3536
onChange && onChange(locale);
37+
___location.reload();
3638
};
3739

3840
return (
3941
<Box className={className}>
4042
<Menu>
41-
<MenuButton as={Button}>
43+
<MenuButton as={Button} {...additionalProps}>
4244
<Flag countryCode={getFlagCodeForLocale(locale)} />
4345
</MenuButton>
4446
<MenuList>

frontend/src/components/Navigation/NavigationHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
useColorModeValue,
1818
useDisclosure,
1919
} from "@chakra-ui/react";
20-
import { ThemeSwitcher } from "components";
20+
import { LocalePicker, ThemeSwitcher } from "components";
2121
import { useAuthState } from "context";
2222
import { useUser } from "hooks";
2323
import { intl } from "locale";
@@ -67,6 +67,7 @@ function NavigationHeader({
6767
</HStack>
6868
<HStack>
6969
<ThemeSwitcher background="transparent" />
70+
<LocalePicker className="text-right" background="transparent" />
7071
<Box pl={2}>
7172
<Menu>
7273
<MenuButton

0 commit comments

Comments
 (0)