diff -r 1f340f3597a8 -r ea92f4fe783d client/src/selectors/authSelectors.js --- a/client/src/selectors/authSelectors.js Tue Oct 09 19:07:47 2018 +0200 +++ b/client/src/selectors/authSelectors.js Mon Oct 08 18:35:47 2018 +0200 @@ -1,32 +1,39 @@ // Selectors linked to the authentication status +import * as R from 'ramda'; -export const getOnline = state => state.getIn(["status", 'online']) +export const getOnline = R.path(["status", 'online']) -export const getToken = state => state.getIn(['authStatus','token']) +export const getToken = R.path(['authStatus','token']) -export const isAuthenticated = state => state.getIn(['authStatus', 'isAuthenticated']) +export const isAuthenticated = R.path(['authStatus', 'isAuthenticated']) -export const getCurrentUser = state => state.getIn(['authStatus', 'currentUser']) +export const getCurrentUser = R.path(['authStatus', 'currentUser']) -export const getClientId = state => state.getIn(['authStatus', 'clientId']) +export const getClientId = R.path(['authStatus', 'clientId']) -export const getCurrentGroupName = state => state.getIn(['authStatus', 'currentGroup']) +export const getCurrentGroupName = R.path(['authStatus', 'currentGroup']) + +export const getGroups = R.prop('groups') -export const getGroups = state => state.get('groups') +const findByName = R.compose(R.find, R.propEq('name')); +const findByGroupName = R.compose(findByName, getCurrentGroupName); -export const getCurrentGroup = state => { - const groupName = getCurrentGroupName(state); - const groups = getGroups(state); - if(groups) { - return groups.find( g => g.get('name') === groupName ); - } else { - return null; - } -} +// export const getCurrentGroup = state => { +// const groupName = getCurrentGroupName(state); +// const groups = getGroups(state); +// if(groups) { +// return groups.find( g => g['name'] === groupName ); +// } else { +// return null; +// } +// } +// https://stackoverflow.com/a/48924396 -export const getCreateGroup = state => state.get('createGroup') +export const getCurrentGroup = R.unnest(R.converge(R.compose, [findByGroupName, R.always(getGroups)])) -export const getAutoSubmit = state => state.get('autoSubmit') +export const getCreateGroup = R.prop('createGroup') + +export const getAutoSubmit = R.prop('autoSubmit')