summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-16 17:07:58 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-17 17:06:50 +0200
commitd9e65dceb38cdb8dc4e464d388755f9456620566 (patch)
treedbc369de8c4a0effce95ca4a54ff6dbfad2b47f5 /opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
parent1edbae1a0224e30bafb98638f419e1f967a9286f (diff)
ui: Restructure OpenDC frontend
This change updates the structure of the OpenDC frontend in order to improve the maintainability of the frontend.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js b/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
new file mode 100644
index 00000000..9b46aa60
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/reducers/current-ids.js
@@ -0,0 +1,54 @@
+import { OPEN_PORTFOLIO_SUCCEEDED, SET_CURRENT_PORTFOLIO } from '../actions/portfolios'
+import { OPEN_PROJECT_SUCCEEDED } from '../actions/projects'
+import { SET_CURRENT_TOPOLOGY } from '../actions/topology/building'
+import { OPEN_SCENARIO_SUCCEEDED, SET_CURRENT_SCENARIO } from '../actions/scenarios'
+
+export function currentTopologyId(state = '-1', action) {
+ switch (action.type) {
+ case SET_CURRENT_TOPOLOGY:
+ return action.topologyId
+ default:
+ return state
+ }
+}
+
+export function currentProjectId(state = '-1', action) {
+ switch (action.type) {
+ case OPEN_PROJECT_SUCCEEDED:
+ return action.id
+ case OPEN_PORTFOLIO_SUCCEEDED:
+ case OPEN_SCENARIO_SUCCEEDED:
+ return action.projectId
+ default:
+ return state
+ }
+}
+
+export function currentPortfolioId(state = '-1', action) {
+ switch (action.type) {
+ case OPEN_PORTFOLIO_SUCCEEDED:
+ case SET_CURRENT_PORTFOLIO:
+ case SET_CURRENT_SCENARIO:
+ return action.portfolioId
+ case OPEN_SCENARIO_SUCCEEDED:
+ return action.portfolioId
+ case OPEN_PROJECT_SUCCEEDED:
+ case SET_CURRENT_TOPOLOGY:
+ return '-1'
+ default:
+ return state
+ }
+}
+export function currentScenarioId(state = '-1', action) {
+ switch (action.type) {
+ case OPEN_SCENARIO_SUCCEEDED:
+ case SET_CURRENT_SCENARIO:
+ return action.scenarioId
+ case OPEN_PORTFOLIO_SUCCEEDED:
+ case SET_CURRENT_TOPOLOGY:
+ case OPEN_PROJECT_SUCCEEDED:
+ return '-1'
+ default:
+ return state
+ }
+}