[ABANDONED] React/Redux front end for the Flexor social network.
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.
 
 

29 lines
1.1 KiB

import { denormalize } from 'src/utils/normalization'
import { AppState, Group, User, EntityType, GroupLog, Invitation, EntityListKey } from 'src/types'
export const getGroups = (state: AppState) => {
const entityList = state.lists[EntityListKey.Groups]
if (!entityList) return []
return denormalize(entityList.entities, EntityType.Group, state.entities) as Group[]
}
export const getLogs = (state: AppState) => {
const entityList = state.lists[EntityListKey.Logs]
if (!entityList) return []
return denormalize(entityList.entities, EntityType.Log, state.entities) as GroupLog[]
}
export const getInvitations = (state: AppState) => {
const entityList = state.lists[EntityListKey.Invitations]
if (!entityList) return []
return denormalize(entityList.entities, EntityType.Invitation, state.entities) as Invitation[]
}
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[]
}