Skip to content

Commit 5154d85

Browse files
committed
fix: apply review feedback
1 parent 9af0020 commit 5154d85

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

app/component/LangSelect.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { matchShape } from 'found';
34
import { useIntl } from 'react-intl';
4-
import { configShape } from '../util/shapes';
55
import { useConfigContext } from '../configurations/ConfigContext';
66

7-
const language = (lang, highlight, match, intl) => {
7+
const Language = ({ lang }, { match }) => {
8+
const { language } = useConfigContext();
9+
const intl = useIntl();
10+
const highlight = lang === language;
11+
812
const aria = highlight
913
? intl.formatMessage(
1014
{ id: 'search-current-suggestion' },
@@ -24,21 +28,18 @@ const language = (lang, highlight, match, intl) => {
2428
);
2529
};
2630

27-
const LangSelect = ({}, { match }) => { // eslint-disable-line
28-
const config = useConfigContext();
29-
const intl = useIntl();
31+
Language.contextTypes = { match: matchShape.isRequired };
32+
Language.propTypes = { lang: PropTypes.string.isRequired };
33+
34+
const LanguageSelect = ({}, { match }) => { // eslint-disable-line
35+
const { availableLanguages } = useConfigContext();
3036
return (
3137
<div key="lang-select" id="lang-select">
32-
{config.availableLanguages.map(lang =>
33-
language(lang, lang === config.language, match, intl),
34-
)}
38+
{availableLanguages.map(lang => (
39+
<Language key={lang} lang={lang} />
40+
))}
3541
</div>
3642
);
3743
};
3844

39-
LangSelect.contextTypes = {
40-
config: configShape.isRequired,
41-
match: matchShape.isRequired,
42-
};
43-
44-
export default LangSelect;
45+
export default LanguageSelect;

0 commit comments

Comments
 (0)