2
0
Files
bot/apps/builder/components/shared/Graph/Nodes/BlockNode/MediaBubblePopoverContent/MediaBubblePopoverContent.tsx

72 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-01-20 16:14:47 +01:00
import {
Portal,
PopoverContent,
PopoverArrow,
PopoverBody,
} from '@chakra-ui/react'
2022-01-20 17:45:25 +01:00
import { ImageUploadContent } from 'components/shared/ImageUploadContent'
2022-01-20 16:14:47 +01:00
import {
2022-06-11 07:27:38 +02:00
BubbleBlock,
BubbleBlockContent,
BubbleBlockType,
TextBubbleBlock,
2022-01-20 16:14:47 +01:00
} from 'models'
import { useRef } from 'react'
2022-03-23 12:01:35 +01:00
import { EmbedUploadContent } from './EmbedUploadContent'
2022-01-20 17:45:25 +01:00
import { VideoUploadContent } from './VideoUploadContent'
2022-01-20 16:14:47 +01:00
type Props = {
2022-06-11 07:27:38 +02:00
block: Exclude<BubbleBlock, TextBubbleBlock>
onContentChange: (content: BubbleBlockContent) => void
2022-01-20 16:14:47 +01:00
}
export const MediaBubblePopoverContent = (props: Props) => {
2022-01-20 16:14:47 +01:00
const ref = useRef<HTMLDivElement | null>(null)
const handleMouseDown = (e: React.MouseEvent) => e.stopPropagation()
return (
<Portal>
2022-03-23 12:01:35 +01:00
<PopoverContent
onMouseDown={handleMouseDown}
2022-06-11 07:27:38 +02:00
w={props.block.type === BubbleBlockType.IMAGE ? '500px' : '400px'}
2022-03-23 12:01:35 +01:00
>
2022-01-20 16:14:47 +01:00
<PopoverArrow />
<PopoverBody ref={ref} shadow="lg">
<MediaBubbleContent {...props} />
2022-01-20 16:14:47 +01:00
</PopoverBody>
</PopoverContent>
</Portal>
)
}
2022-06-11 07:27:38 +02:00
export const MediaBubbleContent = ({ block, onContentChange }: Props) => {
const handleImageUrlChange = (url: string) => onContentChange({ url })
2022-01-20 16:14:47 +01:00
2022-06-11 07:27:38 +02:00
switch (block.type) {
case BubbleBlockType.IMAGE: {
2022-01-20 16:14:47 +01:00
return (
2022-01-20 17:45:25 +01:00
<ImageUploadContent
2022-06-11 07:27:38 +02:00
url={block.content?.url}
onSubmit={handleImageUrlChange}
2022-01-20 17:45:25 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case BubbleBlockType.VIDEO: {
2022-01-20 17:45:25 +01:00
return (
2022-06-11 07:27:38 +02:00
<VideoUploadContent
content={block.content}
onSubmit={onContentChange}
/>
2022-01-20 16:14:47 +01:00
)
}
2022-06-11 07:27:38 +02:00
case BubbleBlockType.EMBED: {
2022-03-23 12:01:35 +01:00
return (
2022-06-11 07:27:38 +02:00
<EmbedUploadContent
content={block.content}
onSubmit={onContentChange}
/>
2022-03-23 12:01:35 +01:00
)
}
2022-01-20 16:14:47 +01:00
}
}