-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c43fd1d
commit 2d17897
Showing
33 changed files
with
847 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
apps/builder/components/board/graph/BlockNode/StepNode/ContentPopover/ContentPopover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
Portal, | ||
PopoverContent, | ||
PopoverArrow, | ||
PopoverBody, | ||
} from '@chakra-ui/react' | ||
import { ImagePopoverContent } from 'components/shared/ImageUploadContent' | ||
import { useTypebot } from 'contexts/TypebotContext' | ||
import { | ||
BubbleStep, | ||
BubbleStepType, | ||
ImageBubbleContent, | ||
ImageBubbleStep, | ||
TextBubbleStep, | ||
} from 'models' | ||
import { useRef } from 'react' | ||
|
||
type Props = { | ||
step: Exclude<BubbleStep, TextBubbleStep> | ||
} | ||
|
||
export const ContentPopover = ({ step }: Props) => { | ||
const ref = useRef<HTMLDivElement | null>(null) | ||
const handleMouseDown = (e: React.MouseEvent) => e.stopPropagation() | ||
|
||
return ( | ||
<Portal> | ||
<PopoverContent onMouseDown={handleMouseDown} w="500px"> | ||
<PopoverArrow /> | ||
<PopoverBody ref={ref} shadow="lg"> | ||
<StepContent step={step} /> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Portal> | ||
) | ||
} | ||
|
||
export const StepContent = ({ step }: Props) => { | ||
const { updateStep } = useTypebot() | ||
const handleContentChange = (content: ImageBubbleContent) => | ||
updateStep(step.id, { content } as Partial<ImageBubbleStep>) | ||
|
||
const handleNewImageSubmit = (url: string) => handleContentChange({ url }) | ||
switch (step.type) { | ||
case BubbleStepType.IMAGE: { | ||
return ( | ||
<ImagePopoverContent | ||
url={step.content?.url} | ||
onSubmit={handleNewImageSubmit} | ||
/> | ||
) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/builder/components/board/graph/BlockNode/StepNode/ContentPopover/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ContentPopover } from './ContentPopover' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
apps/builder/components/shared/ImageUploadContent/GiphySearch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Flex, Input, Stack } from '@chakra-ui/react' | ||
import { GiphyFetch } from '@giphy/js-fetch-api' | ||
import { Grid, SearchContext } from '@giphy/react-components' | ||
import { GiphyLogo } from 'assets/logos' | ||
import React, { useContext, useState, useEffect } from 'react' | ||
import { useDebounce } from 'use-debounce' | ||
|
||
type GiphySearchProps = { | ||
onSubmit: (url: string) => void | ||
} | ||
|
||
const giphyFetch = new GiphyFetch( | ||
process.env.NEXT_PUBLIC_GIPHY_API_KEY as string | ||
) | ||
|
||
export const GiphySearch = ({ onSubmit }: GiphySearchProps) => { | ||
const { fetchGifs, searchKey, setSearch } = useContext(SearchContext) | ||
const fetchGifsTrending = (offset: number) => | ||
giphyFetch.trending({ offset, limit: 10 }) | ||
|
||
const [inputValue, setInputValue] = useState('') | ||
const [debouncedInputValue] = useDebounce(inputValue, 300) | ||
|
||
useEffect(() => { | ||
if (debouncedInputValue === '') return | ||
setSearch(debouncedInputValue) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [debouncedInputValue]) | ||
|
||
const updateUrl = (url: string) => { | ||
onSubmit(url) | ||
} | ||
|
||
return ( | ||
<Stack> | ||
<Flex align="center"> | ||
<Input | ||
flex="1" | ||
autoFocus | ||
placeholder="Search..." | ||
onChange={(e) => setInputValue(e.target.value)} | ||
value={inputValue} | ||
/> | ||
<GiphyLogo w="100px" /> | ||
</Flex> | ||
<Flex overflowY="scroll" maxH="400px"> | ||
<Grid | ||
onGifClick={(gif, e) => { | ||
e.preventDefault() | ||
updateUrl(gif.images.downsized.url) | ||
}} | ||
key={searchKey} | ||
fetchGifs={searchKey === '' ? fetchGifsTrending : fetchGifs} | ||
width={475} | ||
columns={3} | ||
className="my-4" | ||
/> | ||
</Flex> | ||
</Stack> | ||
) | ||
} |
Oops, something went wrong.