[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.
 
 

16 lines
890 B

import { denormalize } from 'src/utils/normalization'
import { AppState, Post, EntityType, EntityListKey } from 'src/types'
const getPostsFromList = (state: AppState, name: string) => {
const entityList = state.lists[name]
if (!entityList) return []
return denormalize(entityList.entities, EntityType.Post, state.entities) as Post[]
}
export const getTimeline = (state: AppState) => getPostsFromList(state, EntityListKey.Timeline)
export const getUserPosts = (state: AppState, id: string) => getPostsFromList(state, `user:${id}:posts`)
export const getPostParents = (state: AppState, id: string) => getPostsFromList(state, `post:${id}:parents`)
export const getPostChildren = (state: AppState, id: string) => getPostsFromList(state, `post:${id}:children`)
export const getPost = (state: AppState, id: string) => denormalize([id], EntityType.Post, state.entities)[0] as Post