revite/src/components/common/LocaleSelector.tsx

39 lines
970 B
TypeScript
Raw Normal View History

import { dispatch } from "../../redux";
import { connectState } from "../../redux/connector";
2021-07-05 06:23:23 -04:00
import { Language, Languages } from "../../context/Locale";
import ComboBox from "../ui/ComboBox";
type Props = {
2021-07-05 06:25:20 -04:00
locale: string;
};
export function LocaleSelector(props: Props) {
2021-07-05 06:25:20 -04:00
return (
<ComboBox
value={props.locale}
onChange={(e) =>
dispatch({
type: "SET_LOCALE",
locale: e.currentTarget.value as Language,
})
}>
{Object.keys(Languages).map((x) => {
const l = Languages[x as keyof typeof Languages];
return (
<option value={x}>
{l.emoji} {l.display}
</option>
);
})}
</ComboBox>
);
}
2021-07-05 06:23:23 -04:00
export default connectState(LocaleSelector, (state) => {
2021-07-05 06:25:20 -04:00
return {
locale: state.locale,
};
2021-07-05 06:23:23 -04:00
});