Skip to content

Avoid reloading app after login/register + remove calling same api requests multiple times. #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: remove unnecessary requests for home/config/elements
  • Loading branch information
raheeliftikhar5 committed Nov 8, 2023
commit 4971e0935bc9e07d9bc72b6695f5f532243687b5
27 changes: 3 additions & 24 deletions client/packages/lowcoder/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ import { CodeEditorTooltipContainer } from "base/codeEditor/codeEditor";
import { ProductLoading } from "components/ProductLoading";
import { language, trans } from "i18n";
import { loadComps } from "comps";
import { fetchHomeData } from "redux/reduxActions/applicationActions";
import { initApp } from "util/commonUtils";
import ApplicationHome from "./pages/ApplicationV2";
import { favicon } from "@lowcoder-ee/assets/images";
import { hasQueryParam } from "util/urlUtils";
import { isFetchUserFinished } from "redux/selectors/usersSelectors";
import { SystemWarning } from "./components/SystemWarning";
import { getBrandingConfig, getSystemConfigFetching } from "./redux/selectors/configSelectors";
import { getBrandingConfig } from "./redux/selectors/configSelectors";
import { buildMaterialPreviewURL } from "./util/materialUtils";
import GlobalInstances from 'components/GlobalInstances';

Expand All @@ -71,35 +70,22 @@ const Wrapper = (props: { children: React.ReactNode }) => (

type AppIndexProps = {
isFetchUserFinished: boolean;
isFetchHomeFinished: boolean;
// isFetchingConfig: boolean;
currentOrgId?: string;
orgDev: boolean;
defaultHomePage: string | null | undefined;
fetchConfig: (orgId?: string) => void;
getCurrentUser: () => void;
fetchHome: () => void;
favicon: string;
brandName: string;
};

class AppIndex extends React.Component<AppIndexProps, any> {
componentDidMount() {
this.props.getCurrentUser();
const { pathname } = history.location;

this.props.fetchConfig(this.props.currentOrgId);

if (pathname === BASE_URL) {
this.props.fetchHome();
}
}

componentDidUpdate(prevProps: AppIndexProps) {
if (history.location.pathname === BASE_URL) {
this.props.fetchHome();
}
if(prevProps.currentOrgId !== this.props.currentOrgId) {
if(prevProps.currentOrgId !== this.props.currentOrgId && this.props.currentOrgId !== '') {
this.props.fetchConfig(this.props.currentOrgId);
}
}
Expand All @@ -108,11 +94,7 @@ class AppIndex extends React.Component<AppIndexProps, any> {
const isTemplate = hasQueryParam("template");
const pathname = history.location.pathname;
// make sure all users in this app have checked login info
if (
!this.props.isFetchUserFinished ||
// this.props.isFetchingConfig ||
(pathname === BASE_URL && !this.props.isFetchHomeFinished)
) {
if (!this.props.isFetchUserFinished) {
const hideLoadingHeader = isTemplate || isAuthUnRequired(pathname);
return <ProductLoading hideHeader={hideLoadingHeader} />;
}
Expand Down Expand Up @@ -185,11 +167,9 @@ class AppIndex extends React.Component<AppIndexProps, any> {

const mapStateToProps = (state: AppState) => ({
isFetchUserFinished: isFetchUserFinished(state),
// isFetchingConfig: getSystemConfigFetching(state),
orgDev: state.ui.users.user.orgDev,
currentOrgId: state.ui.users.user.currentOrgId,
defaultHomePage: state.ui.application.homeOrg?.commonSettings.defaultHomePage,
isFetchHomeFinished: state.ui.application.loadingStatus.fetchHomeDataFinished,
favicon: getBrandingConfig(state)?.favicon
? buildMaterialPreviewURL(getBrandingConfig(state)?.favicon!)
: favicon,
Expand All @@ -201,7 +181,6 @@ const mapDispatchToProps = (dispatch: any) => ({
dispatch(fetchUserAction());
},
fetchConfig: (orgId?: string) => dispatch(fetchConfigAction(orgId)),
fetchHome: () => dispatch(fetchHomeData({})),
});

const AppIndexWithProps = connect(mapStateToProps, mapDispatchToProps)(AppIndex);
Expand Down
10 changes: 1 addition & 9 deletions client/packages/lowcoder/src/pages/ApplicationV2/HomeView.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
import { HomeLayout } from "./HomeLayout";
import { useEffect } from "react";
import { fetchFolderElements } from "../../redux/reduxActions/folderActions";
import { getUser } from "../../redux/selectors/usersSelectors";
import { folderElementsSelector } from "../../redux/selectors/folderSelector";

export function HomeView() {
const dispatch = useDispatch();

const elements = useSelector(folderElementsSelector)[""];
const user = useSelector(getUser);

useEffect(() => {
dispatch(fetchFolderElements({}));
}, []);

if (!user.currentOrgId) {
return null;
}
Expand Down