client/src/components/SessionList.js
changeset 137 279e1dffa213
parent 133 6f3078f7fd47
child 143 cfcbf4bc66f1
--- a/client/src/components/SessionList.js	Thu Aug 03 19:12:25 2017 +0200
+++ b/client/src/components/SessionList.js	Thu Aug 03 23:04:33 2017 +0200
@@ -7,7 +7,8 @@
 import Navbar from './Navbar';
 import * as sessionsActions from '../actions/sessionsActions';
 import uuidV1 from 'uuid/v1';
-import { ActionEnum } from '../constants';
+import { getActiveSessions } from '../selectors/coreSelectors';
+import { getCurrentUser, getGroups, getCurrentGroup } from '../selectors/authSelectors';
 
 class SessionList extends Component {
 
@@ -18,14 +19,22 @@
 
   createSession = () => {
     const sessionId = uuidV1();
-    const groupName = (this.props.currentUser)?this.props.currentUser.get('default_group'):null;
+    let groupName = null;
     let protocol = null;
-    if(groupName != null) {
-      const group = this.props.groups.find((g) => g.name === groupName);
-      if(group) {
-        protocol = group.get('protocol');
+    if(this.props.currentGroup) {
+      groupName = this.props.currentGroup.get('name');
+      protocol = this.props.currentGroup.get('protocol');
+    }
+    if(groupName === null) {
+      groupName = (this.props.currentUser)?this.props.currentUser.get('default_group'):null;
+      if(groupName != null) {
+        const group = this.props.groups.find((g) => g.name === groupName);
+        if(group) {
+          protocol = group.get('protocol');
+        }
       }
     }
+
     this.props.sessionsActions.createSession(sessionId, groupName, protocol);
     this.props.history.push('/sessions/' + sessionId);
   }
@@ -94,9 +103,10 @@
 
 function mapStateToProps(state, props) {
   return {
-    sessions: state.get('sessions').filter(session => session.get('action') !== ActionEnum.DELETED),
-    currentUser: state.getIn(['authStatus', 'currentUser']),
-    groups: state.get('groups')
+    sessions: getActiveSessions(state),
+    currentUser: getCurrentUser(state),
+    groups: getGroups(state),
+    currentGroup: getCurrentGroup(state)
   };
 }