/** * External dependencies */ import { values } from 'lodash'; import { EMPTY_ARRAY } from '@nelio-content/constants'; import { createIndexedSelector } from '@nelio-content/utils'; import type { BoardPostSummary, Maybe, PostId, PostStatusSlug, } from '@nelio-content/types'; /** * Internal dependencies */ import type { State } from '../config'; export function getPostsInStatus( state: State, status: PostStatusSlug ): ReadonlyArray< BoardPostSummary > { return state.board.statuses[ status ] ?? EMPTY_ARRAY; } export const getBoardPostSummary = createIndexedSelector( ( state: State, id: PostId ): Maybe< BoardPostSummary > => { return values( state.board.statuses ) .flatMap( ( p ) => p ) .find( ( p ) => p.id === id ); }, ( state: State, id: PostId ) => ( { key: id, dependants: [ state.board.statuses ], } ) );