Skip to content

Commit

Permalink
refactor: extract language watch to custom hook
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Oct 14, 2024
1 parent 278559f commit ea31800
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
17 changes: 4 additions & 13 deletions packages/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { Loader } from './components/Loader/Loader';
import { Menu } from './components/Menu/Menu';
import { Title } from './components/Title/Title';
import { useConfirm } from './hooks/useConfirm';
import { useLanguageWatch } from './hooks/useLanguageWatch';
import { useQueues } from './hooks/useQueues';
import { useScrollTopOnNav } from './hooks/useScrollTopOnNav';
import { useTranslation } from 'react-i18next';
import { useSettingsStore } from './hooks/useSettings';
import { ThemeProvider } from 'next-themes';

const JobPageLazy = React.lazy(() =>
import('./pages/JobPage/JobPage').then(({ JobPage }) => ({ default: JobPage }))
Expand All @@ -32,21 +30,14 @@ export const App = () => {
useScrollTopOnNav();
const { actions: queueActions } = useQueues();
const { confirmProps } = useConfirm();
useLanguageWatch();

useEffect(() => {
queueActions.updateQueues();
}, []);

const { i18n } = useTranslation();
const { language } = useSettingsStore();
useEffect(() => {
if (language && i18n.language !== language) {
i18n.changeLanguage(language);
}
}, [language]);

return (
<ThemeProvider>
<>
<Header>
<Title />
<HeaderActions />
Expand All @@ -66,6 +57,6 @@ export const App = () => {
</main>
<Menu />
<ToastContainer />
</ThemeProvider>
</>
);
};
14 changes: 14 additions & 0 deletions packages/ui/src/hooks/useLanguageWatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useSettingsStore } from './useSettings';

export function useLanguageWatch() {
const { i18n } = useTranslation();
const { language } = useSettingsStore();

useEffect(() => {
if (language && i18n.language !== language) {
i18n.changeLanguage(language);
}
}, [language]);
}

0 comments on commit ea31800

Please sign in to comment.