summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/routes
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-25 21:53:42 +0200
committerGitHub <noreply@github.com>2021-04-25 21:53:42 +0200
commit128f76f7fd7c8abb41a3bbbd9f1980cbc20ae7a5 (patch)
treeadd513890005233a7784466797bfe6f5052e9eeb /opendc-web/opendc-web-ui/src/routes
parent128a1db017545597a5c035b7960eb3fd36b5f987 (diff)
parent57b54b59ed74ec37338ae26b3864d051255aba49 (diff)
build: Flatten project structure
This change updates the project structure to become flattened. Previously, the simulator, frontend and API each lived into their own directory. With this change, all modules of the project live in the top-level directory of the repository.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/routes')
-rw-r--r--opendc-web/opendc-web-ui/src/routes/index.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-ui/src/routes/index.js b/opendc-web/opendc-web-ui/src/routes/index.js
new file mode 100644
index 00000000..4291a046
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/routes/index.js
@@ -0,0 +1,40 @@
+import React from 'react'
+import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'
+import { userIsLoggedIn } from '../auth/index'
+import App from '../pages/App'
+import Home from '../pages/Home'
+import NotFound from '../pages/NotFound'
+import Profile from '../pages/Profile'
+import Projects from '../pages/Projects'
+
+const ProtectedComponent = (component) => () => (userIsLoggedIn() ? component : <Redirect to="/" />)
+const AppComponent = ({ match }) =>
+ userIsLoggedIn() ? (
+ <App
+ projectId={match.params.projectId}
+ portfolioId={match.params.portfolioId}
+ scenarioId={match.params.scenarioId}
+ />
+ ) : (
+ <Redirect to="/" />
+ )
+
+const Routes = () => (
+ <BrowserRouter>
+ <Switch>
+ <Route exact path="/" component={Home} />
+ <Route exact path="/projects" render={ProtectedComponent(<Projects />)} />
+ <Route exact path="/projects/:projectId" component={AppComponent} />
+ <Route exact path="/projects/:projectId/portfolios/:portfolioId" component={AppComponent} />
+ <Route
+ exact
+ path="/projects/:projectId/portfolios/:portfolioId/scenarios/:scenarioId"
+ component={AppComponent}
+ />
+ <Route exact path="/profile" render={ProtectedComponent(<Profile />)} />
+ <Route path="/*" component={NotFound} />
+ </Switch>
+ </BrowserRouter>
+)
+
+export default Routes