2022-11-24 11:37:08 +00:00
|
|
|
import React, { useRef } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2020-02-11 14:01:35 +00:00
|
|
|
import { messageBlockWithContext } from '../UIKit/MessageBlock';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { IMessageBlocks } from './interfaces';
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Blocks = React.memo(({ blocks, id: mid, rid, blockAction }: IMessageBlocks) => {
|
2020-02-11 14:01:35 +00:00
|
|
|
if (blocks && blocks.length > 0) {
|
2020-04-13 13:56:57 +00:00
|
|
|
const appId = blocks[0]?.appId || '';
|
2022-11-24 11:37:08 +00:00
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
const comp = useRef(
|
|
|
|
React.createElement(
|
|
|
|
messageBlockWithContext({
|
|
|
|
action: async ({ actionId, value, blockId }: { actionId: string; value: string; blockId: string }) => {
|
|
|
|
if (blockAction) {
|
|
|
|
await blockAction({
|
|
|
|
actionId,
|
|
|
|
appId,
|
|
|
|
value,
|
|
|
|
blockId,
|
|
|
|
rid,
|
|
|
|
mid
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
appId,
|
|
|
|
rid
|
|
|
|
}),
|
|
|
|
{ blocks }
|
|
|
|
)
|
2020-02-11 14:01:35 +00:00
|
|
|
);
|
2022-11-24 11:37:08 +00:00
|
|
|
return comp.current;
|
2020-02-11 14:01:35 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Blocks.displayName = 'MessageBlocks';
|
|
|
|
|
|
|
|
export default Blocks;
|