summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-16 23:10:32 +0300
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:43 +0200
commit9bfd652ff2c0bb5c0fa1fbce49e948bd4effa7b8 (patch)
tree3a19dd6bd49d3022a37e84bda1ad50cd8e2fbc97
parent07195f3762b6a8a7dfb44c2231db58c5be13c43f (diff)
Connect simulation remove to API
-rw-r--r--src/actions/simulations.js8
-rw-r--r--src/api/sagas/index.js5
-rw-r--r--src/api/sagas/simulations.js13
-rw-r--r--src/components/modals/TextInputModal.js3
-rw-r--r--src/reducers/simulations.js6
5 files changed, 26 insertions, 9 deletions
diff --git a/src/actions/simulations.js b/src/actions/simulations.js
index 314a2492..ddfacaf0 100644
--- a/src/actions/simulations.js
+++ b/src/actions/simulations.js
@@ -4,6 +4,7 @@ export const CLOSE_NEW_SIMULATION_MODAL = "CLOSE_SIMULATION_POPUP";
export const ADD_SIMULATION = "ADD_SIMULATION";
export const ADD_SIMULATION_SUCCEEDED = "ADD_SIMULATION_SUCCEEDED";
export const DELETE_SIMULATION = "DELETE_SIMULATION";
+export const DELETE_SIMULATION_SUCCEEDED = "DELETE_SIMULATION_SUCCEEDED";
export const OPEN_SIMULATION = "OPEN_SIMULATION";
export function setAuthVisibilityFilter(filter) {
@@ -50,6 +51,13 @@ export function deleteSimulation(id) {
};
}
+export function deleteSimulationSucceeded(id) {
+ return {
+ type: DELETE_SIMULATION_SUCCEEDED,
+ id
+ };
+}
+
export function openSimulation(id) {
return {
type: OPEN_SIMULATION,
diff --git a/src/api/sagas/index.js b/src/api/sagas/index.js
index f315f377..426b344a 100644
--- a/src/api/sagas/index.js
+++ b/src/api/sagas/index.js
@@ -1,12 +1,13 @@
import {takeEvery} from "redux-saga/effects";
import {LOG_IN} from "../../actions/auth";
-import {ADD_SIMULATION} from "../../actions/simulations";
+import {ADD_SIMULATION, DELETE_SIMULATION} from "../../actions/simulations";
import {FETCH_AUTHORIZATIONS_OF_CURRENT_USER} from "../../actions/users";
-import {onSimulationAdd} from "./simulations";
+import {onSimulationAdd, onSimulationDelete} from "./simulations";
import {onFetchAuthorizationsOfCurrentUser, onFetchLoggedInUser} from "./users";
export default function* rootSaga() {
yield takeEvery(LOG_IN, onFetchLoggedInUser);
yield takeEvery(FETCH_AUTHORIZATIONS_OF_CURRENT_USER, onFetchAuthorizationsOfCurrentUser);
yield takeEvery(ADD_SIMULATION, onSimulationAdd);
+ yield takeEvery(DELETE_SIMULATION, onSimulationDelete);
}
diff --git a/src/api/sagas/simulations.js b/src/api/sagas/simulations.js
index b824d8d5..9c3bd24c 100644
--- a/src/api/sagas/simulations.js
+++ b/src/api/sagas/simulations.js
@@ -1,7 +1,7 @@
import {call, put} from "redux-saga/effects";
import {addToAuthorizationStore, addToSimulationStore} from "../../actions/objects";
-import {addSimulationSucceeded} from "../../actions/simulations";
-import {addSimulation} from "../routes/simulations";
+import {addSimulationSucceeded, deleteSimulationSucceeded} from "../../actions/simulations";
+import {addSimulation, deleteSimulation} from "../routes/simulations";
export function* onSimulationAdd(action) {
try {
@@ -19,3 +19,12 @@ export function* onSimulationAdd(action) {
console.log(error);
}
}
+
+export function* onSimulationDelete(action) {
+ try {
+ yield call(deleteSimulation, action.id);
+ yield put(deleteSimulationSucceeded(action.id));
+ } catch (error) {
+ console.log(error);
+ }
+}
diff --git a/src/components/modals/TextInputModal.js b/src/components/modals/TextInputModal.js
index 90a5db12..97986fe2 100644
--- a/src/components/modals/TextInputModal.js
+++ b/src/components/modals/TextInputModal.js
@@ -33,8 +33,7 @@ class TextInputModal extends React.Component {
}}>
<div className="form-group">
<label className="form-control-label">{this.props.label}:</label>
- <input type="text" className="form-control" ref="textInput" value={this.props.initialValue}
- autoFocus/>
+ <input type="text" className="form-control" ref="textInput" value={this.props.initialValue}/>
</div>
</form>
</Modal>
diff --git a/src/reducers/simulations.js b/src/reducers/simulations.js
index 5a34ee7f..9d830877 100644
--- a/src/reducers/simulations.js
+++ b/src/reducers/simulations.js
@@ -1,7 +1,7 @@
import {
ADD_SIMULATION_SUCCEEDED,
CLOSE_NEW_SIMULATION_MODAL,
- DELETE_SIMULATION,
+ DELETE_SIMULATION_SUCCEEDED,
OPEN_NEW_SIMULATION_MODAL,
SET_AUTH_VISIBILITY_FILTER
} from "../actions/simulations";
@@ -16,8 +16,8 @@ export function authorizationsOfCurrentUser(state = [], action) {
...state,
action.authorization
];
- case DELETE_SIMULATION:
- return [];
+ case DELETE_SIMULATION_SUCCEEDED:
+ return state.filter(authorization => authorization[1] !== action.id);
default:
return state;
}