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.
18 lines
618 B
18 lines
618 B
import { denormalize } from 'src/utils/normalization'
|
|
import { AppState, Entity, EntityType } from '../types'
|
|
|
|
export const getEntityStore = (state: AppState) => state.entities
|
|
|
|
export const getEntity = <T extends Entity = Entity>(state: AppState, type: EntityType, id?: string) => {
|
|
if (!id) return
|
|
const entities = getEntityStore(state)
|
|
|
|
switch (type) {
|
|
case EntityType.User:
|
|
return denormalize([id], EntityType.User, entities)[0] as T
|
|
case EntityType.Group:
|
|
return denormalize([id], EntityType.Group, entities)[0] as T
|
|
default:
|
|
return
|
|
}
|
|
}
|