From 43c892b89ddd447ba7de9c6fef3184ac05a65434 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 16 Jul 2023 04:15:48 +0300 Subject: [PATCH] Revert "Fixed: Ensure translations are fetched before loading app" This reverts commit eeaea17c1f08878df27d82c968aa3b47fb82f605. --- frontend/build/webpack.config.js | 4 --- frontend/src/App/App.js | 7 ++--- frontend/src/Components/Page/ErrorPage.js | 4 --- frontend/src/Components/Page/PageConnector.js | 5 +--- frontend/src/Utilities/String/translate.js | 29 ++++++++----------- frontend/src/index.js | 5 +--- 6 files changed, 17 insertions(+), 37 deletions(-) diff --git a/frontend/build/webpack.config.js b/frontend/build/webpack.config.js index 9201a5e76..82601a415 100644 --- a/frontend/build/webpack.config.js +++ b/frontend/build/webpack.config.js @@ -84,10 +84,6 @@ module.exports = (env) => { hints: false }, - experiments: { - topLevelAwait: true - }, - plugins: [ new webpack.DefinePlugin({ __DEV__: !isProduction, diff --git a/frontend/src/App/App.js b/frontend/src/App/App.js index 3c1319331..3871b14e9 100644 --- a/frontend/src/App/App.js +++ b/frontend/src/App/App.js @@ -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 ( - + @@ -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; diff --git a/frontend/src/Components/Page/ErrorPage.js b/frontend/src/Components/Page/ErrorPage.js index 7c58a675b..4440cf3be 100644 --- a/frontend/src/Components/Page/ErrorPage.js +++ b/frontend/src/Components/Page/ErrorPage.js @@ -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, diff --git a/frontend/src/Components/Page/PageConnector.js b/frontend/src/Components/Page/PageConnector.js index 7340be1a2..985dcf9b9 100644 --- a/frontend/src/Components/Page/PageConnector.js +++ b/frontend/src/Components/Page/PageConnector.js @@ -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 ( ); } @@ -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, diff --git a/frontend/src/Utilities/String/translate.js b/frontend/src/Utilities/String/translate.js index 9e7452741..7529bb616 100644 --- a/frontend/src/Utilities/String/translate.js +++ b/frontend/src/Utilities/String/translate.js @@ -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 = {}; + url: '/localization', + success: function(data) { + localization = data.strings; + } + }; -export function fetchTranslations() { - return new Promise(async(resolve) => { - try { - const data = await getTranslations(); - translations = data.strings; + createAjaxRequest(ajaxOptions); - resolve(true); - } catch (error) { - resolve(false); - } - }); + return localization; } +const translations = getTranslations(); + export default function translate(key, args = []) { const translation = translations[key] || key; diff --git a/frontend/src/index.js b/frontend/src/index.js index 1c35b5872..40f4ae77c 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -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( , document.getElementById('root') );