Skip to content

Commit

Permalink
Fix icon on initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmarklloyd committed Jun 1, 2021
1 parent 115300d commit 359c29d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions server/frontend/src/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ class Home extends Component {
return a.source > b.source ? 1 : -1
});
d.data.forEach(element => {
var updated = translateStatus(element.status)
sensors.push({
source: element.source,
status: element.status,
timestamp: element.timestamp,
timesince: timeSince(element.timestamp),
icon: "zap-off"
icon: updated.icon,
color: updated.color
})
})
component.setState({data: sensors})
})
}

render() {
var state
return (
<SiteWrapper>
<Page.Content>
{this.state.data.length > 0 ? (
<Grid.Row cards={true}>
<Grid.Col sm={6} lg={3}>
{this.state.data.map(item => (
state = translateStatus(item.status), // eslint-disable-line no-sequences
<Sensor key={item.source} source={item.source} socket={socket} status={item.status} icon={state.icon} color={state.color} timestamp={item.timestamp} timesince={item.timesince}/>
<Sensor key={item.source} source={item.source} socket={socket} status={item.status} icon={item.icon} color={item.color} timestamp={item.timestamp} timesince={item.timesince}/>
))
}
</Grid.Col>
Expand Down
5 changes: 1 addition & 4 deletions server/frontend/src/Sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class Sensor extends Component {
this.props.socket.on("sensor/status", function(data) {
if (data.source === source) {
var updated = translateStatus(data.status)
if (data.source === "front-door") {
console.log(updated)
}
component.setState({
color: updated.color,
source: data.source,
Expand All @@ -31,7 +28,7 @@ class Sensor extends Component {
state = {
color: "",
source: this.props.source,
icon: "zap-off",
icon: "",
timestamp: "",
timesince: ""
};
Expand Down

0 comments on commit 359c29d

Please sign in to comment.