Commit 48445e60 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Use UIActions for a starting point of event flow

parent 7d01a432
......@@ -9,7 +9,7 @@ import ElementFilter from './ElementFilter';
import SampleDetails from './SampleDetails';
import ShareModal from './managing_actions/ShareModal';
import ElementActions from './actions/ElementActions';
import UIActions from './actions/UIActions';
import Aviator from 'aviator'
Aviator.root = '/';
......@@ -18,7 +18,8 @@ Aviator.setRoutes({
'/': 'root',
target: {
root: function(e) {
ElementActions.unselectCurrentElement();
//UIActions.selectCollection({id: 'all'});
UIActions.deselectAllElements('sample');
let modalDomNode = document.getElementById('modal');
if(modalDomNode) {
......@@ -29,8 +30,7 @@ Aviator.setRoutes({
'/sample': {
target: {
show: function(e) {
let sampleId = e['params']['id'];
ElementActions.fetchSampleById(sampleId)
UIActions.selectElement({type: 'sample', id: e['params']['id']})
}
},
'/:id': 'show'
......
......@@ -76,8 +76,7 @@ export default class CollectionSubtree extends React.Component {
}
handleClick() {
UIActions.deselectAllElements('collection');
UIActions.selectElement({type: 'collection', id: this.state.root.id});
UIActions.selectCollection(this.state.root);
Aviator.navigate('/');
}
......
......@@ -3,10 +3,6 @@ import SamplesFetcher from '../fetchers/SamplesFetcher';
class ElementActions {
unselectCurrentElement() {
this.dispatch();
}
fetchSampleById(id) {
SamplesFetcher.fetchById(id)
.then((result) => {
......
......@@ -2,6 +2,10 @@ import alt from '../alt';
// An element object has a type and an id, e.g., {type: 'sample', id: 1}
class UIActions {
selectCollection(collection) {
this.dispatch(collection)
}
checkAllElements(type) {
this.dispatch(type);
}
......@@ -24,6 +28,7 @@ class UIActions {
}
deselectAllElements(type) {
console.log("deselectAllElements: " + type);
this.dispatch(type);
}
}
......
import alt from '../alt';
import ElementActions from '../actions/ElementActions';
import UIActions from '../actions/UIActions';
import UIStore from './UIStore';
class ElementStore {
constructor() {
......@@ -12,7 +14,7 @@ class ElementStore {
handleFetchSampleById: ElementActions.fetchSampleById,
handleFetchSamplesByCollectionId: ElementActions.fetchSamplesByCollectionId,
handleUpdateSample: ElementActions.updateSample,
handleUnselectCurrentElement: ElementActions.unselectCurrentElement
handleUnselectCurrentElement: UIActions.deselectAllElements
})
}
......@@ -30,6 +32,7 @@ class ElementStore {
}
handleUnselectCurrentElement() {
//this.waitFor(UIStore.dispatchToken);
this.state.currentElement = null;
}
}
......
......@@ -10,10 +10,12 @@ class UIStore {
constructor() {
this.state = {
checkedSampleIds: Immutable.List(),
currentCollectionId: null
currentCollectionId: null,
currentSampleId: null
};
this.bindListeners({
handleSelectCollection: UIActions.selectCollection,
handleCheckAllElements: UIActions.checkAllElements,
handleCheckElement: UIActions.checkElement,
handleUncheckElement: UIActions.uncheckElement,
......@@ -60,21 +62,27 @@ class UIStore {
handleDeselectAllElements(type) {
switch(type) {
case 'collection':
this.state.currentCollectionId = null;
case 'sample':
this.state.currentSampleId = null;
break;
}
}
handleSelectElement(element) {
switch(element.type) {
case 'collection':
this.state.currentCollectionId = element.id;
case 'sample':
this.state.currentSampleId = element.id;
// TODO also for reactions and so on
ElementActions.fetchSamplesByCollectionId(element.id)
ElementActions.fetchSampleById(element.id)
break;
}
}
handleSelectCollection(collection) {
this.state.currentCollectionId = collection.id;
// TODO also for reactions and so on
ElementActions.fetchSamplesByCollectionId(collection.id)
}
}
export default alt.createStore(UIStore, 'UIStore');
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment