Skip to content

Commit

Permalink
Merge branch 'main' into snyk-fix-c5b757e9f2e5e171d9e5ac77a0bb3478
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms authored Aug 20, 2024
2 parents cd6d42e + 9a888c2 commit f5c5546
Show file tree
Hide file tree
Showing 225 changed files with 2,392 additions and 5,148 deletions.
9 changes: 9 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"culori": "^3.2.0",
"geojson": "^0.5.0",
"jotai": "^2.6.2",
"jotai-effect": "^1.0.0",
"jotai-scope": "^0.5.1",
"jotai-tanstack-query": "^0.8.2",
"lodash": "^4.17.21",
Expand Down
55 changes: 30 additions & 25 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,57 +44,62 @@ enum InitAppState {

const layout: LayoutElement[] = [];

const WORKBENCH = new Workbench();

function App() {
// Workbench must be kept as a state in order to keep it when any framework code is changed in dev mode.
// Otherwise, the workbench will be reset on every code change. This would cause it to loose its state and will
// cause the app to crash.
const [workbench] = React.useState(new Workbench());

const [isMounted, setIsMounted] = React.useState<boolean>(false);
const [initAppState, setInitAppState] = React.useState<InitAppState>(InitAppState.CheckingIfUserIsSignedIn);

const queryClient = useQueryClient();
const { authState } = useAuthProvider();

function initApp() {
if (!WORKBENCH.loadLayoutFromLocalStorage()) {
WORKBENCH.makeLayout(layout);
}

if (WORKBENCH.getLayout().length === 0) {
WORKBENCH.getGuiMessageBroker().setState(GuiState.LeftDrawerContent, LeftDrawerContent.ModulesList);
} else {
WORKBENCH.getGuiMessageBroker().setState(GuiState.LeftDrawerContent, LeftDrawerContent.ModuleSettings);
}
setInitAppState(InitAppState.InitCompleted);
WORKBENCH.getGuiMessageBroker().setState(GuiState.AppInitialized, true);
}

function signIn() {
window.location.href = `/api/login?redirect_url_after_login=${btoa("/")}`;
}

React.useEffect(
function handleMountWhenSignedIn() {
function initApp() {
if (!workbench.loadLayoutFromLocalStorage()) {
workbench.makeLayout(layout);
}

if (workbench.getLayout().length === 0) {
workbench.getGuiMessageBroker().setState(GuiState.LeftDrawerContent, LeftDrawerContent.ModulesList);
} else {
workbench
.getGuiMessageBroker()
.setState(GuiState.LeftDrawerContent, LeftDrawerContent.ModuleSettings);
}
setInitAppState(InitAppState.InitCompleted);
workbench.getGuiMessageBroker().setState(GuiState.AppInitialized, true);
}

if (authState !== AuthState.LoggedIn || isMounted) {
return;
}

setIsMounted(true);

const storedEnsembleIdents = WORKBENCH.maybeLoadEnsembleSettingsFromLocalStorage();
const storedEnsembleIdents = workbench.maybeLoadEnsembleSettingsFromLocalStorage();
if (storedEnsembleIdents) {
setInitAppState(InitAppState.LoadingEnsembles);
WORKBENCH.loadAndSetupEnsembleSetInSession(queryClient, storedEnsembleIdents).finally(() => {
workbench.loadAndSetupEnsembleSetInSession(queryClient, storedEnsembleIdents).finally(() => {
initApp();
});
} else {
initApp();
}

return function handleUnmount() {
WORKBENCH.clearLayout();
WORKBENCH.resetModuleInstanceNumbers();
workbench.clearLayout();
workbench.resetModuleInstanceNumbers();
};
},
[authState, isMounted, queryClient]
[authState, isMounted, queryClient, workbench]
);

function makeStateMessages() {
Expand Down Expand Up @@ -160,12 +165,12 @@ function App() {
})}
>
<>
<LeftNavBar workbench={WORKBENCH} />
<SettingsContentPanels workbench={WORKBENCH} />
<RightNavBar workbench={WORKBENCH} />
<LeftNavBar workbench={workbench} />
<SettingsContentPanels workbench={workbench} />
<RightNavBar workbench={workbench} />
</>
</div>
<ToggleDevToolsButton guiMessageBroker={WORKBENCH.getGuiMessageBroker()} />
<ToggleDevToolsButton guiMessageBroker={workbench.getGuiMessageBroker()} />
</>
);
}
Expand Down
Loading

0 comments on commit f5c5546

Please sign in to comment.