Skip to content
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

webui: Don't use inline functional component for router's Switch to avoid unnecessary re-renders. #336

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion components/webui/client/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#react-target {
#root {
display: flex;
height: 100%;
}
2 changes: 1 addition & 1 deletion components/webui/client/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
</head>

<body>
<div id="react-target"></div>
<div id="root"></div>
</body>
6 changes: 2 additions & 4 deletions components/webui/client/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import {App} from "/imports/ui/App.jsx";
Meteor.startup(() => {
const routes = (
<Router history={createBrowserHistory()}>
<Switch>
<App/>
</Switch>
<App/>
</Router>
);

render(routes, document.getElementById("react-target"));
render(routes, document.getElementById("root"));
});
84 changes: 0 additions & 84 deletions components/webui/imports/api/user/client/methods.js

This file was deleted.

23 changes: 0 additions & 23 deletions components/webui/imports/api/user/server/methods.js

This file was deleted.

57 changes: 14 additions & 43 deletions components/webui/imports/ui/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from "react";
import {faFileUpload, faSearch} from "@fortawesome/free-solid-svg-icons";
import {Redirect, Route, Switch} from "react-router";

import {login} from "../api/user/client/methods";
import {LOCAL_STORAGE_KEYS} from "./constants";

import IngestView from "./IngestView/IngestView.jsx";
Expand All @@ -29,16 +28,10 @@ const ROUTES = [
];

const App = () => {
const [loggedIn, setLoggedIn] = React.useState(false);
const [isSidebarCollapsed, setSidebarStateCollapsed] = React.useState(
"true" === localStorage.getItem(LOCAL_STORAGE_KEYS.IS_SIDEBAR_COLLAPSED),
);

React.useEffect(async () => {
const result = await login();
setLoggedIn(result);
}, []);

React.useEffect(() => {
localStorage.setItem(LOCAL_STORAGE_KEYS.IS_SIDEBAR_COLLAPSED,
isSidebarCollapsed.toString());
Expand All @@ -48,48 +41,26 @@ const App = () => {
setSidebarStateCollapsed(!isSidebarCollapsed);
};

const Spinner = () => <div className="h-100">
<div className="d-flex justify-content-center align-items-center h-100">
<div className="spinner-grow"
style={{
width: "3rem",
height: "3rem",
}} role="status">
<span className="visually-hidden">Loading...</span>
</div>
</div>
</div>;

const Routes = () => <Switch>
<Route exact path="/">
<Redirect to="/ingest"/>
</Route>
<Route exact path={"/ingest"}>
<IngestView/>
</Route>
<Route exact path={"/search"}>
<SearchView/>
</Route>
</Switch>;

return (<div style={{
display: "flex",
height: "100%",
}}>
return (<>
<Sidebar
isSidebarCollapsed={isSidebarCollapsed}
routes={ROUTES}
onSidebarToggle={handleSidebarToggle}
/>
<div style={{
flexGrow: 1,
minWidth: 0,
}}>
<div style={{height: "100%"}}>
{!loggedIn ? <Spinner/> : <Routes/>}
</div>
<div id={"page-container"}>
<Switch>
<Route exact path="/">
<Redirect to="/ingest"/>
</Route>
<Route exact path={"/ingest"}>
<IngestView/>
</Route>
<Route exact path={"/search"}>
<SearchView/>
</Route>
</Switch>
</div>
</div>);
</>);
};

export {App};
4 changes: 4 additions & 0 deletions components/webui/imports/ui/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ body {
height: 100%;
}

#page-container {
flex-grow: 1;
}

@import "IngestView/IngestView.scss";
@import "SearchView/SearchView.scss";
@import "Sidebar/Sidebar.scss";
1 change: 0 additions & 1 deletion components/webui/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "/imports/api/ingestion/server/publications";
import "/imports/api/search/server/collections";
import "/imports/api/search/server/methods";
import "/imports/api/search/server/publications";
import "/imports/api/user/server/methods";
import {deinitDbManagers, initDbManagers} from "../imports/utils/DbManager";


Expand Down
Loading