Skip to content

Commit

Permalink
fix: use only supported langs
Browse files Browse the repository at this point in the history
  • Loading branch information
martyanovandrey committed Feb 25, 2025
1 parent 41f1aa7 commit 97d241c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@diplodoc/babel-preset": "^1.0.3",
"@diplodoc/components": "^4.23.1",
"@diplodoc/components": "^4.23.2",
"@diplodoc/lint": "^1.1.1",
"@diplodoc/openapi-extension": "^2.7.0",
"@diplodoc/tsconfig": "^1.0.2",
Expand Down
14 changes: 7 additions & 7 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DocLeadingPageData,
DocPageData,
Lang,
SUPPORTED_LANGS,
configure,
} from '@diplodoc/components';
import '@diplodoc/transform/dist/js/yfm';
Expand Down Expand Up @@ -67,15 +68,14 @@ function hasNavigation(

export function App(props: DocInnerProps): ReactElement {
const {data, router, lang, search, analytics} = props;
const settings = useSettings();
const langData = useLangs(props);
const mobileView = useMobile();

configure({
lang,
lang: Object.keys(SUPPORTED_LANGS).includes(lang) ? lang : Lang.En,
});

const settings = useSettings();
const langs = useLangs(props);
const mobileView = useMobile();

const {theme, textSize, wideFormat, fullScreen, showMiniToc} = settings;

const page = useMemo(
Expand All @@ -93,10 +93,10 @@ export function App(props: DocInnerProps): ReactElement {
const controls: HeaderControlsProps = useMemo(
() => ({
...settings,
...langs,
...langData,
mobileView,
}),
[langs, settings, mobileView],
[langData, settings, mobileView],
);
const direction = getDirection(lang);
const landingPage = getLandingPage(data);
Expand Down
14 changes: 10 additions & 4 deletions src/components/App/useLangs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import {useCallback, useMemo} from 'react';

export function useLangs({router, lang, langs}: AppProps) {
const onChangeLang = useCallback(
(lang: `${Lang}` | Lang) => {
const path = getLangPath(router, lang);
window.location.replace(path);
(newLang: `${Lang}` | Lang) => {
window.location.replace(getLangPath(router, newLang, window.location.href));
},
[router],
);

return useMemo(() => ({lang, langs, onChangeLang}), [lang, langs, onChangeLang]);
return useMemo(
() => ({
lang,
langs,
onChangeLang,
}),
[lang, langs, onChangeLang],
);
}

0 comments on commit 97d241c

Please sign in to comment.