Browse Source

Splitted indi panel

master
Anthony Hinsinger 4 years ago
parent
commit
85ec30234f
  1. 43
      src/apolloclient.js
  2. 1
      src/components/indi/panel.js
  3. 14
      src/devices.js

43
src/apolloclient.js

@ -78,6 +78,49 @@ const client = new ApolloClient({
}), }),
}); });
const GETDEVICES = gql`
query devices {
devices {
id
...DeviceInfo
messages @client
properties {
id
name
...PropertyVector
}
}
}
${deviceInfoFragment}
${propertyVectorFragment}
`;
const NEW_DEVICE = gql`
subscription newIndiDevice {
newIndiDevice {
id
...DeviceInfo
}
}
${deviceInfoFragment}
`;
client
.subscribe({
query: NEW_DEVICE,
})
.subscribe(({ data }) => {
const res = client.readQuery({ query: GETDEVICES });
data.newIndiDevice.properties = [];
data.newIndiDevice.messages = [];
client.writeQuery({
query: GETDEVICES,
data: { devices: [...res.devices, data.newIndiDevice] },
});
});
const GETDEVICE = gql` const GETDEVICE = gql`
query device($id: String!) { query device($id: String!) {
device(id: $id) { device(id: $id) {

1
src/components/indi/panel.js

@ -52,7 +52,6 @@ export const IndiPanel = () => {
)} )}
</Tabs> </Tabs>
) : null} ) : null}
<Button icon={<Contact />} onClick={() => setOpenMsg(true)} />
</Box> </Box>
); );
}; };

14
src/devices.js

@ -26,9 +26,9 @@ const GETDEVICES = gql`
${deviceInfoFragment} ${deviceInfoFragment}
`; `;
const CONNECT = gql` const START = gql`
mutation connect { mutation start {
connect start
} }
`; `;
@ -51,14 +51,9 @@ const useIndiState = () => {
const Devices = () => { const Devices = () => {
//const connected = useIndiState(); //const connected = useIndiState();
const { data } = useQuery(GETDEVICES); const [connect] = useMutation(START);
const [connect] = useMutation(CONNECT);
const [disconnect] = useMutation(DISCONNECT); const [disconnect] = useMutation(DISCONNECT);
if (!data || !data.devices) {
return <div>No data</div>;
}
return ( return (
<Box fill background="light-3"> <Box fill background="light-3">
<Header background="brand" pad="small"> <Header background="brand" pad="small">
@ -85,6 +80,7 @@ const Devices = () => {
}} }}
/> />
)} )}
<Button icon={<Contact />} onClick={() => {}} />
</Box> </Box>
</Header> </Header>

Loading…
Cancel
Save