Skip to content

Commit

Permalink
⚡ (video) Allow changing video height when resolved to an iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno authored and jmgoncalves97 committed Jan 17, 2025
1 parent be70401 commit 01b913c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Stack, Text } from '@chakra-ui/react'
import { VideoBubbleContent } from '@typebot.io/schemas'
import { TextInput } from '@/components/inputs'
import {
VariableString,
VideoBubbleContent,
VideoBubbleContentType,
} from '@typebot.io/schemas'
import { NumberInput, TextInput } from '@/components/inputs'
import { useScopedI18n } from '@/locales'
import { parseVideoUrl } from '@typebot.io/lib/parseVideoUrl'

Expand All @@ -11,24 +15,42 @@ type Props = {

export const VideoUploadContent = ({ content, onSubmit }: Props) => {
const scopedT = useScopedI18n('editor.blocks.bubbles.video.settings')
const handleUrlChange = (url: string) => {
const updateUrl = (url: string) => {
const info = parseVideoUrl(url)
return onSubmit({
type: info.type,
url,
id: info.id,
})
}
const updateHeight = (height?: number | VariableString) => {
return onSubmit({
...content,
height,
})
}
return (
<Stack p="2">
<TextInput
placeholder={scopedT('worksWith.placeholder')}
defaultValue={content?.url ?? ''}
onChange={handleUrlChange}
/>
<Text fontSize="sm" color="gray.400" textAlign="center">
{scopedT('worksWith.text')}
</Text>
<Stack p="2" spacing={4}>
<Stack>
<TextInput
placeholder={scopedT('worksWith.placeholder')}
defaultValue={content?.url ?? ''}
onChange={updateUrl}
/>
<Text fontSize="sm" color="gray.400" textAlign="center">
{scopedT('worksWith.text')}
</Text>
</Stack>

{content?.type !== VideoBubbleContentType.URL && (
<NumberInput
label="Height:"
defaultValue={content?.height ?? 400}
onValueChange={updateHeight}
suffix={scopedT('numberInput.unit')}
width="150px"
/>
)}
</Stack>
)
}
1 change: 1 addition & 0 deletions apps/builder/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export default {
'Funktioniert mit YouTube, Vimeo und anderen',
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
'Füge den Videolink ein...',
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
'editor.blocks.bubbles.textEditor.plate.label': 'Texteditor',
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
'Nach einer Variable suchen',
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export default {
'Works with Youtube, Vimeo and others',
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
'Paste the video link...',
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
'editor.blocks.bubbles.textEditor.plate.label': 'Text editor',
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
'Search for a variable',
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export default {
'Fonctionne avec Youtube, Vimeo et autres',
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
'Collez le lien de la vidéo...',
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
'editor.blocks.bubbles.textEditor.plate.label': 'Éditeur de texte',
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
'Rechercher une variable',
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export default {
'Compatível com Youtube, Vimeo e outros',
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
'Colar o link do vídeo...',
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
'editor.blocks.bubbles.textEditor.plate.label': 'Editor de texto',
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
'Pesquisar uma variável',
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export default {
'Compatível com Youtube, Vimeo e outros',
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
'Colar o link do vídeo...',
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
'editor.blocks.bubbles.textEditor.plate.label': 'Editor de texto',
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
'Pesquisar uma variável',
Expand Down
8 changes: 7 additions & 1 deletion packages/bot-engine/parseBubbleBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ export const parseBubbleBlock = (
const parsedContent = deepParseVariables(variables)(block.content)
return {
...block,
content: parsedContent.url ? parseVideoUrl(parsedContent.url) : {},
content: {
...(parsedContent.url ? parseVideoUrl(parsedContent.url) : {}),
height:
typeof parsedContent.height === 'string'
? parseFloat(parsedContent.height)
: parsedContent.height,
},
}
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const VideoBubble = (props: Props) => {
})

return (
<div class="flex flex-col animate-fade-in" ref={ref}>
<div class="flex flex-col w-full animate-fade-in" ref={ref}>
<div class="flex w-full items-center">
<div class="flex relative z-10 items-start typebot-host-bubble overflow-hidden">
<div class="flex relative z-10 items-start typebot-host-bubble overflow-hidden w-full">
<div
class="flex items-center absolute px-4 py-2 bubble-typing z-10 "
style={{
Expand Down Expand Up @@ -86,7 +86,11 @@ export const VideoBubble = (props: Props) => {
isTyping() ? 'opacity-0' : 'opacity-100 p-4'
)}
style={{
height: isTyping() ? (isMobile() ? '32px' : '36px') : '200px',
height: isTyping()
? isMobile()
? '32px'
: '36px'
: `${props.content.height ?? '400'}px`,
}}
>
<iframe
Expand Down
2 changes: 2 additions & 0 deletions packages/schemas/features/blocks/bubbles/video/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { z } from 'zod'
import { blockBaseSchema } from '../../baseSchemas'
import { BubbleBlockType } from '../enums'
import { VideoBubbleContentType } from './enums'
import { variableStringSchema } from '../../../utils'

export const videoBubbleContentSchema = z.object({
url: z.string().optional(),
id: z.string().optional(),
type: z.nativeEnum(VideoBubbleContentType).optional(),
height: z.number().or(variableStringSchema).optional(),
})

export const videoBubbleBlockSchema = blockBaseSchema.merge(
Expand Down

0 comments on commit 01b913c

Please sign in to comment.