You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
import { createSelector } from 'reselect'
|
|
|
|
import { getEntityStore } from './entities'
|
|
import { denormalize } from 'src/utils/normalization'
|
|
import { AppState, Group, User, EntityType, GroupLog, Invitation } from 'src/types'
|
|
|
|
export const getGroupIds = (state: AppState) => state.directory.groups
|
|
|
|
export const getGroups = createSelector(
|
|
[getEntityStore, getGroupIds],
|
|
(entities, groups) => denormalize(groups, EntityType.Group, entities) as Group[]
|
|
)
|
|
|
|
export const getGroupMembers = (state: AppState, group: string) => {
|
|
const users = state.entities[EntityType.User]
|
|
if (!users) return []
|
|
|
|
return denormalize(Object.values(users).filter(user => user.group === group).map(user => user.id), EntityType.User, state.entities) as User[]
|
|
}
|
|
|
|
export const getLogs = (state: AppState) => {
|
|
const logs = state.entities[EntityType.Log]
|
|
if (!logs) return []
|
|
|
|
return denormalize(Object.keys(logs), EntityType.Log, state.entities) as GroupLog[]
|
|
}
|
|
|
|
export const getInvitations = (state: AppState) => {
|
|
const invitations = state.entities[EntityType.Invitation]
|
|
if (!invitations) return []
|
|
|
|
return denormalize(Object.keys(invitations), EntityType.Invitation, state.entities) as Invitation[]
|
|
}
|