import { ParsedBlock } from '../types/Block' ; import { UNSUPPORTED_TYPE } from '../types/BlockTypes' ; import { NotionBlock } from '../types/NotionBlock' ; function areRelated ( previous , current ) { return previous . isList ( ) && previous . equalsType ( current . notionType ) ; } param blocks returns export default function getBlocksToRender ( blocks ) { const cleanBlocks = blocks . filter ( ( { type } ) => type !== UNSUPPORTED_TYPE ) ; if ( ! cleanBlocks . length ) return [ ] ; const returnBlocks = [ ] ; for ( let i = 0 ; i < cleanBlocks . length ; i ++ ) { const previousBlock = returnBlocks [ returnBlocks . length - 1 ] ; const block = new ParsedBlock ( cleanBlocks [ i ] ) ; if ( previousBlock && areRelated ( previousBlock , block ) ) { previousBlock . addItem ( cleanBlocks [ i ] ) ; } else { returnBlocks . push ( block ) ; } } return returnBlocks ; }