Web:Studio:Added HOC withLoading.

This commit is contained in:
Vlada Gazizova 2022-04-19 10:26:48 +03:00
parent f48809b13a
commit e0f8e6eea4
6 changed files with 151 additions and 92 deletions

View File

@ -4,11 +4,11 @@ import { ArticleHeaderContent, ArticleBodyContent } from "./Article";
import { SectionHeaderContent, SectionPagingContent } from "./Section"; import { SectionHeaderContent, SectionPagingContent } from "./Section";
import { inject, observer } from "mobx-react"; import { inject, observer } from "mobx-react";
import Section from "@appserver/common/components/Section"; import Section from "@appserver/common/components/Section";
import LoaderSectionHeader from "./Section/loaderSectionHeader"; import withLoading from "../../../../HOCs/withLoading";
import commonIconsStyles from "@appserver/components/utils/common-icons-style";
const ArticleSettings = React.memo(() => { const ArticleSettings = React.memo(({ isLoadedPage }) => {
return ( return (
<Article> <Article isLoadedPage={isLoadedPage}>
<Article.Header> <Article.Header>
<ArticleHeaderContent /> <ArticleHeaderContent />
</Article.Header> </Article.Header>
@ -26,6 +26,7 @@ const Layout = ({
language, language,
children, children,
addUsers, addUsers,
isLoadedPage,
}) => { }) => {
useEffect(() => { useEffect(() => {
currentProductId !== "settings" && setCurrentProductId("settings"); currentProductId !== "settings" && setCurrentProductId("settings");
@ -33,7 +34,7 @@ const Layout = ({
return ( return (
<> <>
<ArticleSettings /> <ArticleSettings isLoadedPage={isLoadedPage} />
<Section withBodyScroll={true}> <Section withBodyScroll={true}>
<Section.SectionHeader> <Section.SectionHeader>
<SectionHeaderContent /> <SectionHeaderContent />
@ -53,9 +54,10 @@ const Layout = ({
export default inject(({ auth, setup }) => { export default inject(({ auth, setup }) => {
const { language, settingsStore } = auth; const { language, settingsStore } = auth;
const { addUsers } = setup.headerAction; const { addUsers } = setup.headerAction;
return { return {
language, language,
setCurrentProductId: settingsStore.setCurrentProductId, setCurrentProductId: settingsStore.setCurrentProductId,
addUsers, addUsers,
}; };
})(observer(Layout)); })(withLoading(observer(Layout)));

View File

@ -1,4 +1,4 @@
import React from "react"; import React, { useEffect } from "react";
import { withTranslation } from "react-i18next"; import { withTranslation } from "react-i18next";
import styled from "styled-components"; import styled from "styled-components";
import Text from "@appserver/components/text"; import Text from "@appserver/components/text";
@ -11,9 +11,8 @@ import withCultureNames from "@appserver/common/hoc/withCultureNames";
import history from "@appserver/common/history"; import history from "@appserver/common/history";
import { Base } from "@appserver/components/themes"; import { Base } from "@appserver/components/themes";
import LoaderCustomizationNavbar from "./sub-components/loaderCustomizationNavbar"; import LoaderCustomizationNavbar from "./sub-components/loaderCustomizationNavbar";
import { StyledArrowRightIcon } from "../common/settingsCustomization/StyledSettings"; import { StyledArrowRightIcon } from "../common/settingsCustomization/StyledSettings";
import { withRouter } from "react-router";
const StyledComponent = styled.div` const StyledComponent = styled.div`
padding-top: 13px; padding-top: 13px;
@ -47,15 +46,28 @@ const StyledComponent = styled.div`
StyledComponent.defaultProps = { theme: Base }; StyledComponent.defaultProps = { theme: Base };
const CustomizationNavbar = ({ t, theme, helpUrlCommonSettings }) => { const CustomizationNavbar = ({
t,
theme,
helpUrlCommonSettings,
isLoaded,
tReady,
setIsLoadedCustomizationNavbar,
isLoadedPage,
}) => {
const isLoadedSetting = isLoaded && tReady;
useEffect(() => {
if (isLoadedSetting) setIsLoadedCustomizationNavbar(isLoadedSetting);
}, [isLoadedSetting]);
const onClickLink = (e) => { const onClickLink = (e) => {
e.preventDefault(); e.preventDefault();
history.push(e.target.pathname); history.push(e.target.pathname);
}; };
//return <LoaderCustomizationNavbar />; return !isLoadedPage ? (
<LoaderCustomizationNavbar />
return ( ) : (
<StyledComponent> <StyledComponent>
<div className="category-item-wrapper"> <div className="category-item-wrapper">
<div className="category-item-heading"> <div className="category-item-heading">
@ -128,14 +140,19 @@ const CustomizationNavbar = ({ t, theme, helpUrlCommonSettings }) => {
); );
}; };
export default inject(({ auth }) => { export default inject(({ auth, common }) => {
const { helpUrlCommonSettings, theme } = auth.settingsStore; const { helpUrlCommonSettings, theme } = auth.settingsStore;
const { isLoaded, setIsLoadedCustomizationNavbar } = common;
return { return {
theme, theme,
helpUrlCommonSettings, helpUrlCommonSettings,
isLoaded,
setIsLoadedCustomizationNavbar,
}; };
})( })(
withCultureNames( withRouter(
observer(withTranslation(["Settings", "Common"])(CustomizationNavbar)) withCultureNames(
observer(withTranslation(["Settings", "Common"])(CustomizationNavbar))
)
) )
); );

View File

@ -11,6 +11,8 @@ import CustomizationNavbar from "./customization-navbar";
import { Base } from "@appserver/components/themes"; import { Base } from "@appserver/components/themes";
import { setDocumentTitle } from "../../../../../helpers/utils"; import { setDocumentTitle } from "../../../../../helpers/utils";
import LoaderDescriptionCustomization from "./sub-components/loaderDescriptionCustomization"; import LoaderDescriptionCustomization from "./sub-components/loaderDescriptionCustomization";
import { withRouter } from "react-router";
import withLoading from "../../../../../HOCs/withLoading";
const StyledComponent = styled.div` const StyledComponent = styled.div`
width: 100%; width: 100%;
@ -65,9 +67,24 @@ const StyledComponent = styled.div`
StyledComponent.defaultProps = { theme: Base }; StyledComponent.defaultProps = { theme: Base };
const Customization = ({ t, setIsLoadingArticleSettings }) => { const Customization = (props) => {
const { t, isLoaded, tReady, setIsLoadedCustomization, isLoadedPage } = props;
const [mobileView, setMobileView] = useState(true); const [mobileView, setMobileView] = useState(true);
const [isLoadingCustomization, setIsLoadingCustomization] = useState(false);
const isLoadedSetting = isLoaded && tReady;
useEffect(() => {
setDocumentTitle(t("Customization"));
window.addEventListener("resize", checkInnerWidth);
return () => window.removeEventListener("resize", checkInnerWidth);
}, []);
useEffect(() => {
if (isLoadedSetting) {
setIsLoadedCustomization(isLoadedSetting);
}
}, [isLoadedSetting]);
const checkInnerWidth = () => { const checkInnerWidth = () => {
if (isSmallTablet()) { if (isSmallTablet()) {
@ -77,47 +94,35 @@ const Customization = ({ t, setIsLoadingArticleSettings }) => {
} }
}; };
useEffect(() => {
setDocumentTitle(t("Customization"));
//TODO: Add method to get the portal name
setIsLoadingArticleSettings(true);
setTimeout(() => {
setIsLoadingCustomization(false);
setIsLoadingArticleSettings(isLoadingCustomization);
}, 3000);
window.addEventListener("resize", checkInnerWidth);
return () => window.removeEventListener("resize", checkInnerWidth);
}, []);
const isMobile = !!(isSmallTablet() && mobileView); const isMobile = !!(isSmallTablet() && mobileView);
return isMobile ? ( return isMobile ? (
<CustomizationNavbar /> <CustomizationNavbar isLoadedPage={isLoadedPage} />
) : ( ) : (
<StyledComponent> <StyledComponent>
<div className="category-description">{`${t( {!isLoadedPage ? (
"Settings:CustomizationDescription" <LoaderDescriptionCustomization />
)}`}</div> ) : (
{/* <LoaderDescriptionCustomization /> */} <div className="category-description">{`${t(
<LanguageAndTimeZone "Settings:CustomizationDescription"
isLoadingCustomization={isLoadingCustomization} )}`}</div>
isMobileView={isMobile} )}
/> <LanguageAndTimeZone isMobileView={isMobile} />
<WelcomePageSettings isMobileView={isMobile} /> <WelcomePageSettings isMobileView={isMobile} />
<PortalRenaming isMobileView={isMobile} /> <PortalRenaming isMobileView={isMobile} />
</StyledComponent> </StyledComponent>
); );
}; };
export default inject(({ setup }) => { export default inject(({ common }) => {
const { setIsLoadingArticleSettings } = setup; const { isLoaded, setIsLoadedCustomization } = common;
return { return {
setIsLoadingArticleSettings, isLoaded,
setIsLoadedCustomization,
}; };
})( })(
withCultureNames( withLoading(
withTranslation(["Settings", "Common"])(observer(Customization)) withRouter(withTranslation(["Settings", "Common"])(observer(Customization)))
) )
); );

View File

@ -5,15 +5,35 @@ import { withTranslation } from "react-i18next";
import { AppServerConfig } from "@appserver/common/constants"; import { AppServerConfig } from "@appserver/common/constants";
import { combineUrl } from "@appserver/common/utils"; import { combineUrl } from "@appserver/common/utils";
import config from "../../../../../../package.json"; import config from "../../../../../../package.json";
import { inject, observer } from "mobx-react";
import Customization from "./customization"; import Customization from "./customization";
import WhiteLabel from "./whitelabel"; import WhiteLabel from "./whitelabel";
import LoaderSubmenu from "./sub-components/loaderSubmenu"; import withLoading from "../../../../../HOCs/withLoading";
const SubmenuCommon = (props) => { const SubmenuCommon = (props) => {
const { t, history } = props; const {
t,
history,
isLoaded,
tReady,
setIsLoadedSubmenu,
isLoadedPage,
} = props;
const [currentTab, setCurrentTab] = useState(0); const [currentTab, setCurrentTab] = useState(0);
const [isLoading, setIsLoading] = useState(false);
const isLoadedSetting = isLoaded && tReady;
useEffect(() => {
const path = location.pathname;
const currentTab = data.findIndex((item) => path.includes(item.id));
if (currentTab !== -1) {
setCurrentTab(currentTab);
}
}, []);
useEffect(() => {
if (isLoadedSetting) setIsLoadedSubmenu(isLoadedSetting);
}, [isLoadedSetting]);
const data = [ const data = [
{ {
@ -28,15 +48,6 @@ const SubmenuCommon = (props) => {
}, },
]; ];
useEffect(() => {
const path = location.pathname;
const currentTab = data.findIndex((item) => path.includes(item.id));
if (currentTab !== -1) {
setCurrentTab(currentTab);
}
//setIsLoading(true);
}, []);
const onSelect = (e) => { const onSelect = (e) => {
history.push( history.push(
combineUrl( combineUrl(
@ -46,16 +57,23 @@ const SubmenuCommon = (props) => {
) )
); );
}; };
//TODO: isLoading
return isLoading ? ( return (
<LoaderSubmenu />
) : (
<Submenu <Submenu
data={data} data={data}
startSelect={currentTab} startSelect={currentTab}
onSelect={(e) => onSelect(e)} onSelect={(e) => onSelect(e)}
isLoading={!isLoadedPage}
/> />
); );
}; };
export default withTranslation("Settings")(withRouter(SubmenuCommon)); export default inject(({ common }) => {
const { isLoaded, setIsLoadedSubmenu } = common;
return {
isLoaded,
setIsLoadedSubmenu,
};
})(
withLoading(withRouter(withTranslation("Settings")(observer(SubmenuCommon))))
);

View File

@ -1,6 +1,5 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { withTranslation } from "react-i18next"; import { withTranslation } from "react-i18next";
import Loader from "@appserver/components/loader";
import toastr from "@appserver/components/toast/toastr"; import toastr from "@appserver/components/toast/toastr";
import HelpButton from "@appserver/components/help-button"; import HelpButton from "@appserver/components/help-button";
import FieldContainer from "@appserver/components/field-container"; import FieldContainer from "@appserver/components/field-container";
@ -19,10 +18,18 @@ import { StyledSettingsComponent, StyledScrollbar } from "./StyledSettings";
import { saveToSessionStorage, getFromSessionStorage } from "../../../utils"; import { saveToSessionStorage, getFromSessionStorage } from "../../../utils";
import { setDocumentTitle } from "../../../../../../helpers/utils"; import { setDocumentTitle } from "../../../../../../helpers/utils";
import LoaderCustomization from "../sub-components/loaderCustomization"; import LoaderCustomization from "../sub-components/loaderCustomization";
import withLoading from "../../../../../../HOCs/withLoading";
const PortalRenaming = (props) => {
const {
t,
setPortalRename,
isMobileView,
tReady,
isLoaded,
setIsLoadedPortalRenaming,
isLoadedPage,
} = props;
const PortalRenaming = ({ t, setPortalRename, isMobileView }) => {
// TODO: Change false
const [isLoadedData, setIsLoadedData] = useState(true);
const [isLoadingPortalNameSave, setIsLoadingPortalNameSave] = useState(false); const [isLoadingPortalNameSave, setIsLoadingPortalNameSave] = useState(false);
const portalNameFromSessionStorage = getFromSessionStorage("portalName"); const portalNameFromSessionStorage = getFromSessionStorage("portalName");
@ -46,6 +53,8 @@ const PortalRenaming = ({ t, setPortalRename, isMobileView }) => {
const lengthNameError = const lengthNameError =
"The account name must be between 6 and 50 characters long"; "The account name must be between 6 and 50 characters long";
const isLoadedSetting = isLoaded && tReady;
useEffect(() => { useEffect(() => {
setDocumentTitle(t("PortalRenaming")); setDocumentTitle(t("PortalRenaming"));
@ -77,6 +86,10 @@ const PortalRenaming = ({ t, setPortalRename, isMobileView }) => {
); );
}, []); }, []);
useEffect(() => {
if (isLoadedSetting) setIsLoadedPortalRenaming(isLoadedSetting);
}, [isLoadedSetting]);
//TODO: Need a method to get the portal name //TODO: Need a method to get the portal name
const onSavePortalRename = () => { const onSavePortalRename = () => {
setIsLoadingPortalNameSave(true); setIsLoadingPortalNameSave(true);
@ -187,9 +200,8 @@ const PortalRenaming = ({ t, setPortalRename, isMobileView }) => {
</div> </div>
); );
//return <LoaderCustomization portalRenaming={true} />; return !isLoadedPage ? (
return !isLoadedData ? ( <LoaderCustomization portalRenaming={true} />
<Loader className="pageLoader" type="rombs" size="40px" />
) : ( ) : (
<StyledSettingsComponent <StyledSettingsComponent
hasScroll={hasScroll} hasScroll={hasScroll}
@ -225,12 +237,16 @@ const PortalRenaming = ({ t, setPortalRename, isMobileView }) => {
); );
}; };
export default inject(({ auth, setup }) => { export default inject(({ auth, setup, common }) => {
const { theme } = auth.settingsStore; const { theme } = auth.settingsStore;
const { setPortalRename } = setup; const { setPortalRename } = setup;
const { isLoaded, setIsLoadedPortalRenaming } = common;
return { return {
theme, theme,
setPortalRename, setPortalRename,
isLoaded,
setIsLoadedPortalRenaming,
}; };
})(withTranslation(["Settings", "Common"])(observer(PortalRenaming))); })(
withLoading(withTranslation(["Settings", "Common"])(observer(PortalRenaming)))
);

View File

@ -20,6 +20,7 @@ import { isSmallTablet } from "@appserver/components/utils/device";
import checkScrollSettingsBlock from "../utils"; import checkScrollSettingsBlock from "../utils";
import { StyledSettingsComponent, StyledScrollbar } from "./StyledSettings"; import { StyledSettingsComponent, StyledScrollbar } from "./StyledSettings";
import LoaderCustomization from "../sub-components/loaderCustomization"; import LoaderCustomization from "../sub-components/loaderCustomization";
import withLoading from "../../../../../../HOCs/withLoading";
let greetingTitleFromSessionStorage = ""; let greetingTitleFromSessionStorage = "";
let greetingTitleDefaultFromSessionStorage = ""; let greetingTitleDefaultFromSessionStorage = "";
@ -45,7 +46,6 @@ class WelcomePageSettings extends React.Component {
setDocumentTitle(t("CustomTitlesWelcome")); setDocumentTitle(t("CustomTitlesWelcome"));
this.state = { this.state = {
isLoadedData: false,
isLoading: false, isLoading: false,
greetingTitle: greetingTitleFromSessionStorage || greetingSettings, greetingTitle: greetingTitleFromSessionStorage || greetingSettings,
greetingTitleDefault: greetingTitleDefault:
@ -61,15 +61,17 @@ class WelcomePageSettings extends React.Component {
componentDidMount() { componentDidMount() {
window.addEventListener("resize", this.checkInnerWidth); window.addEventListener("resize", this.checkInnerWidth);
showLoader();
this.setState({
isLoadedData: true,
});
hideLoader();
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
const { isLoaded, setIsLoadedWelcomePageSettings, tReady } = this.props;
const { hasScroll } = this.state; const { hasScroll } = this.state;
const isLoadedSetting = isLoaded && tReady;
if (isLoadedSetting) setIsLoadedWelcomePageSettings(isLoadedSetting);
const checkScroll = checkScrollSettingsBlock(); const checkScroll = checkScrollSettingsBlock();
window.addEventListener("resize", checkScroll); window.addEventListener("resize", checkScroll);
@ -90,12 +92,6 @@ class WelcomePageSettings extends React.Component {
settingsMobile.style.display = "none"; settingsMobile.style.display = "none";
} }
if (prevState.isLoadedData !== true) {
this.setState({
isLoadedData: true,
});
}
if (this.state.greetingTitleDefault) { if (this.state.greetingTitleDefault) {
this.checkChanges(); this.checkChanges();
} }
@ -217,9 +213,8 @@ class WelcomePageSettings extends React.Component {
}; };
render() { render() {
const { t, isMobileView } = this.props; const { t, isMobileView, isLoadedPage } = this.props;
const { const {
isLoadedData,
greetingTitle, greetingTitle,
isLoadingGreetingSave, isLoadingGreetingSave,
isLoadingGreetingRestore, isLoadingGreetingRestore,
@ -250,9 +245,8 @@ class WelcomePageSettings extends React.Component {
</div> </div>
); );
// return <LoaderCustomization welcomePage={true} />; return !isLoadedPage ? (
return !isLoadedData ? ( <LoaderCustomization welcomePage={true} />
<Loader className="pageLoader" type="rombs" size="40px" />
) : ( ) : (
<StyledSettingsComponent <StyledSettingsComponent
hasScroll={hasScroll} hasScroll={hasScroll}
@ -293,14 +287,21 @@ class WelcomePageSettings extends React.Component {
} }
} }
export default inject(({ auth, setup }) => { export default inject(({ auth, setup, common }) => {
const { greetingSettings, organizationName, theme } = auth.settingsStore; const { greetingSettings, organizationName, theme } = auth.settingsStore;
const { setGreetingTitle, restoreGreetingTitle } = setup; const { setGreetingTitle, restoreGreetingTitle } = setup;
const { isLoaded, setIsLoadedWelcomePageSettings } = common;
return { return {
theme, theme,
greetingSettings, greetingSettings,
organizationName, organizationName,
setGreetingTitle, setGreetingTitle,
restoreGreetingTitle, restoreGreetingTitle,
isLoaded,
setIsLoadedWelcomePageSettings,
}; };
})(withTranslation(["Settings", "Common"])(observer(WelcomePageSettings))); })(
withLoading(
withTranslation(["Settings", "Common"])(observer(WelcomePageSettings))
)
);