Revert "Fixed: Ensure translations are fetched before loading app"

This reverts commit eeaea17c1f.
This commit is contained in:
Bogdan 2023-07-16 04:15:48 +03:00
parent eeaea17c1f
commit 43c892b89d
6 changed files with 18 additions and 38 deletions

View File

@ -84,10 +84,6 @@ module.exports = (env) => {
hints: false
},
experiments: {
topLevelAwait: true
},
plugins: [
new webpack.DefinePlugin({
__DEV__: !isProduction,

View File

@ -7,13 +7,13 @@ import PageConnector from 'Components/Page/PageConnector';
import ApplyTheme from './ApplyTheme';
import AppRoutes from './AppRoutes';
function App({ store, history, hasTranslationsError }) {
function App({ store, history }) {
return (
<DocumentTitle title={window.Lidarr.instanceName}>
<Provider store={store}>
<ConnectedRouter history={history}>
<ApplyTheme>
<PageConnector hasTranslationsError={hasTranslationsError}>
<PageConnector>
<AppRoutes app={App} />
</PageConnector>
</ApplyTheme>
@ -25,8 +25,7 @@ function App({ store, history, hasTranslationsError }) {
App.propTypes = {
store: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
hasTranslationsError: PropTypes.bool.isRequired
history: PropTypes.object.isRequired
};
export default App;

View File

@ -7,7 +7,6 @@ function ErrorPage(props) {
const {
version,
isLocalStorageSupported,
hasTranslationsError,
artistError,
customFiltersError,
tagsError,
@ -21,8 +20,6 @@ function ErrorPage(props) {
if (!isLocalStorageSupported) {
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) {
errorMessage = getErrorMessage(artistError, 'Failed to load artist from API');
} else if (customFiltersError) {
@ -55,7 +52,6 @@ function ErrorPage(props) {
ErrorPage.propTypes = {
version: PropTypes.string.isRequired,
isLocalStorageSupported: PropTypes.bool.isRequired,
hasTranslationsError: PropTypes.bool.isRequired,
artistError: PropTypes.object,
customFiltersError: PropTypes.object,
tagsError: PropTypes.object,

View File

@ -220,7 +220,6 @@ class PageConnector extends Component {
render() {
const {
hasTranslationsError,
isPopulated,
hasError,
dispatchFetchArtist,
@ -234,12 +233,11 @@ class PageConnector extends Component {
...otherProps
} = this.props;
if (hasTranslationsError || hasError || !this.state.isLocalStorageSupported) {
if (hasError || !this.state.isLocalStorageSupported) {
return (
<ErrorPage
{...this.state}
{...otherProps}
hasTranslationsError={hasTranslationsError}
/>
);
}
@ -260,7 +258,6 @@ class PageConnector extends Component {
}
PageConnector.propTypes = {
hasTranslationsError: PropTypes.bool.isRequired,
isPopulated: PropTypes.bool.isRequired,
hasError: PropTypes.bool.isRequired,
isSidebarVisible: PropTypes.bool.isRequired,

View File

@ -1,28 +1,23 @@
import createAjaxRequest from 'Utilities/createAjaxRequest';
function getTranslations() {
return createAjaxRequest({
global: false,
let localization = null;
const ajaxOptions = {
async: false,
dataType: 'json',
url: '/localization'
}).request;
}
let translations = {};
export function fetchTranslations() {
return new Promise(async(resolve) => {
try {
const data = await getTranslations();
translations = data.strings;
resolve(true);
} catch (error) {
resolve(false);
url: '/localization',
success: function(data) {
localization = data.strings;
}
});
};
createAjaxRequest(ajaxOptions);
return localization;
}
const translations = getTranslations();
export default function translate(key, args = []) {
const translation = translations[key] || key;

View File

@ -2,7 +2,7 @@ import { createBrowserHistory } from 'history';
import React from 'react';
import { render } from 'react-dom';
import createAppStore from 'Store/createAppStore';
import { fetchTranslations } from 'Utilities/String/translate';
import App from './App/App';
import 'Diag/ConsoleApi';
import './preload';
@ -12,14 +12,11 @@ import './index.css';
const history = createBrowserHistory();
const store = createAppStore(history);
const hasTranslationsError = !await fetchTranslations();
const { default: App } = await import('./App/App');
render(
<App
store={store}
history={history}
hasTranslationsError={hasTranslationsError}
/>,
document.getElementById('root')
);