diff --git a/src/components/designer/NetworkDesigner.tsx b/src/components/designer/NetworkDesigner.tsx index f5225cb..7b2ac3e 100644 --- a/src/components/designer/NetworkDesigner.tsx +++ b/src/components/designer/NetworkDesigner.tsx @@ -5,7 +5,7 @@ import useDebounce from 'hooks/useDebounce'; import { useStoreActions, useStoreState } from 'store'; import { Network } from 'types'; import { Loader } from 'components/common'; -import { CustomLink, CustomNodeInner } from './custom'; +import { Link, NodeInner, Port, Ports } from './custom'; import OpenChannelModal from './lnd/OpenChannelModal'; import Sidebar from './Sidebar'; @@ -49,7 +49,12 @@ const NetworkDesigner: React.FC = ({ network, updateStateDelay = 3000 }) diff --git a/src/components/designer/custom/CustomLink.tsx b/src/components/designer/custom/Link.tsx similarity index 100% rename from src/components/designer/custom/CustomLink.tsx rename to src/components/designer/custom/Link.tsx diff --git a/src/components/designer/custom/CustomNodeInner.tsx b/src/components/designer/custom/NodeInner.tsx similarity index 100% rename from src/components/designer/custom/CustomNodeInner.tsx rename to src/components/designer/custom/NodeInner.tsx diff --git a/src/components/designer/custom/Port.tsx b/src/components/designer/custom/Port.tsx new file mode 100644 index 0000000..1ae3cdc --- /dev/null +++ b/src/components/designer/custom/Port.tsx @@ -0,0 +1,45 @@ +import React from 'react'; +import styled from '@emotion/styled'; +import { IPortDefaultProps } from '@mrblenny/react-flow-chart'; + +const Outer = styled.div` + width: 18px; + height: 18px; + border-radius: 50%; + background: white; + cursor: pointer; + display: flex; + justify-content: center; + align-items: center; + &:hover > div { + width: 10px; + height: 10px; + } +`; + +const Inner = styled.div<{ color: string; active: boolean }>` + width: ${props => (props.active ? '10px' : '7px')}; + height: ${props => (props.active ? '10px' : '7px')}; + border-radius: 50%; + background: ${props => props.color}; + cursor: pointer; + transition: all 0.3s; +`; + +const CustomPort: React.FC = ({ + port, + isLinkSelected, + isLinkHovered, +}) => { + let color = 'grey'; + if (port.properties) { + color = port.properties.initiator ? '#52c41a' : '#6495ED'; + } + return ( + + + + ); +}; + +export default CustomPort; diff --git a/src/components/designer/custom/Ports.tsx b/src/components/designer/custom/Ports.tsx new file mode 100644 index 0000000..e0cf7c9 --- /dev/null +++ b/src/components/designer/custom/Ports.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import { IPortsDefaultProps } from '@mrblenny/react-flow-chart'; +import PortsGroup from './PortsGroup'; + +const Ports: React.FC = ({ children, config }) => { + return ( +
+ + {children.filter(child => ['input', 'top'].includes(child.props.port.type))} + + + {children.filter(child => ['output', 'bottom'].includes(child.props.port.type))} + + + {children.filter(child => ['right'].includes(child.props.port.type))} + + + {children.filter(child => ['left'].includes(child.props.port.type))} + +
+ ); +}; + +export default Ports; diff --git a/src/components/designer/custom/PortsGroup.tsx b/src/components/designer/custom/PortsGroup.tsx new file mode 100644 index 0000000..6086e8c --- /dev/null +++ b/src/components/designer/custom/PortsGroup.tsx @@ -0,0 +1,54 @@ +import css from '@emotion/css'; +import styled from '@emotion/styled'; +import { IPortsGroupDefaultProps } from '@mrblenny/react-flow-chart'; + +const PortsGroup = styled.div` + position: absolute; + display: flex; + justify-content: center; + ${props => { + if (props.side === 'top') { + return css` + width: 100%; + left: 0; + top: -9px; + flex-direction: row; + > div { + margin: 0 3px; + } + `; + } else if (props.side === 'bottom') { + return css` + width: 100%; + left: 0; + bottom: -9px; + flex-direction: row; + > div { + margin: 0 3px; + } + `; + } else if (props.side === 'left') { + return css` + height: 100%; + top: 0; + left: -9px; + flex-direction: column; + > div { + margin: 3px 0; + } + `; + } else { + return css` + height: 100%; + top: 0; + right: -9px; + flex-direction: column; + > div { + margin: 3px 0; + } + `; + } + }} +`; + +export default PortsGroup; diff --git a/src/components/designer/custom/index.ts b/src/components/designer/custom/index.ts index b6446f6..2eca02b 100644 --- a/src/components/designer/custom/index.ts +++ b/src/components/designer/custom/index.ts @@ -1,2 +1,4 @@ -export { default as CustomLink } from './CustomLink'; -export { default as CustomNodeInner } from './CustomNodeInner'; +export { default as Link } from './Link'; +export { default as NodeInner } from './NodeInner'; +export { default as Port } from './Port'; +export { default as Ports } from './Ports'; diff --git a/src/components/designer/link/LinkDetails.tsx b/src/components/designer/link/LinkDetails.tsx index 6a4f40a..c157a3a 100644 --- a/src/components/designer/link/LinkDetails.tsx +++ b/src/components/designer/link/LinkDetails.tsx @@ -14,7 +14,7 @@ const LinkDetails: React.FC = ({ link, network }) => { let cmp =
You've somehow managed to select an invalid link
; const { bitcoin, lightning } = network.nodes; - const { type } = link.properties as LinkProperties; + const { type } = (link.properties as LinkProperties) || {}; switch (type) { case 'backend': const bitcoinNode = bitcoin.find(n => n.name === link.to.nodeId); diff --git a/src/components/network/NetworkView.tsx b/src/components/network/NetworkView.tsx index 1a5c8c1..6885a28 100644 --- a/src/components/network/NetworkView.tsx +++ b/src/components/network/NetworkView.tsx @@ -48,6 +48,15 @@ interface Props { const NetworkViewWrap: React.FC> = ({ match }) => { const { networks } = useStoreState(s => s.network); + const { load } = useStoreActions(s => s.network); + const { notify } = useStoreActions(s => s.app); + const loadAsync = useAsyncCallback(async () => { + try { + await load(); + } catch (error) { + notify({ message: 'Unable to load networks', error }); + } + }); if (match.params.id) { const networkId = parseInt(match.params.id); const network = networks.find(n => n.id === networkId); @@ -61,6 +70,9 @@ const NetworkViewWrap: React.FC> = ({ match }) image={Empty.PRESENTED_IMAGE_SIMPLE} description={`Could not find a network with the id '${match.params.id}'`} > +