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

66 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 {
BubbleStep,
BubbleStepContent,
2022-01-20 16:14:47 +01:00
BubbleStepType,
TextBubbleStep,
} 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 = {
step: Exclude<BubbleStep, TextBubbleStep>
onContentChange: (content: BubbleStepContent) => 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}
w={props.step.type === BubbleStepType.IMAGE ? '500px' : '400px'}
>
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>
)
}
export const MediaBubbleContent = ({ step, onContentChange }: Props) => {
const handleImageUrlChange = (url: string) => onContentChange({ url })
2022-01-20 16:14:47 +01:00
switch (step.type) {
case BubbleStepType.IMAGE: {
return (
2022-01-20 17:45:25 +01:00
<ImageUploadContent
url={step.content?.url}
onSubmit={handleImageUrlChange}
2022-01-20 17:45:25 +01:00
/>
)
}
case BubbleStepType.VIDEO: {
return (
<VideoUploadContent content={step.content} onSubmit={onContentChange} />
2022-01-20 16:14:47 +01:00
)
}
2022-03-23 12:01:35 +01:00
case BubbleStepType.EMBED: {
return (
<EmbedUploadContent content={step.content} onSubmit={onContentChange} />
)
}
2022-01-20 16:14:47 +01:00
}
}