summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/store/hooks/project.js
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-13 17:42:53 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-17 17:06:50 +0200
commit1edbae1a0224e30bafb98638f419e1f967a9286f (patch)
tree2047c5a684379dfd395891e9447199f6001cef9b /opendc-web/opendc-web-ui/src/store/hooks/project.js
parent1891a6f3963d3ddeae0ea093f9a7e3608a97b4d7 (diff)
ui: Move modal state outside of Redux
This change updates the frontend so that the modal state is not stored inside Redux but instead is stored using the useState hook. This simplifies the design of the modal components.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/store/hooks/project.js')
-rw-r--r--opendc-web/opendc-web-ui/src/store/hooks/project.js48
1 files changed, 47 insertions, 1 deletions
diff --git a/opendc-web/opendc-web-ui/src/store/hooks/project.js b/opendc-web/opendc-web-ui/src/store/hooks/project.js
index 0f2f1b66..0db49fdd 100644
--- a/opendc-web/opendc-web-ui/src/store/hooks/project.js
+++ b/opendc-web/opendc-web-ui/src/store/hooks/project.js
@@ -25,8 +25,54 @@ import { useSelector } from 'react-redux'
/**
* Return the current active project.
*/
-export function useProject() {
+export function useActiveProject() {
return useSelector((state) =>
state.currentProjectId !== '-1' ? state.objects.project[state.currentProjectId] : undefined
)
}
+
+/**
+ * Return the active portfolio.
+ */
+export function useActivePortfolio() {
+ return useSelector((state) => state.objects.portfolio[state.currentPortfolioId])
+}
+
+/**
+ * Return the active scenario.
+ */
+export function useActiveScenario() {
+ return useSelector((state) => state.objects.scenario[state.currentScenarioId])
+}
+
+/**
+ * Return the portfolios for the specified project id.
+ */
+export function usePortfolios(projectId) {
+ return useSelector((state) => {
+ let portfolios = state.objects.project[projectId]
+ ? state.objects.project[projectId].portfolioIds.map((t) => state.objects.portfolio[t])
+ : []
+ if (portfolios.filter((t) => !t).length > 0) {
+ portfolios = []
+ }
+
+ return portfolios
+ })
+}
+
+/**
+ * Return the scenarios for the specified portfolio id.
+ */
+export function useScenarios(portfolioId) {
+ return useSelector((state) => {
+ let scenarios = state.objects.portfolio[portfolioId]
+ ? state.objects.portfolio[portfolioId].scenarioIds.map((t) => state.objects.scenario[t])
+ : []
+ if (scenarios.filter((t) => !t).length > 0) {
+ scenarios = []
+ }
+
+ return scenarios
+ })
+}