summaryrefslogtreecommitdiff
path: root/src/reducers
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-31 17:59:51 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:50 +0200
commit3f736cd3db63f106eac02f220477b4a0f3b0eceb (patch)
tree80afa73f8c4d281b2fccba8ad2baa7c10f7e7e84 /src/reducers
parentb17f1d8cb4815f57a4b7043cc91b867ec3cbc867 (diff)
Implement room creation
Diffstat (limited to 'src/reducers')
-rw-r--r--src/reducers/index.js3
-rw-r--r--src/reducers/objects.js33
-rw-r--r--src/reducers/topology.js19
3 files changed, 52 insertions, 3 deletions
diff --git a/src/reducers/index.js b/src/reducers/index.js
index 4ddaaec9..d3ace393 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -4,7 +4,7 @@ import {interactionLevel} from "./interaction-level";
import {modals} from "./modals";
import {objects} from "./objects";
import {authorizationsOfCurrentUser, authVisibilityFilter, currentSimulationId} from "./simulations";
-import {currentDatacenterId} from "./topology";
+import {currentDatacenterId, currentRoomInConstruction} from "./topology";
const rootReducer = combineReducers({
auth,
@@ -15,6 +15,7 @@ const rootReducer = combineReducers({
currentSimulationId,
currentDatacenterId,
interactionLevel,
+ currentRoomInConstruction,
});
export default rootReducer;
diff --git a/src/reducers/objects.js b/src/reducers/objects.js
index 4fbffea6..801a5456 100644
--- a/src/reducers/objects.js
+++ b/src/reducers/objects.js
@@ -1,5 +1,10 @@
import {combineReducers} from "redux";
-import {ADD_PROP_TO_STORE_OBJECT, ADD_TO_STORE} from "../actions/objects";
+import {
+ ADD_ID_TO_STORE_OBJECT_LIST_PROP,
+ ADD_PROP_TO_STORE_OBJECT,
+ ADD_TO_STORE,
+ REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP
+} from "../actions/objects";
export const objects = combineReducers({
simulation: object("simulation"),
@@ -33,14 +38,40 @@ function objectWithId(type, getId) {
if (action.type === ADD_TO_STORE) {
return Object.assign(
+ {},
state,
{[getId(action.object)]: action.object}
);
} else if (action.type === ADD_PROP_TO_STORE_OBJECT) {
return Object.assign(
+ {},
state,
{[action.objectId]: Object.assign(state[action.objectId], action.propObject)}
);
+ } else if (action.type === ADD_ID_TO_STORE_OBJECT_LIST_PROP) {
+ return Object.assign(
+ {},
+ state,
+ {
+ [action.objectId]: Object.assign(
+ {},
+ state[action.objectId],
+ {[action.propName]: [...state[action.objectId][action.propName], action.id]}
+ )
+ }
+ );
+ } else if (action.type === REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP) {
+ return Object.assign(
+ {},
+ state,
+ {
+ [action.objectId]: Object.assign(
+ {},
+ state[action.objectId],
+ {[action.propName]: state[action.objectId][action.propName].filter(id => id !== action.id)}
+ )
+ }
+ );
}
return state;
diff --git a/src/reducers/topology.js b/src/reducers/topology.js
index caafb7c1..c8690816 100644
--- a/src/reducers/topology.js
+++ b/src/reducers/topology.js
@@ -1,4 +1,9 @@
-import {FETCH_LATEST_DATACENTER_SUCCEEDED} from "../actions/topology";
+import {
+ CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
+ FETCH_LATEST_DATACENTER_SUCCEEDED,
+ FINISH_NEW_ROOM_CONSTRUCTION,
+ START_NEW_ROOM_CONSTRUCTION_SUCCEEDED
+} from "../actions/topology";
export function currentDatacenterId(state = -1, action) {
switch (action.type) {
@@ -8,3 +13,15 @@ export function currentDatacenterId(state = -1, action) {
return state;
}
}
+
+export function currentRoomInConstruction(state = -1, action) {
+ switch (action.type) {
+ case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED:
+ return action.roomId;
+ case CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED:
+ case FINISH_NEW_ROOM_CONSTRUCTION:
+ return -1;
+ default:
+ return state;
+ }
+}