Fixed: Ensure translations are fetched before loading app
This commit is contained in:
parent
3aa3ac90ed
commit
ad2721dc55
|
@ -84,6 +84,10 @@ module.exports = (env) => {
|
||||||
hints: false
|
hints: false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
experiments: {
|
||||||
|
topLevelAwait: true
|
||||||
|
},
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
__DEV__: !isProduction,
|
__DEV__: !isProduction,
|
||||||
|
|
|
@ -7,13 +7,13 @@ import PageConnector from 'Components/Page/PageConnector';
|
||||||
import ApplyTheme from './ApplyTheme';
|
import ApplyTheme from './ApplyTheme';
|
||||||
import AppRoutes from './AppRoutes';
|
import AppRoutes from './AppRoutes';
|
||||||
|
|
||||||
function App({ store, history }) {
|
function App({ store, history, hasTranslationsError }) {
|
||||||
return (
|
return (
|
||||||
<DocumentTitle title={window.Sonarr.instanceName}>
|
<DocumentTitle title={window.Sonarr.instanceName}>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<ConnectedRouter history={history}>
|
<ConnectedRouter history={history}>
|
||||||
<ApplyTheme>
|
<ApplyTheme>
|
||||||
<PageConnector>
|
<PageConnector hasTranslationsError={hasTranslationsError}>
|
||||||
<AppRoutes app={App} />
|
<AppRoutes app={App} />
|
||||||
</PageConnector>
|
</PageConnector>
|
||||||
</ApplyTheme>
|
</ApplyTheme>
|
||||||
|
@ -25,7 +25,8 @@ function App({ store, history }) {
|
||||||
|
|
||||||
App.propTypes = {
|
App.propTypes = {
|
||||||
store: PropTypes.object.isRequired,
|
store: PropTypes.object.isRequired,
|
||||||
history: PropTypes.object.isRequired
|
history: PropTypes.object.isRequired,
|
||||||
|
hasTranslationsError: PropTypes.bool.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
|
@ -7,6 +7,7 @@ function ErrorPage(props) {
|
||||||
const {
|
const {
|
||||||
version,
|
version,
|
||||||
isLocalStorageSupported,
|
isLocalStorageSupported,
|
||||||
|
hasTranslationsError,
|
||||||
seriesError,
|
seriesError,
|
||||||
customFiltersError,
|
customFiltersError,
|
||||||
tagsError,
|
tagsError,
|
||||||
|
@ -19,6 +20,8 @@ function ErrorPage(props) {
|
||||||
|
|
||||||
if (!isLocalStorageSupported) {
|
if (!isLocalStorageSupported) {
|
||||||
errorMessage = 'Local Storage is not supported or disabled. A plugin or private browsing may have disabled it.';
|
errorMessage = 'Local Storage is not supported or disabled. A plugin or private browsing may have disabled it.';
|
||||||
|
} else if (hasTranslationsError) {
|
||||||
|
errorMessage = 'Failed to load translations from API';
|
||||||
} else if (seriesError) {
|
} else if (seriesError) {
|
||||||
errorMessage = getErrorMessage(seriesError, 'Failed to load series from API');
|
errorMessage = getErrorMessage(seriesError, 'Failed to load series from API');
|
||||||
} else if (customFiltersError) {
|
} else if (customFiltersError) {
|
||||||
|
@ -49,6 +52,7 @@ function ErrorPage(props) {
|
||||||
ErrorPage.propTypes = {
|
ErrorPage.propTypes = {
|
||||||
version: PropTypes.string.isRequired,
|
version: PropTypes.string.isRequired,
|
||||||
isLocalStorageSupported: PropTypes.bool.isRequired,
|
isLocalStorageSupported: PropTypes.bool.isRequired,
|
||||||
|
hasTranslationsError: PropTypes.bool.isRequired,
|
||||||
seriesError: PropTypes.object,
|
seriesError: PropTypes.object,
|
||||||
customFiltersError: PropTypes.object,
|
customFiltersError: PropTypes.object,
|
||||||
tagsError: PropTypes.object,
|
tagsError: PropTypes.object,
|
||||||
|
|
|
@ -220,6 +220,7 @@ class PageConnector extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
hasTranslationsError,
|
||||||
isPopulated,
|
isPopulated,
|
||||||
hasError,
|
hasError,
|
||||||
dispatchFetchSeries,
|
dispatchFetchSeries,
|
||||||
|
@ -232,11 +233,12 @@ class PageConnector extends Component {
|
||||||
...otherProps
|
...otherProps
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (hasError || !this.state.isLocalStorageSupported) {
|
if (hasTranslationsError || hasError || !this.state.isLocalStorageSupported) {
|
||||||
return (
|
return (
|
||||||
<ErrorPage
|
<ErrorPage
|
||||||
{...this.state}
|
{...this.state}
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
|
hasTranslationsError={hasTranslationsError}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -257,6 +259,7 @@ class PageConnector extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
PageConnector.propTypes = {
|
PageConnector.propTypes = {
|
||||||
|
hasTranslationsError: PropTypes.bool.isRequired,
|
||||||
isPopulated: PropTypes.bool.isRequired,
|
isPopulated: PropTypes.bool.isRequired,
|
||||||
hasError: PropTypes.bool.isRequired,
|
hasError: PropTypes.bool.isRequired,
|
||||||
isSidebarVisible: PropTypes.bool.isRequired,
|
isSidebarVisible: PropTypes.bool.isRequired,
|
||||||
|
|
|
@ -10,9 +10,11 @@ function getTranslations() {
|
||||||
|
|
||||||
let translations = {};
|
let translations = {};
|
||||||
|
|
||||||
getTranslations().then((data) => {
|
export function fetchTranslations() {
|
||||||
translations = data.strings;
|
return getTranslations().then((data) => {
|
||||||
});
|
translations = data.strings;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default function translate(key, tokens) {
|
export default function translate(key, tokens) {
|
||||||
const translation = translations[key] || key;
|
const translation = translations[key] || key;
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { createBrowserHistory } from 'history';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from 'react-dom';
|
import { render } from 'react-dom';
|
||||||
import createAppStore from 'Store/createAppStore';
|
import createAppStore from 'Store/createAppStore';
|
||||||
|
import { fetchTranslations } from 'Utilities/String/translate';
|
||||||
import App from './App/App';
|
import App from './App/App';
|
||||||
|
|
||||||
import './preload';
|
import './preload';
|
||||||
|
@ -12,11 +13,20 @@ import './index.css';
|
||||||
|
|
||||||
const history = createBrowserHistory();
|
const history = createBrowserHistory();
|
||||||
const store = createAppStore(history);
|
const store = createAppStore(history);
|
||||||
|
let hasTranslationsError = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fetchTranslations();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
hasTranslationsError = true;
|
||||||
|
}
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<App
|
<App
|
||||||
store={store}
|
store={store}
|
||||||
history={history}
|
history={history}
|
||||||
|
hasTranslationsError={hasTranslationsError}
|
||||||
/>,
|
/>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue