Skip to content

Commit

Permalink
feat(editor): ♿️ Improve previewing blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 2, 2022
1 parent 0500981 commit 327da31
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
const [isMouseDown, setIsMouseDown] = useState(false)
const [isConnecting, setIsConnecting] = useState(false)
const isPreviewing =
previewingEdge?.to.blockId === block.id ||
previewingEdge?.from.blockId === block.id
previewingEdge?.from.blockId === block.id ||
(previewingEdge?.to.blockId === block.id &&
isNotDefined(previewingEdge.to.stepId))
const isStartBlock =
isDefined(block.steps[0]) && block.steps[0].type === 'start'

Expand Down
68 changes: 37 additions & 31 deletions apps/builder/components/shared/Graph/Nodes/ItemNode/ItemNode.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex } from '@chakra-ui/react'
import { ContextMenu } from 'components/shared/ContextMenu'
import { Coordinates } from 'contexts/GraphContext'
import { Coordinates, useGraph } from 'contexts/GraphContext'
import { NodePosition, useDragDistance } from 'contexts/GraphDndContext'
import { useTypebot } from 'contexts/TypebotContext'
import {
Expand Down Expand Up @@ -35,8 +35,10 @@ export const ItemNode = ({
onMouseDown,
}: Props) => {
const { typebot } = useTypebot()
const { previewingEdge } = useGraph()
const [isMouseOver, setIsMouseOver] = useState(false)
const itemRef = useRef<HTMLDivElement | null>(null)
const isPreviewing = previewingEdge?.from.itemId === item.id
const isConnectable = !(
typebot?.blocks[indices.blockIndex].steps[
indices.stepIndex
Expand All @@ -62,39 +64,43 @@ export const ItemNode = ({
{(ref, isOpened) => (
<Flex
data-testid="item"
ref={setMultipleRefs([ref, itemRef])}
align="center"
pos="relative"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
shadow="sm"
_hover={isReadOnly ? {} : { shadow: 'md' }}
transition="box-shadow 200ms"
borderWidth="1px"
rounded="md"
borderColor={isOpened ? 'blue.400' : 'gray.100'}
pointerEvents={isReadOnly ? 'none' : 'all'}
bgColor="white"
w="full"
ref={setMultipleRefs([ref, itemRef])}
>
<ItemNodeContent
item={item}
isMouseOver={isMouseOver}
indices={indices}
isLastItem={isLastItem}
/>
{typebot && isConnectable && (
<SourceEndpoint
source={{
blockId: typebot.blocks[indices.blockIndex].id,
stepId: item.stepId,
itemId: item.id,
}}
pos="absolute"
right="-49px"
pointerEvents="all"
<Flex
align="center"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
shadow="sm"
_hover={isReadOnly ? {} : { shadow: 'md' }}
transition="box-shadow 200ms, border-color 200ms"
rounded="md"
borderWidth={isOpened || isPreviewing ? '2px' : '1px'}
borderColor={isOpened || isPreviewing ? 'blue.400' : 'gray.100'}
margin={isOpened || isPreviewing ? '-1px' : 0}
pointerEvents={isReadOnly ? 'none' : 'all'}
bgColor="white"
w="full"
>
<ItemNodeContent
item={item}
isMouseOver={isMouseOver}
indices={indices}
isLastItem={isLastItem}
/>
)}
{typebot && isConnectable && (
<SourceEndpoint
source={{
blockId: typebot.blocks[indices.blockIndex].id,
stepId: item.stepId,
itemId: item.id,
}}
pos="absolute"
right="-49px"
pointerEvents="all"
/>
)}
</Flex>
</Flex>
)}
</ContextMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const StepNode = ({
openedStepId,
setOpenedStepId,
setFocusedBlockId,
previewingEdge,
} = useGraph()
const { updateStep } = useTypebot()
const [isConnecting, setIsConnecting] = useState(false)
Expand All @@ -62,6 +63,8 @@ export const StepNode = ({
)
const stepRef = useRef<HTMLDivElement | null>(null)

const isPreviewing = isConnecting || previewingEdge?.to.stepId === step.id

const onDrag = (position: NodePosition) => {
if (step.type === 'start' || !onMouseDown) return
onMouseDown(position, step)
Expand Down Expand Up @@ -170,8 +173,9 @@ export const StepNode = ({
flex="1"
userSelect="none"
p="3"
borderWidth="1px"
borderColor={isConnecting || isOpened ? 'blue.400' : 'gray.200'}
borderWidth={isOpened || isPreviewing ? '2px' : '1px'}
borderColor={isOpened || isPreviewing ? 'blue.400' : 'gray.200'}
margin={isOpened || isPreviewing ? '-1px' : 0}
rounded="lg"
cursor={'pointer'}
bgColor="gray.50"
Expand Down

4 comments on commit 327da31

@vercel
Copy link

@vercel vercel bot commented on 327da31 Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 327da31 Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 327da31 Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 327da31 Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2-alpha – ./apps/viewer

viewer-v2-alpha-git-main-typebot-io.vercel.app
viewer-v2-alpha-typebot-io.vercel.app

Please sign in to comment.