Adapted to astraw-server
This commit is contained in:
+42
-6
@@ -58,13 +58,13 @@ const client = new ApolloClient({
|
|||||||
IndiVector: ["NumberVector", "SwitchVector", "TextVector", "LightVector"],
|
IndiVector: ["NumberVector", "SwitchVector", "TextVector", "LightVector"],
|
||||||
},
|
},
|
||||||
typePolicies: {
|
typePolicies: {
|
||||||
/*Query: {
|
Query: {
|
||||||
fields: {
|
fields: {
|
||||||
device(_, { toReference, args }) {
|
device(_, { toReference, args }) {
|
||||||
return toReference({ __typename: "IndiDevice", id: args.id });
|
return toReference({ __typename: "IndiDevice", id: args.id });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},*/
|
},
|
||||||
IndiDevice: {
|
IndiDevice: {
|
||||||
fields: {
|
fields: {
|
||||||
messages: {
|
messages: {
|
||||||
@@ -129,17 +129,53 @@ client
|
|||||||
/*drivers:
|
/*drivers:
|
||||||
data.newProperty.name === "DRIVER_INFO"
|
data.newProperty.name === "DRIVER_INFO"
|
||||||
? data.newProperty.vector.values[3].text
|
? data.newProperty.vector.values[3].text
|
||||||
: res.device.drivers,
|
: res.device.drivers,*/
|
||||||
connected:
|
connected:
|
||||||
data.newProperty.name === "CONNECTION"
|
data.newIndiProp.name === "CONNECTION"
|
||||||
? data.newProperty.vector.values[0].switch
|
? data.newIndiProp.vector.values[0].switch
|
||||||
: res.device.connected,*/
|
: res.device.connected,
|
||||||
properties: [...res.device.properties, data.newIndiProp],
|
properties: [...res.device.properties, data.newIndiProp],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const NEW_VALUE = gql`
|
||||||
|
subscription newIndiValue {
|
||||||
|
newIndiValue {
|
||||||
|
id
|
||||||
|
device
|
||||||
|
...VectorData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
${vectorFragment}
|
||||||
|
`;
|
||||||
|
|
||||||
|
client
|
||||||
|
.subscribe({
|
||||||
|
query: NEW_VALUE,
|
||||||
|
})
|
||||||
|
.subscribe(({ data }) => {
|
||||||
|
if (data.newIndiValue.name === "CONNECTION") {
|
||||||
|
const res = client.readQuery({
|
||||||
|
query: GETDEVICE,
|
||||||
|
variables: { id: data.newIndiValue.device },
|
||||||
|
});
|
||||||
|
client.writeQuery({
|
||||||
|
query: GETDEVICE,
|
||||||
|
variables: { id: res.device.id },
|
||||||
|
data: {
|
||||||
|
device: {
|
||||||
|
...res.device,
|
||||||
|
connected: data.newIndiValue.values[0].switch,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const CONNECTED = gql`
|
const CONNECTED = gql`
|
||||||
subscription connected {
|
subscription connected {
|
||||||
|
|||||||
+11
-2
@@ -7,6 +7,7 @@ import Device from "./components/indi/device";
|
|||||||
import { Box, Tabs, Tab, Button, Header, Heading, Layer } from "grommet";
|
import { Box, Tabs, Tab, Button, Header, Heading, Layer } from "grommet";
|
||||||
import { Contact } from "grommet-icons";
|
import { Contact } from "grommet-icons";
|
||||||
import { isConnectedQuery } from "./graphql/query";
|
import { isConnectedQuery } from "./graphql/query";
|
||||||
|
import { StatusGood, StatusDisabled } from "grommet-icons";
|
||||||
|
|
||||||
const GETDEVICES = gql`
|
const GETDEVICES = gql`
|
||||||
query devices {
|
query devices {
|
||||||
@@ -103,8 +104,16 @@ const Devices = () => {
|
|||||||
<Tabs justify="start">
|
<Tabs justify="start">
|
||||||
{data && data.devices ? (
|
{data && data.devices ? (
|
||||||
data.devices.map((d) => (
|
data.devices.map((d) => (
|
||||||
<Tab title={d.name} key={d.id}>
|
<Tab
|
||||||
<Device device={d} messages={openMsg} onMessagesClosed={() => setOpenMsg(false)}/>
|
icon={d.connected ? <StatusGood /> : <StatusDisabled />}
|
||||||
|
title={d.name}
|
||||||
|
key={d.id}
|
||||||
|
>
|
||||||
|
<Device
|
||||||
|
device={d}
|
||||||
|
messages={openMsg}
|
||||||
|
onMessagesClosed={() => setOpenMsg(false)}
|
||||||
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user