⚡ (audio) Add autoplay switch in settings
This commit is contained in:
@ -3,21 +3,25 @@ import { AudioBubbleContent } from '@typebot.io/schemas'
|
|||||||
import { TextInput } from '@/components/inputs'
|
import { TextInput } from '@/components/inputs'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { UploadButton } from '@/components/ImageUploadContent/UploadButton'
|
import { UploadButton } from '@/components/ImageUploadContent/UploadButton'
|
||||||
|
import { SwitchWithLabel } from '@/components/inputs/SwitchWithLabel'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
fileUploadPath: string
|
fileUploadPath: string
|
||||||
content: AudioBubbleContent
|
content: AudioBubbleContent
|
||||||
onSubmit: (content: AudioBubbleContent) => void
|
onContentChange: (content: AudioBubbleContent) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AudioBubbleForm = ({
|
export const AudioBubbleForm = ({
|
||||||
fileUploadPath,
|
fileUploadPath,
|
||||||
content,
|
content,
|
||||||
onSubmit,
|
onContentChange,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [currentTab, setCurrentTab] = useState<'link' | 'upload'>('link')
|
const [currentTab, setCurrentTab] = useState<'link' | 'upload'>('link')
|
||||||
|
|
||||||
const submit = (url: string) => onSubmit({ url })
|
const updateUrl = (url: string) => onContentChange({ ...content, url })
|
||||||
|
|
||||||
|
const updateAutoPlay = (isAutoplayEnabled: boolean) =>
|
||||||
|
onContentChange({ ...content, isAutoplayEnabled })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
@ -37,31 +41,38 @@ export const AudioBubbleForm = ({
|
|||||||
Embed link
|
Embed link
|
||||||
</Button>
|
</Button>
|
||||||
</HStack>
|
</HStack>
|
||||||
<Stack p="2">
|
<Stack p="2" spacing={4}>
|
||||||
{currentTab === 'upload' && (
|
<Stack>
|
||||||
<Flex justify="center" py="2">
|
{currentTab === 'upload' && (
|
||||||
<UploadButton
|
<Flex justify="center" py="2">
|
||||||
fileType="audio"
|
<UploadButton
|
||||||
filePath={fileUploadPath}
|
fileType="audio"
|
||||||
onFileUploaded={submit}
|
filePath={fileUploadPath}
|
||||||
colorScheme="blue"
|
onFileUploaded={updateUrl}
|
||||||
>
|
colorScheme="blue"
|
||||||
Choose a file
|
>
|
||||||
</UploadButton>
|
Choose a file
|
||||||
</Flex>
|
</UploadButton>
|
||||||
)}
|
</Flex>
|
||||||
{currentTab === 'link' && (
|
)}
|
||||||
<>
|
{currentTab === 'link' && (
|
||||||
<TextInput
|
<>
|
||||||
placeholder="Paste the audio file link..."
|
<TextInput
|
||||||
defaultValue={content.url ?? ''}
|
placeholder="Paste the audio file link..."
|
||||||
onChange={submit}
|
defaultValue={content.url ?? ''}
|
||||||
/>
|
onChange={updateUrl}
|
||||||
<Text fontSize="sm" color="gray.400" textAlign="center">
|
/>
|
||||||
Works with .MP3s and .WAVs
|
<Text fontSize="sm" color="gray.400" textAlign="center">
|
||||||
</Text>
|
Works with .MP3s and .WAVs
|
||||||
</>
|
</Text>
|
||||||
)}
|
</>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
<SwitchWithLabel
|
||||||
|
label={'Enable autoplay'}
|
||||||
|
initialValue={content.isAutoplayEnabled ?? true}
|
||||||
|
onCheckChange={updateAutoPlay}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
)
|
||||||
|
@ -77,7 +77,7 @@ export const MediaBubbleContent = ({
|
|||||||
<AudioBubbleForm
|
<AudioBubbleForm
|
||||||
content={block.content}
|
content={block.content}
|
||||||
fileUploadPath={`typebots/${typebotId}/blocks/${block.id}`}
|
fileUploadPath={`typebots/${typebotId}/blocks/${block.id}`}
|
||||||
onSubmit={onContentChange}
|
onContentChange={onContentChange}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.1.14",
|
"version": "0.1.15",
|
||||||
"description": "Javascript library to display typebots on your website",
|
"description": "Javascript library to display typebots on your website",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -74,7 +74,10 @@ export const Bot = (props: BotProps & { class?: string }) => {
|
|||||||
return setError(new Error("The bot you're looking for doesn't exist."))
|
return setError(new Error("The bot you're looking for doesn't exist."))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) return setError(new Error("Error! Couldn't initiate the chat."))
|
if (!data) {
|
||||||
|
if (error) console.error(error)
|
||||||
|
return setError(new Error("Error! Couldn't initiate the chat."))
|
||||||
|
}
|
||||||
|
|
||||||
if (data.resultId && typebotIdFromProps)
|
if (data.resultId && typebotIdFromProps)
|
||||||
setResultInStorage(data.typebot.settings.general.rememberUser?.storage)(
|
setResultInStorage(data.typebot.settings.general.rememberUser?.storage)(
|
||||||
|
@ -55,7 +55,7 @@ export const HostBubble = (props: Props) => {
|
|||||||
</Match>
|
</Match>
|
||||||
<Match when={props.message.type === BubbleBlockType.AUDIO}>
|
<Match when={props.message.type === BubbleBlockType.AUDIO}>
|
||||||
<AudioBubble
|
<AudioBubble
|
||||||
url={(props.message.content as AudioBubbleContent).url}
|
content={props.message.content as AudioBubbleContent}
|
||||||
onTransitionEnd={onTransitionEnd}
|
onTransitionEnd={onTransitionEnd}
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
|
@ -4,7 +4,7 @@ import type { AudioBubbleContent } from '@typebot.io/schemas'
|
|||||||
import { createSignal, onCleanup, onMount } from 'solid-js'
|
import { createSignal, onCleanup, onMount } from 'solid-js'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
url: AudioBubbleContent['url']
|
content: AudioBubbleContent
|
||||||
onTransitionEnd: (offsetTop?: number) => void
|
onTransitionEnd: (offsetTop?: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +50,8 @@ export const AudioBubble = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
<audio
|
<audio
|
||||||
ref={audioElement}
|
ref={audioElement}
|
||||||
src={props.url}
|
src={props.content.url}
|
||||||
autoplay
|
autoplay={props.content.isAutoplayEnabled ?? true}
|
||||||
class={
|
class={
|
||||||
'z-10 text-fade-in ' +
|
'z-10 text-fade-in ' +
|
||||||
(isTyping() ? 'opacity-0' : 'opacity-100 m-2')
|
(isTyping() ? 'opacity-0' : 'opacity-100 m-2')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/nextjs",
|
"name": "@typebot.io/nextjs",
|
||||||
"version": "0.1.14",
|
"version": "0.1.15",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.1.14",
|
"version": "0.1.15",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -4,6 +4,7 @@ import { BubbleBlockType } from './enums'
|
|||||||
|
|
||||||
export const audioBubbleContentSchema = z.object({
|
export const audioBubbleContentSchema = z.object({
|
||||||
url: z.string().optional(),
|
url: z.string().optional(),
|
||||||
|
isAutoplayEnabled: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const audioBubbleBlockSchema = blockBaseSchema.merge(
|
export const audioBubbleBlockSchema = blockBaseSchema.merge(
|
||||||
|
Reference in New Issue
Block a user