Browse Source

Improved message display

master
Anthony Hinsinger 6 years ago
parent
commit
f15787abe3
  1. 3
      src/App.js
  2. 62
      src/components/indi/device.js
  3. 1
      src/components/indi/text.js

3
src/App.js

@ -44,6 +44,9 @@ const theme = deepMerge(grommet, { @@ -44,6 +44,9 @@ const theme = deepMerge(grommet, {
vertical: "xsmall",
},
},
layer: {
background: "#00000000",
},
});
function App() {

62
src/components/indi/device.js

@ -1,9 +1,17 @@ @@ -1,9 +1,17 @@
import React, { useState, useEffect, Fragment } from "react";
import { useMutation, useApolloClient } from "@apollo/react-hooks";
import React, { useState, useEffect, useContext } from "react";
import { useMutation, useApolloClient } from "@apollo/react-hooks";
import { msgToColor } from "../../utils/indi";
import Property from "./property";
import gql from "graphql-tag";
import { Box, Button, Tabs, Tab, Text, Layer } from "grommet";
import {
Box,
Button,
Tabs,
Tab,
Text,
Layer,
ResponsiveContext,
} from "grommet";
import { Close, Trash } from "grommet-icons";
const CONNECT_DEVICE = gql`
@ -28,6 +36,7 @@ const Device = ({ device, messages, onMessagesClosed }) => { @@ -28,6 +36,7 @@ const Device = ({ device, messages, onMessagesClosed }) => {
const [groups, setGroups] = useState([]);
const [selectedTabs, setSelectedTabs] = useState({});
const [currentTab, setCurrentTab] = useState(0);
const size = useContext(ResponsiveContext);
useEffect(() => {
const groups = new Set();
@ -36,7 +45,7 @@ const Device = ({ device, messages, onMessagesClosed }) => { @@ -36,7 +45,7 @@ const Device = ({ device, messages, onMessagesClosed }) => {
});
setGroups(Array.from(groups));
setCurrentTab(selectedTabs[device.id] || 0);
}, [device]);
}, [device, selectedTabs]);
return (
<Box>
@ -72,26 +81,33 @@ const Device = ({ device, messages, onMessagesClosed }) => { @@ -72,26 +81,33 @@ const Device = ({ device, messages, onMessagesClosed }) => {
{messages ? (
<Layer position="right" full="vertical" modal={false}>
<Box direction="row">
<Button icon={<Close />} onClick={() => onMessagesClosed()} />
<Box
background={{ color: "light-1", opacity: "strong" }}
fill="vertical"
align="start"
width={size}
>
<Box direction="row" justify="end" fill="horizontal">
<Button
icon={<Trash />}
onClick={() => {
client.writeFragment({
id: client.cache.config.dataIdFromObject(device),
fragment: MSGS_FRAGMENT,
data: {
__typename: "Device",
messages: [],
},
});
}}
/>
</Box>
<Box width="medium" pad="small">
{device.messages.map((msg) => (
<Text color={msgToColor(msg)}>{msg}</Text>
))}
icon={<Trash />}
onClick={() => {
client.writeFragment({
id: client.cache.config.dataIdFromObject(device),
fragment: MSGS_FRAGMENT,
data: {
__typename: "Device",
messages: [],
},
});
}}
/>
<Button icon={<Close />} onClick={() => onMessagesClosed()} />
</Box>
<Box pad="medium">
{device.messages.map((msg) => (
<Text color={msgToColor(msg)}>{msg}</Text>
))}
</Box>
</Box>
</Layer>
) : null}

1
src/components/indi/text.js

@ -33,7 +33,6 @@ const TextValue = ({ vector, value }) => { @@ -33,7 +33,6 @@ const TextValue = ({ vector, value }) => {
name: value.name,
value: newval,
};
console.log(input);
sendOneText({ variables: { input } });
}}
></Button>

Loading…
Cancel
Save