Skip to content

Commit

Permalink
feat(editor): ⚡️ Image picker and dynamic preview
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 12, 2022
1 parent 6af47f0 commit a89f4ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { Box, Text, Image } from '@chakra-ui/react'
import { ImageBubbleStep } from 'models'

export const ImageBubbleContent = ({ step }: { step: ImageBubbleStep }) =>
!step.content?.url ? (
export const ImageBubbleContent = ({ step }: { step: ImageBubbleStep }) => {
const containsVariables =
step.content?.url?.includes('{{') && step.content.url.includes('}}')
return !step.content?.url ? (
<Text color={'gray.500'}>Click to edit...</Text>
) : (
<Box w="full">
<Image
src={step.content?.url}
alt="Step image"
src={
containsVariables ? '/images/dynamic-image.png' : step.content?.url
}
alt="Block image"
rounded="md"
objectFit="cover"
/>
</Box>
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useEffect, useState } from 'react'
import { ChangeEvent, useState } from 'react'
import {
Button,
Flex,
Expand All @@ -13,10 +13,9 @@ import { SearchContextManager } from '@giphy/react-components'
import { UploadButton } from '../buttons/UploadButton'
import { GiphySearch } from './GiphySearch'
import { useTypebot } from 'contexts/TypebotContext'
import { useDebounce } from 'use-debounce'
import { Input } from '../Textbox'
import { BaseEmoji, emojiIndex } from 'emoji-mart'
import { emojis } from './emojis'
import { Input } from '../Textbox/Input'

type Props = {
url?: string
Expand Down Expand Up @@ -123,26 +122,15 @@ const UploadFileContent = ({ onNewUrl }: ContentProps) => {
)
}

const EmbedLinkContent = ({ initialUrl, onNewUrl }: ContentProps) => {
const [imageUrl, setImageUrl] = useState(initialUrl ?? '')
const [debouncedImageUrl] = useDebounce(imageUrl, 100)

useEffect(() => {
if (initialUrl === debouncedImageUrl) return
onNewUrl(imageUrl)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedImageUrl])

return (
<Stack py="2">
<Input
placeholder={'Paste the image link...'}
onChange={setImageUrl}
defaultValue={imageUrl}
/>
</Stack>
)
}
const EmbedLinkContent = ({ initialUrl, onNewUrl }: ContentProps) => (
<Stack py="2">
<Input
placeholder={'Paste the image link...'}
onChange={onNewUrl}
defaultValue={initialUrl ?? ''}
/>
</Stack>
)

const EmojiContent = ({
onEmojiSelected,
Expand Down
Binary file added apps/builder/public/images/dynamic-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a89f4ec

Please sign in to comment.