--- a/client/src/components/Session.js Thu Aug 03 19:12:25 2017 +0200
+++ b/client/src/components/Session.js Thu Aug 03 23:04:33 2017 +0200
@@ -11,7 +11,8 @@
import * as sessionsActions from '../actions/sessionsActions';
import * as notesActions from '../actions/notesActions';
import * as userActions from '../actions/userActions';
-import { ActionEnum } from '../constants';
+import { getSession, getSessionNotes } from '../selectors/coreSelectors';
+import { getAutoSubmit } from '../selectors/authSelectors';
class Session extends Component {
render() {
@@ -56,18 +57,12 @@
const sessionId = props.match.params.id;
- const sessions = state.get('sessions');
- const notes = state.get('notes');
- const autoSubmit = state.get('autoSubmit');
-
- const currentSession = sessions.find(session => session._id === sessionId);
- const currentNotes = notes.filter(note => {
- return (note.get('session') === sessionId && note.get('action') !== ActionEnum.DELETED);
- }).sortBy( n => n.get('startedAt') );
+ const autoSubmit = getAutoSubmit(state);
+ const currentSession = getSession(sessionId, state);
+ const currentNotes = getSessionNotes(sessionId, state);
return {
currentSession,
- sessions,
notes: currentNotes,
autoSubmit
};
--- 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)
};
}
--- a/client/src/sagas/networkSaga.js Thu Aug 03 19:12:25 2017 +0200
+++ b/client/src/sagas/networkSaga.js Thu Aug 03 23:04:33 2017 +0200
@@ -46,12 +46,13 @@
} catch (error) {
yield put(setOnlineStatus(false));
//TODO: This is ugly...
- if ((error.non_field_errors &&
- error.non_field_errors &&
- error.non_field_errors.length &&
- error.non_field_errors.length > 0 &&
- ( error.non_field_errors[0] === 'Signature has expired.' ||
- error.non_field_errors[0] === 'Refresh has expired.' )) ||
+ const data = error.data;
+ if ((data.non_field_errors &&
+ data.non_field_errors &&
+ data.non_field_errors.length &&
+ data.non_field_errors.length > 0 &&
+ ( data.non_field_errors[0] === 'Signature has expired.' ||
+ data.non_field_errors[0] === 'Refresh has expired.' )) ||
(error.detail && (
error.detail === 'Signature has expired.' ||
error.detail=== 'Refresh has expired.'
--- a/client/src/selectors/authSelectors.js Thu Aug 03 19:12:25 2017 +0200
+++ b/client/src/selectors/authSelectors.js Thu Aug 03 23:04:33 2017 +0200
@@ -26,5 +26,7 @@
export const getCreateGroup = state => state.get('createGroup')
+export const getAutoSubmit = state => state.get('autoSubmit')
+
--- a/client/src/selectors/coreSelectors.js Thu Aug 03 19:12:25 2017 +0200
+++ b/client/src/selectors/coreSelectors.js Thu Aug 03 23:04:33 2017 +0200
@@ -43,3 +43,21 @@
export const getCreatedNotes = getNoteMapSelector(ActionEnum.CREATED);
export const getDeletedNotes = getNoteMapSelector(ActionEnum.DELETED);
+
+export const getActiveSessions = state => state.get('sessions').filter(session => session.get('action') !== ActionEnum.DELETED)
+
+export const getSessions = state => state.get('sessions')
+export const getNotes = state => state.get('notes')
+
+export const getSession = (sessionId, state) => {
+ const sessions = getSessions(state);
+ return sessions.find(session => session._id === sessionId)
+}
+
+export const getSessionNotes = (sessionId, state) => {
+ const notes = getNotes(state);
+ return notes.filter(note => {
+ return (note.get('session') === sessionId && note.get('action') !== ActionEnum.DELETED);
+ }).sortBy( n => n.get('startedAt') );
+}
+