client/src/selectors/authSelectors.js
changeset 168 ea92f4fe783d
parent 137 279e1dffa213
child 170 7da1d5137b0b
equal deleted inserted replaced
167:1f340f3597a8 168:ea92f4fe783d
     1 // Selectors linked to the authentication status
     1 // Selectors linked to the authentication status
       
     2 import * as R from 'ramda';
     2 
     3 
     3 export const getOnline = state => state.getIn(["status", 'online'])
     4 export const getOnline = R.path(["status", 'online'])
     4 
     5 
     5 export const getToken = state => state.getIn(['authStatus','token'])
     6 export const getToken = R.path(['authStatus','token'])
     6 
     7 
     7 export const isAuthenticated = state => state.getIn(['authStatus', 'isAuthenticated'])
     8 export const isAuthenticated = R.path(['authStatus', 'isAuthenticated'])
     8 
     9 
     9 export const getCurrentUser = state => state.getIn(['authStatus', 'currentUser'])
    10 export const getCurrentUser = R.path(['authStatus', 'currentUser'])
    10 
    11 
    11 export const getClientId = state => state.getIn(['authStatus', 'clientId'])
    12 export const getClientId = R.path(['authStatus', 'clientId'])
    12 
    13 
    13 export const getCurrentGroupName = state => state.getIn(['authStatus', 'currentGroup'])
    14 export const getCurrentGroupName = R.path(['authStatus', 'currentGroup'])
    14 
    15 
    15 export const getGroups = state => state.get('groups')
    16 export const getGroups = R.prop('groups')
    16 
    17 
    17 export const getCurrentGroup = state => {
    18 const findByName = R.compose(R.find, R.propEq('name'));
    18   const groupName = getCurrentGroupName(state);
    19 const findByGroupName = R.compose(findByName, getCurrentGroupName);
    19   const groups = getGroups(state);
       
    20   if(groups) {
       
    21     return groups.find( g => g.get('name') === groupName );
       
    22   } else {
       
    23     return null;
       
    24   }
       
    25 }
       
    26 
    20 
    27 export const getCreateGroup = state => state.get('createGroup')
    21 // export const getCurrentGroup = state => {
       
    22 //   const groupName = getCurrentGroupName(state);
       
    23 //   const groups = getGroups(state);
       
    24 //   if(groups) {
       
    25 //     return groups.find( g => g['name'] === groupName );
       
    26 //   } else {
       
    27 //     return null;
       
    28 //   }
       
    29 // }
       
    30 // https://stackoverflow.com/a/48924396
    28 
    31 
    29 export const getAutoSubmit = state => state.get('autoSubmit')
    32 export const getCurrentGroup = R.unnest(R.converge(R.compose, [findByGroupName, R.always(getGroups)]))
       
    33 
       
    34 export const getCreateGroup = R.prop('createGroup')
       
    35 
       
    36 export const getAutoSubmit = R.prop('autoSubmit')
    30 
    37 
    31 
    38 
    32 
    39