mirror of https://github.com/lukechilds/polar.git
jamaljsr
5 years ago
9 changed files with 242 additions and 129 deletions
@ -0,0 +1,66 @@ |
|||
import React from 'react'; |
|||
import { useAsyncCallback } from 'react-async-hook'; |
|||
import styled from '@emotion/styled'; |
|||
import { Button, Tooltip } from 'antd'; |
|||
import { useStoreActions } from 'store'; |
|||
import { Network, Status } from 'types'; |
|||
import lndLogo from 'resources/lnd.png'; |
|||
import SidebarCard from '../SidebarCard'; |
|||
import DraggableNode from './DraggableNode'; |
|||
|
|||
const Styled = { |
|||
AddNodes: styled.h3` |
|||
margin-top: 30px; |
|||
`,
|
|||
AddDesc: styled.p` |
|||
opacity: 0.5; |
|||
font-size: 12px; |
|||
`,
|
|||
}; |
|||
|
|||
interface Props { |
|||
network: Network; |
|||
} |
|||
|
|||
const DefaultSidebar: React.FC<Props> = ({ network }) => { |
|||
const { notify } = useStoreActions(s => s.app); |
|||
const { syncChart, redrawChart } = useStoreActions(s => s.designer); |
|||
const syncChartAsync = useAsyncCallback(async () => { |
|||
try { |
|||
await syncChart(network); |
|||
redrawChart(); |
|||
notify({ message: 'The designer has been synced with the Lightning nodes' }); |
|||
} catch (error) { |
|||
notify({ message: 'Failed to sync the network', error }); |
|||
} |
|||
}); |
|||
|
|||
return ( |
|||
<SidebarCard |
|||
title="Network Designer" |
|||
extra={ |
|||
<Tooltip title="Update channels from nodes"> |
|||
<Button |
|||
icon="reload" |
|||
disabled={network.status !== Status.Started} |
|||
onClick={syncChartAsync.execute} |
|||
loading={syncChartAsync.loading} |
|||
/> |
|||
</Tooltip> |
|||
} |
|||
> |
|||
<p>Click on an element in the designer to see details</p> |
|||
<Styled.AddNodes>Add Nodes</Styled.AddNodes> |
|||
<Styled.AddDesc> |
|||
Drag a node below onto the canvas to add it to the network |
|||
</Styled.AddDesc> |
|||
<DraggableNode |
|||
label="LND v0.7.1 Node" |
|||
icon={lndLogo} |
|||
properties={{ test: 'asd' }} |
|||
/> |
|||
</SidebarCard> |
|||
); |
|||
}; |
|||
|
|||
export default DefaultSidebar; |
@ -0,0 +1,42 @@ |
|||
import React from 'react'; |
|||
import styled from '@emotion/styled'; |
|||
import { REACT_FLOW_CHART } from '@mrblenny/react-flow-chart'; |
|||
|
|||
const Styled = { |
|||
Node: styled.div` |
|||
display: flex; |
|||
justify-content: space-between; |
|||
margin: 20px 0; |
|||
padding: 15px 20px; |
|||
border: 1px solid #e8e8e8; |
|||
border-radius: 3px; |
|||
box-shadow: 4px 2px 9px rgba(0, 0, 0, 0.1); |
|||
cursor: move; |
|||
`,
|
|||
Icon: styled.img` |
|||
width: 24px; |
|||
height: 24px; |
|||
`,
|
|||
}; |
|||
|
|||
interface Props { |
|||
label: string; |
|||
icon: string; |
|||
properties: any; |
|||
} |
|||
|
|||
const DraggableNode: React.FC<Props> = ({ label, icon, properties }) => { |
|||
return ( |
|||
<Styled.Node |
|||
draggable |
|||
onDragStart={event => { |
|||
event.dataTransfer.setData(REACT_FLOW_CHART, JSON.stringify(properties)); |
|||
}} |
|||
> |
|||
<span>{label}</span> |
|||
<Styled.Icon src={icon} alt={label} /> |
|||
</Styled.Node> |
|||
); |
|||
}; |
|||
|
|||
export default DraggableNode; |
Loading…
Reference in new issue