Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
feat: use simpler context consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Aug 1, 2019
1 parent 8ab5d55 commit 66e0c26
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/About/About.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { Button, Card, CardBody, CardHeader } from 'reactstrap'
import { Cache } from 'aws-amplify'
import { IdentityIdContext } from '../App'
import { IdentityIdConsumer } from '../App'

export const About = () => (
<Card>
Expand All @@ -10,9 +10,9 @@ export const About = () => (
<dl>
<dt>User</dt>
<dd>
<IdentityIdContext.Consumer>
<IdentityIdConsumer>
{identityId => identityId}
</IdentityIdContext.Consumer>
</IdentityIdConsumer>
</dd>
</dl>
<hr />
Expand Down
4 changes: 4 additions & 0 deletions src/AccelerometerDiagram/AccelerometerDiagram.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
div.historicalDataChart {
width: 100%;
height: 250px;
}
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ Amplify.configure({
},
})

export const IdentityIdContext = React.createContext<string>('unauthorized')
export const CredentialsContext = React.createContext<{
const IdentityIdContext = React.createContext<string>('unauthorized')
export const IdentityIdConsumer = IdentityIdContext.Consumer
const CredentialsContext = React.createContext<{
accessKeyId: string
sessionToken: string
secretAccessKey: string
Expand All @@ -56,12 +57,14 @@ export const CredentialsContext = React.createContext<{
sessionToken: '',
secretAccessKey: '',
})
export const IotContext = React.createContext<{ iot: Iot; iotData: IotData }>({
export const CredentialsConsumer = CredentialsContext.Consumer
const IotContext = React.createContext<{ iot: Iot; iotData: IotData }>({
iot: new Iot(),
iotData: new IotData({
endpoint: process.env.REACT_APP_MQTT_ENDPOINT,
}),
})
export const IotConsumer = IotContext.Consumer

const Navigation = (props: {
navbar?: boolean
Expand Down
8 changes: 4 additions & 4 deletions src/Cat/Cat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { IdentityIdContext, IotContext, CredentialsContext } from '../App'
import { IdentityIdConsumer, IotConsumer, CredentialsConsumer } from '../App'
import { Card, CardHeader, CardBody } from 'reactstrap'
import { Iot, IotData, S3 } from 'aws-sdk'
import { Loading } from '../Loading/Loading'
Expand Down Expand Up @@ -358,9 +358,9 @@ export const Cat = ({ catId }: { catId: string }) => (
/>
)
}}
</IotContext.Consumer>
</IotConsumer>
)}
</IdentityIdContext.Consumer>
</IdentityIdConsumer>
)}
</CredentialsContext.Consumer>
</CredentialsConsumer>
)
6 changes: 3 additions & 3 deletions src/Cats/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { IotContext } from '../App'
import { IotConsumer } from '../App'
import { Table, Card, CardHeader, CardBody } from 'reactstrap'
import { Iot } from 'aws-sdk'
import { Loading } from '../Loading/Loading'
Expand Down Expand Up @@ -64,7 +64,7 @@ const ListCats = ({ iot }: { iot: Iot }) => {
}

export const List = () => (
<IotContext.Consumer>
<IotConsumer>
{({ iot }) => <ListCats iot={iot} />}
</IotContext.Consumer>
</IotConsumer>
)
Empty file.
Empty file.

0 comments on commit 66e0c26

Please sign in to comment.