mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
#23 using custom blocks at lab nodes
This commit is contained in:
parent
bee41ebfb3
commit
031de64acc
17 changed files with 330 additions and 43 deletions
|
@ -3,6 +3,7 @@ import { createElement, FC, useCallback, useMemo } from 'react';
|
|||
import { isNil, prop } from 'ramda';
|
||||
import {
|
||||
INodeComponentProps,
|
||||
LAB_PREVIEW_LAYOUT,
|
||||
NODE_COMPONENTS,
|
||||
NODE_HEADS,
|
||||
NODE_INLINES,
|
||||
|
@ -11,11 +12,12 @@ import {
|
|||
// useNodeBlocks returns head, block and inline blocks of node
|
||||
export const useNodeBlocks = (node: INode, isLoading: boolean) => {
|
||||
const createNodeBlock = useCallback(
|
||||
(block?: FC<INodeComponentProps>) =>
|
||||
(block?: FC<INodeComponentProps>, key = 0) =>
|
||||
!isNil(block) &&
|
||||
createElement(block, {
|
||||
node,
|
||||
isLoading,
|
||||
key,
|
||||
}),
|
||||
[node, isLoading]
|
||||
);
|
||||
|
@ -35,5 +37,13 @@ export const useNodeBlocks = (node: INode, isLoading: boolean) => {
|
|||
[node, createNodeBlock]
|
||||
);
|
||||
|
||||
return { head, block, inline };
|
||||
const lab = useMemo(
|
||||
() =>
|
||||
node?.type && prop(node.type, LAB_PREVIEW_LAYOUT)
|
||||
? prop(node.type, LAB_PREVIEW_LAYOUT).map((comp, i) => createNodeBlock(comp, i))
|
||||
: undefined,
|
||||
[node, createNodeBlock]
|
||||
);
|
||||
|
||||
return { head, block, inline, lab };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue