Files
sim/app/w/hooks/use-block-connections.ts
2025-01-31 11:29:13 -08:00

36 lines
801 B
TypeScript

import { useWorkflowStore } from '@/stores/workflow/store'
import { shallow } from 'zustand/shallow'
export interface ConnectedBlock {
id: string
type: string
outputType: string
name: string
}
export function useBlockConnections(blockId: string) {
const { edges, blocks } = useWorkflowStore(
(state) => ({
edges: state.edges,
blocks: state.blocks
}),
shallow
)
const incomingConnections = edges
.filter(edge => edge.target === blockId)
.map(edge => {
const sourceBlock = blocks[edge.source]
return {
id: sourceBlock.id,
type: sourceBlock.type,
outputType: 'response',
name: sourceBlock.name,
}
})
return {
incomingConnections,
hasIncomingConnections: incomingConnections.length > 0
}
}