mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 13:10:13 -07:00
Revert "Fixed: Ensure translations are fetched before loading app"
This reverts commit eeaea17c1f
.
This commit is contained in:
parent
eeaea17c1f
commit
43c892b89d
6 changed files with 18 additions and 38 deletions
|
@ -84,10 +84,6 @@ 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, hasTranslationsError }) {
|
function App({ store, history }) {
|
||||||
return (
|
return (
|
||||||
<DocumentTitle title={window.Lidarr.instanceName}>
|
<DocumentTitle title={window.Lidarr.instanceName}>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<ConnectedRouter history={history}>
|
<ConnectedRouter history={history}>
|
||||||
<ApplyTheme>
|
<ApplyTheme>
|
||||||
<PageConnector hasTranslationsError={hasTranslationsError}>
|
<PageConnector>
|
||||||
<AppRoutes app={App} />
|
<AppRoutes app={App} />
|
||||||
</PageConnector>
|
</PageConnector>
|
||||||
</ApplyTheme>
|
</ApplyTheme>
|
||||||
|
@ -25,8 +25,7 @@ function App({ store, history, hasTranslationsError }) {
|
||||||
|
|
||||||
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,7 +7,6 @@ function ErrorPage(props) {
|
||||||
const {
|
const {
|
||||||
version,
|
version,
|
||||||
isLocalStorageSupported,
|
isLocalStorageSupported,
|
||||||
hasTranslationsError,
|
|
||||||
artistError,
|
artistError,
|
||||||
customFiltersError,
|
customFiltersError,
|
||||||
tagsError,
|
tagsError,
|
||||||
|
@ -21,8 +20,6 @@ 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 (artistError) {
|
} else if (artistError) {
|
||||||
errorMessage = getErrorMessage(artistError, 'Failed to load artist from API');
|
errorMessage = getErrorMessage(artistError, 'Failed to load artist from API');
|
||||||
} else if (customFiltersError) {
|
} else if (customFiltersError) {
|
||||||
|
@ -55,7 +52,6 @@ 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,
|
|
||||||
artistError: PropTypes.object,
|
artistError: PropTypes.object,
|
||||||
customFiltersError: PropTypes.object,
|
customFiltersError: PropTypes.object,
|
||||||
tagsError: PropTypes.object,
|
tagsError: PropTypes.object,
|
||||||
|
|
|
@ -220,7 +220,6 @@ class PageConnector extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
hasTranslationsError,
|
|
||||||
isPopulated,
|
isPopulated,
|
||||||
hasError,
|
hasError,
|
||||||
dispatchFetchArtist,
|
dispatchFetchArtist,
|
||||||
|
@ -234,12 +233,11 @@ class PageConnector extends Component {
|
||||||
...otherProps
|
...otherProps
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (hasTranslationsError || hasError || !this.state.isLocalStorageSupported) {
|
if (hasError || !this.state.isLocalStorageSupported) {
|
||||||
return (
|
return (
|
||||||
<ErrorPage
|
<ErrorPage
|
||||||
{...this.state}
|
{...this.state}
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
hasTranslationsError={hasTranslationsError}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -260,7 +258,6 @@ 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,
|
||||||
|
|
|
@ -1,27 +1,22 @@
|
||||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||||
|
|
||||||
function getTranslations() {
|
function getTranslations() {
|
||||||
return createAjaxRequest({
|
let localization = null;
|
||||||
global: false,
|
const ajaxOptions = {
|
||||||
|
async: false,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
url: '/localization'
|
url: '/localization',
|
||||||
}).request;
|
success: function(data) {
|
||||||
|
localization = data.strings;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
createAjaxRequest(ajaxOptions);
|
||||||
|
|
||||||
|
return localization;
|
||||||
}
|
}
|
||||||
|
|
||||||
let translations = {};
|
const translations = getTranslations();
|
||||||
|
|
||||||
export function fetchTranslations() {
|
|
||||||
return new Promise(async(resolve) => {
|
|
||||||
try {
|
|
||||||
const data = await getTranslations();
|
|
||||||
translations = data.strings;
|
|
||||||
|
|
||||||
resolve(true);
|
|
||||||
} catch (error) {
|
|
||||||
resolve(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function translate(key, args = []) {
|
export default function translate(key, args = []) {
|
||||||
const translation = translations[key] || key;
|
const translation = translations[key] || key;
|
||||||
|
|
|
@ -2,7 +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 'Diag/ConsoleApi';
|
import 'Diag/ConsoleApi';
|
||||||
import './preload';
|
import './preload';
|
||||||
|
@ -12,14 +12,11 @@ import './index.css';
|
||||||
|
|
||||||
const history = createBrowserHistory();
|
const history = createBrowserHistory();
|
||||||
const store = createAppStore(history);
|
const store = createAppStore(history);
|
||||||
const hasTranslationsError = !await fetchTranslations();
|
|
||||||
const { default: App } = await import('./App/App');
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<App
|
<App
|
||||||
store={store}
|
store={store}
|
||||||
history={history}
|
history={history}
|
||||||
hasTranslationsError={hasTranslationsError}
|
|
||||||
/>,
|
/>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue