Skip to content

Commit

Permalink
fix(editor): ♿️ Improve block focus
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 29, 2022
1 parent 1f992c6 commit 261cd9a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
blocksCoordinates,
updateBlockCoordinates,
isReadOnly,
focusedBlockId,
setFocusedBlockId,
} = useGraph()
const { typebot, updateBlock } = useTypebot()
const { setMouseOverBlock, mouseOverBlock } = useStepDnd()
Expand Down Expand Up @@ -91,7 +93,10 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
})
}

const onDragStart = () => setIsMouseDown(true)
const onDragStart = () => {
setFocusedBlockId(block.id)
setIsMouseDown(true)
}
const onDragStop = () => setIsMouseDown(false)
return (
<ContextMenu<HTMLDivElement>
Expand Down Expand Up @@ -131,6 +136,7 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
cursor={isMouseDown ? 'grabbing' : 'pointer'}
boxShadow="0px 0px 0px 1px #e9edf3;"
_hover={{ shadow: 'lg' }}
zIndex={focusedBlockId === block.id ? 10 : 1}
>
<Editable
defaultValue={block.title}
Expand Down
10 changes: 8 additions & 2 deletions apps/builder/components/shared/Graph/Nodes/StepNode/StepNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ export const StepNode = ({
onMouseDown?: (stepNodePosition: NodePosition, step: DraggableStep) => void
}) => {
const { query } = useRouter()
const { setConnectingIds, connectingIds, openedStepId, setOpenedStepId } =
useGraph()
const {
setConnectingIds,
connectingIds,
openedStepId,
setOpenedStepId,
setFocusedBlockId,
} = useGraph()
const { updateStep } = useTypebot()
const [isConnecting, setIsConnecting] = useState(false)
const [isPopoverOpened, setIsPopoverOpened] = useState(
Expand Down Expand Up @@ -113,6 +118,7 @@ export const StepNode = ({
}

const handleClick = (e: React.MouseEvent) => {
setFocusedBlockId(step.blockId)
e.stopPropagation()
if (isTextBubbleStep(step)) setIsEditing(true)
setOpenedStepId(step.id)
Expand Down
1 change: 1 addition & 0 deletions apps/builder/components/shared/VariableSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const VariableSearchInput = ({
debounced(e.target.value)
onOpen()
if (e.target.value === '') {
onSelectVariable(undefined)
setFilteredItems([...variables.slice(0, 50)])
return
}
Expand Down
6 changes: 6 additions & 0 deletions apps/builder/contexts/GraphContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const graphContext = createContext<{
openedStepId?: string
setOpenedStepId: Dispatch<SetStateAction<string | undefined>>
isReadOnly: boolean
focusedBlockId?: string
setFocusedBlockId: Dispatch<SetStateAction<string | undefined>>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
}>({
Expand All @@ -98,6 +100,8 @@ export const GraphProvider = ({
const [blocksCoordinates, setBlocksCoordinates] = useState<BlocksCoordinates>(
{}
)
const [focusedBlockId, setFocusedBlockId] = useState<string>()

useEffect(() => {
setBlocksCoordinates(
blocks.reduce(
Expand Down Expand Up @@ -149,6 +153,8 @@ export const GraphProvider = ({
blocksCoordinates,
updateBlockCoordinates,
isReadOnly,
focusedBlockId,
setFocusedBlockId,
}}
>
{children}
Expand Down

3 comments on commit 261cd9a

@vercel
Copy link

@vercel vercel bot commented on 261cd9a Mar 29, 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 261cd9a Mar 29, 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 261cd9a Mar 29, 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

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

Please sign in to comment.