2020-09-07 10:22:16 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2020-09-06 02:27:01 +02:00
|
|
|
import { IntlProvider } from 'react-intl';
|
2020-09-07 10:22:16 +02:00
|
|
|
import { Provider, useDispatch, useSelector } from 'react-redux';
|
2020-08-05 07:45:05 +02:00
|
|
|
import { useStore } from 'redux/store';
|
2020-09-08 04:48:40 +02:00
|
|
|
import { updateApp } from 'redux/actions/app';
|
|
|
|
import { messages } from 'lib/lang';
|
2020-08-06 04:04:02 +02:00
|
|
|
import 'styles/variables.css';
|
2020-07-17 10:03:38 +02:00
|
|
|
import 'styles/bootstrap-grid.css';
|
2020-08-02 06:20:52 +02:00
|
|
|
import 'styles/index.css';
|
2020-09-07 10:22:16 +02:00
|
|
|
|
|
|
|
const Intl = ({ children }) => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const locale = useSelector(state => state.app.locale);
|
|
|
|
|
2020-09-08 00:25:09 +02:00
|
|
|
const Wrapper = ({ children }) => <span className={locale}>{children}</span>;
|
|
|
|
|
2020-09-07 10:22:16 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const saved = localStorage.getItem('locale');
|
|
|
|
if (saved) {
|
|
|
|
dispatch(updateApp({ locale: saved }));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2020-09-08 00:25:09 +02:00
|
|
|
<IntlProvider locale={locale} messages={messages[locale]} textComponent={Wrapper}>
|
2020-09-07 10:22:16 +02:00
|
|
|
{children}
|
|
|
|
</IntlProvider>
|
|
|
|
);
|
|
|
|
};
|
2020-07-17 10:03:38 +02:00
|
|
|
|
|
|
|
export default function App({ Component, pageProps }) {
|
2020-08-05 07:45:05 +02:00
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
return (
|
2020-09-07 10:22:16 +02:00
|
|
|
<Provider store={store}>
|
|
|
|
<Intl>
|
2020-09-06 02:27:01 +02:00
|
|
|
<Component {...pageProps} />
|
2020-09-07 10:22:16 +02:00
|
|
|
</Intl>
|
|
|
|
</Provider>
|
2020-08-05 07:45:05 +02:00
|
|
|
);
|
2020-07-17 10:03:38 +02:00
|
|
|
}
|