Merge branch 'develop' into feature/optimization

This commit is contained in:
Alexey Safronov 2021-09-15 11:47:29 +03:00 committed by GitHub
commit e2f977ce17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 142 additions and 301 deletions

View File

@ -326,7 +326,8 @@ class SettingsStore {
};
get firebaseHelper() {
return new FirebaseHelper(this.firebase);
window.firebaseHelper = new FirebaseHelper(this.firebase);
return window.firebaseHelper;
}
}

View File

@ -1,9 +1,12 @@
import firebase from "firebase/app";
import "firebase/remote-config";
import "firebase/storage";
class FirebaseHelper {
remoteConfig = null;
firebaseConfig = null;
firebaseStorage = null;
constructor(settings) {
this.firebaseConfig = settings;
@ -15,6 +18,8 @@ class FirebaseHelper {
firebase.app();
}
this.firebaseStorage = firebase.storage();
this.remoteConfig = firebase.remoteConfig();
this.remoteConfig.settings = {
@ -87,6 +92,22 @@ class FirebaseHelper {
return await Promise.resolve(campaigns);
}
async getCampaignsImages(banner) {
const storageRef = this.firebaseStorage.ref();
const tangRef = storageRef.child(
`campaigns/images/campaigns.${banner}.png`
);
return await tangRef.getDownloadURL();
}
async getCampaignsTranslations(banner, lng) {
const storageRef = this.firebaseStorage.ref();
const tangRef = storageRef.child(
`campaigns/locales/${lng}/CampaignPersonal${banner}.json`
);
return await tangRef.getDownloadURL();
}
}
export default FirebaseHelper;

View File

@ -247,7 +247,7 @@ export function getProviderTranslation(provider, t) {
}
}
function getLanguage(lng) {
export function getLanguage(lng) {
try {
let language = lng == "en-US" || lng == "en-GB" ? "en" : lng;
@ -272,9 +272,6 @@ export function loadLanguagePath(homepage, fixedNS = null) {
if (ns.length > 0 && ns[0] === "Common") {
return `/static/locales/${language}/Common.json`;
}
if (ns.length > 0 && ns[0].includes("Campaign")) {
return `/static/locales/${language}/${ns[0]}.json`;
}
return `${homepage}/locales/${language}/${fixedNS || ns}.json`;
};
}

View File

@ -1,9 +1,10 @@
import React from "react";
import React, { useState } from "react";
import PropTypes from "prop-types";
import BannerWrapper from "./styled-campaigns-banner";
import Button from "../button";
import Text from "../text";
import Loaders from "@appserver/common/components/Loaders";
const onButtonClick = (url) => {
window.location = url;
@ -11,6 +12,11 @@ const onButtonClick = (url) => {
const CampaignsBanner = (props) => {
const { headerLabel, subHeaderLabel, img, btnLabel, link } = props;
const [imageLoad, setImageLoad] = useState(false);
const handleImageLoaded = () => {
setImageLoad(true);
};
const onMouseDown = (e) => {
e.preventDefault();
@ -26,7 +32,8 @@ const CampaignsBanner = (props) => {
{subHeaderLabel}
</Text>
<img src={img} onMouseDown={onMouseDown} />
{!imageLoad && <Loaders.Rectangle height="140px" borderRadius="5px" />}
<img src={img} onMouseDown={onMouseDown} onLoad={handleImageLoaded} />
</a>
<Button

View File

@ -36,7 +36,7 @@ const BannerWrapper = styled.div`
.banner-btn:active {
color: #fff;
background: #ed7309;
background: #2da7db;
border: none;
}
`;

View File

@ -1,17 +1,55 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { withTranslation } from "react-i18next";
import i18n from "i18next";
import Backend from "i18next-http-backend";
import { getLanguage } from "@appserver/common/utils";
import CampaignsBanner from "@appserver/components/campaigns-banner";
import { ADS_TIMEOUT } from "../../../helpers/constants";
import { LANGUAGE } from "@appserver/common/constants";
const i18nConfig = i18n.createInstance();
let translationUrl;
const loadLanguagePath = async () => {
if (!window.firebaseHelper) return;
const lng = localStorage.getItem(LANGUAGE) || "en";
const language = getLanguage(lng instanceof Array ? lng[0] : lng);
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
const index = Number(localStorage.getItem("bannerIndex") || 0);
const campaign = campaigns[index];
try {
translationUrl = await window.firebaseHelper.getCampaignsTranslations(
campaign,
language
);
} catch (e) {
translationUrl = await window.firebaseHelper.getCampaignsTranslations(
campaign,
"en"
);
//console.error(e);
}
return translationUrl;
};
const bannerHOC = (WrappedComponent) => (props) => {
const { FirebaseHelper } = props;
const Banner = () => {
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
const defaultBannerName = "Cloud";
const [bannerName, setBannerName] = useState(defaultBannerName);
const [bannerImage, setBannerImage] = useState("");
const [bannerTranslation, setBannerTranslation] = useState();
useEffect(() => {
const updateBanner = async () => {
let index = Number(localStorage.getItem("bannerIndex") || 0);
const campaign = campaigns[index];
@ -21,31 +59,72 @@ const Banner = () => {
index++;
}
try {
const translationUrl = await loadLanguagePath();
setBannerTranslation(translationUrl);
i18nConfig.use(Backend).init({
lng: localStorage.getItem(LANGUAGE) || "en",
fallbackLng: "en",
load: "all",
debug: false,
defaultNS: "",
backend: {
loadPath: function () {
return translationUrl;
},
},
});
const image = await FirebaseHelper.getCampaignsImages(
campaign.toLowerCase()
);
setBannerImage(image);
} catch (e) {
updateBanner();
//console.error(e);
}
localStorage.setItem("bannerIndex", index);
setBannerName(campaign);
};
useEffect(() => {
updateBanner();
setInterval(updateBanner, ADS_TIMEOUT);
}, []);
const { t, i18n, ready } = useTranslation(`CampaignPersonal${bannerName}`, {
useSuspense: false,
});
if (!bannerTranslation || !bannerImage) return <></>;
if (
!campaigns.length ||
!ready ||
!i18n.exists(`CampaignPersonal${bannerName}:Header`)
) {
return <WrappedComponent bannerImage={bannerImage} {...props} />;
};
const Banner = (props) => {
//console.log("Banner render", props);
const { t, tReady, bannerImage } = props;
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
if (!campaigns.length || !tReady) {
return <></>;
}
return (
<CampaignsBanner
headerLabel={t(`CampaignPersonal${bannerName}:Header`)}
subHeaderLabel={t(`CampaignPersonal${bannerName}:SubHeader`)}
img={`/static/images/campaigns.${bannerName.toLowerCase()}.png`}
btnLabel={t(`CampaignPersonal${bannerName}:ButtonLabel`)}
link={t(`CampaignPersonal${bannerName}:Link`)}
headerLabel={t("Header")}
subHeaderLabel={t("SubHeader")}
img={bannerImage}
btnLabel={t("ButtonLabel")}
link={t("Link")}
/>
);
};
export default Banner;
const BannerWithTranslation = withTranslation()(Banner);
const WrapperBanner = (props) => (
<BannerWithTranslation i18n={i18nConfig} useSuspense={false} {...props} />
);
export default bannerHOC(WrapperBanner);

View File

@ -12,7 +12,7 @@ import Banner from "./Banner";
import { inject, observer } from "mobx-react";
import { withRouter } from "react-router-dom";
import config from "../../../../package.json";
import { combineUrl } from "@appserver/common/utils";
import { clickBackdrop, combineUrl } from "@appserver/common/utils";
import { AppServerConfig } from "@appserver/common/constants";
import FilesFilter from "@appserver/common/api/files/filter";
import { isDesktop, isTablet } from "react-device-detect";
@ -71,6 +71,7 @@ class ArticleBodyContent extends React.Component {
personal,
firstLoad,
isDesktopClient,
FirebaseHelper,
} = this.props;
//console.log("Article Body render");
@ -99,7 +100,9 @@ class ArticleBodyContent extends React.Component {
{(isDesktop || isTablet) &&
personal &&
!firstLoad &&
campaigns.length > 0 && <Banner />}
campaigns.length > 0 && (
<Banner FirebaseHelper={FirebaseHelper} />
)}
</>
)}
</>
@ -145,6 +148,7 @@ export default inject(
hideArticle,
firstLoad,
isDesktopClient,
FirebaseHelper: auth.settingsStore.firebaseHelper,
};
}
)(observer(withRouter(ArticleBodyContent)));

View File

@ -8,3 +8,5 @@ export const thumbnailStatuses = {
ERROR: 2,
NOT_REQUIRED: 3,
};
export const ADS_TIMEOUT = 60000;

View File

@ -25,7 +25,7 @@ newInstance.use(Backend).init({
backend: {
loadPath: loadLanguagePath(config.homepage),
allowMultiLoading: false,
crossDomain: false,
crossDomain: true,
},
react: {

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE für Business",
"SubHeader": "Dokumente, Projekte, Kunden & E-Mails",
"ButtonLabel": "Kostenlos testen",
"Link": "https://www.onlyoffice.com/de/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE für PC",
"SubHeader": "Gratis Alternative zu MS Office",
"ButtonLabel": "Herunterladen",
"Link": "https://www.onlyoffice.com/de/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE für Schulen",
"SubHeader": "Endecken Sie alle Rabatte",
"ButtonLabel": "Mehr erfahren",
"Link": "https://www.onlyoffice.com/de/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE On-Premises",
"SubHeader": "Schützen Sie Ihre Dokumente",
"ButtonLabel": "Jetzt erhalten",
"Link": "https://www.onlyoffice.com/de/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE Integration",
"SubHeader": "Editoren für Ihre Plattform",
"ButtonLabel": "Jetzt integrieren",
"Link": "https://www.onlyoffice.com/de/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for business",
"SubHeader": "Docs, projects, clients & emails",
"ButtonLabel": "Start free trial",
"Link": "https://www.onlyoffice.com/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for PC",
"SubHeader": "Get a free alternative to MS Office",
"ButtonLabel": "Download",
"Link": "https://www.onlyoffice.com/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for schools",
"SubHeader": "Learn about education discounts",
"ButtonLabel": "Learn more",
"Link": "https://www.onlyoffice.com/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE on-premises",
"SubHeader": "Keep your docs and projects safe",
"ButtonLabel": "Get it now",
"Link": "https://www.onlyoffice.com/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for integration",
"SubHeader": "Use online editors with your platform",
"ButtonLabel": "Integrate now",
"Link": "https://www.onlyoffice.com/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE pour les entreprises",
"SubHeader": "Documents, projets, clients et mails.",
"ButtonLabel": "Commencer lessai gratuit",
"Link": "https://www.onlyoffice.com/fr/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE pour le PC",
"SubHeader": "Alternative gratuite à MS Office",
"ButtonLabel": "Télécharger",
"Link": "https://www.onlyoffice.com/fr/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE éducation",
"SubHeader": "Voir toutes les offres",
"ButtonLabel": "En savoir plus",
"Link": "https://www.onlyoffice.com/fr/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "Solution auto-hébergée",
"SubHeader": "Vos docs en toute sécurité",
"ButtonLabel": "Obtenir maintenant",
"Link": "https://www.onlyoffice.com/fr/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE intégration",
"SubHeader": "Éditeurs pour votre plateforme",
"ButtonLabel": "Intégrer maintenant",
"Link": "https://www.onlyoffice.com/fr/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE per business",
"SubHeader": "Documenti, progetti, clienti ed e-mail",
"ButtonLabel": "Inizia la prova gratuita",
"Link": "https://www.onlyoffice.com/it/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE per PC",
"SubHeader": "Alternativa gratuita a MS Office",
"ButtonLabel": "Scarica",
"Link": "https://www.onlyoffice.com/it/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE per scuole",
"SubHeader": "Informazioni sugli sconti",
"ButtonLabel": "Per saperne di più",
"Link": "https://www.onlyoffice.com/it/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE sul server",
"SubHeader": "Mantieni documenti al sicuro",
"ButtonLabel": "Scaricalo ora",
"Link": "https://www.onlyoffice.com/it/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE integrazioni",
"SubHeader": "Editor per la tua piattaforma",
"ButtonLabel": "Connetti ora",
"Link": "https://www.onlyoffice.com/it/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for business",
"SubHeader": "Docs, projects, clients & emails",
"ButtonLabel": "Start free trial",
"Link": "https://www.onlyoffice.com/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for PC",
"SubHeader": "Get a free alternative to MS Office",
"ButtonLabel": "Download",
"Link": "https://www.onlyoffice.com/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for schools",
"SubHeader": "Learn about education discounts",
"ButtonLabel": "Learn more",
"Link": "https://www.onlyoffice.com/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE on-premises",
"SubHeader": "Keep your docs and projects safe",
"ButtonLabel": "Get it now",
"Link": "https://www.onlyoffice.com/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for integration",
"SubHeader": "Use online editors with your platform",
"ButtonLabel": "Integrate now",
"Link": "https://www.onlyoffice.com/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for business",
"SubHeader": "Docs, projects, clients & emails",
"ButtonLabel": "Start free trial",
"Link": "https://www.onlyoffice.com/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for PC",
"SubHeader": "Get a free alternative to MS Office",
"ButtonLabel": "Download",
"Link": "https://www.onlyoffice.com/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for schools",
"SubHeader": "Learn about education discounts",
"ButtonLabel": "Learn more",
"Link": "https://www.onlyoffice.com/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE on-premises",
"SubHeader": "Keep your docs and projects safe",
"ButtonLabel": "Get it now",
"Link": "https://www.onlyoffice.com/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for integration",
"SubHeader": "Use online editors with your platform",
"ButtonLabel": "Integrate now",
"Link": "https://www.onlyoffice.com/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for business",
"SubHeader": "Docs, projects, clients & emails",
"ButtonLabel": "Start free trial",
"Link": "https://www.onlyoffice.com/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for PC",
"SubHeader": "Get a free alternative to MS Office",
"ButtonLabel": "Download",
"Link": "https://www.onlyoffice.com/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for schools",
"SubHeader": "Learn about education discounts",
"ButtonLabel": "Learn more",
"Link": "https://www.onlyoffice.com/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE on-premises",
"SubHeader": "Keep your docs and projects safe",
"ButtonLabel": "Get it now",
"Link": "https://www.onlyoffice.com/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for integration",
"SubHeader": "Use online editors with your platform",
"ButtonLabel": "Integrate now",
"Link": "https://www.onlyoffice.com/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE для бизнеса",
"SubHeader": "Документы, проекты, клиенты и почта",
"ButtonLabel": "Начните бесплатно",
"Link": "https://www.onlyoffice.com/ru/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE для ПК",
"SubHeader": "Получите бесплатную альтернативу MS Office",
"ButtonLabel": "Скачать",
"Link": "https://www.onlyoffice.com/ru/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE для школ",
"SubHeader": "Узнайте больше об образовательных скидках",
"ButtonLabel": "Узнать больше",
"Link": "https://www.onlyoffice.com/ru/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE локально",
"SubHeader": "Обеспечьте сохранность документов и проектов",
"ButtonLabel": "Получить сейчас",
"Link": "https://www.onlyoffice.com/ru/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE для интеграции",
"SubHeader": "Используйте онлайн-редакторы с вашей платформой",
"ButtonLabel": "Интегрировать сейчас",
"Link": "https://www.onlyoffice.com/ru/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for business",
"SubHeader": "Docs, projects, clients & emails",
"ButtonLabel": "Start free trial",
"Link": "https://www.onlyoffice.com/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for PC",
"SubHeader": "Get a free alternative to MS Office",
"ButtonLabel": "Download",
"Link": "https://www.onlyoffice.com/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for schools",
"SubHeader": "Learn about education discounts",
"ButtonLabel": "Learn more",
"Link": "https://www.onlyoffice.com/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE on-premises",
"SubHeader": "Keep your docs and projects safe",
"ButtonLabel": "Get it now",
"Link": "https://www.onlyoffice.com/download-commercial.aspx?utm_source=personal&utm_campaign=BannerPersonalEnterprise"
}

View File

@ -1,6 +0,0 @@
{
"Header": "ONLYOFFICE for integration",
"SubHeader": "Use online editors with your platform",
"ButtonLabel": "Integrate now",
"Link": "https://www.onlyoffice.com/connectors.aspx?utm_source=personal&utm_campaign=BannerPersonalIntegration"
}