Skip to content

Commit f832625

Browse files
committed
Simplify status components.
1 parent 02820a3 commit f832625

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

demo/components/Copy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
// @flow
12
import React from 'react'
23

34
import auth from '../../src/'
45

56
export default class Copy extends React.Component<Object, Object> {
6-
constructor(props) {
7-
super(props)
8-
auth.trackSession(session => this.setState({ loggedIn: !!session }))
7+
componentWillMount() {
8+
auth.trackSession(session =>
9+
this.setState({ webId: session && session.webId })
10+
)
911
}
1012

1113
render() {
12-
const { loggedIn } = this.state
14+
const { webId } = this.state
1315
return (
1416
<p>
1517
This is a simple demo of the Solid Auth Client. You're currently
16-
{loggedIn
17-
? ' logged in.'
18-
: ' anonymous. Click "Log in" to authenticate and see some information about yourself.'}
18+
{webId ? ' logged in' : ' anonymous'}.
1919
</p>
2020
)
2121
}

demo/components/PersonalInfo.js

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,23 @@ import React from 'react'
33

44
import auth from '../../src/'
55

6-
type Profile = {
7-
'foaf:name': ?{ '@value': string }
8-
}
9-
106
export default class PersonalInfo extends React.Component<Object, Object> {
11-
constructor(props: {}) {
12-
super(props)
13-
auth.trackSession(async session => {
14-
let webId, profile, name
15-
if (session) {
16-
webId = session.webId
17-
profile = await this.fetchProfile(webId)
18-
name = profile['foaf:name'] && profile['foaf:name']['@value']
19-
}
20-
this.setState({ webId, name })
21-
})
22-
}
23-
24-
fetchProfile = (webId: string): Promise<Profile> => {
25-
const query = `
26-
@prefix foaf http://xmlns.com/foaf/0.1/
27-
${webId} { foaf:name }
28-
`
29-
return auth
30-
.fetch('https://databox.me/,query', {
31-
method: 'POST',
32-
body: query
33-
})
34-
.then(resp => resp.json())
7+
componentWillMount() {
8+
auth.trackSession(session =>
9+
this.setState({ webId: session && session.webId })
10+
)
3511
}
3612

3713
render() {
38-
const { webId, name } = this.state
14+
const { webId } = this.state
3915
return webId ? (
40-
<div>
41-
Hey there, <span>{name}</span>! Your WebID is:{' '}
16+
<p>
17+
Your WebID is{' '}
4218
<a href={webId} target="_blank">
4319
<code>{webId}</code>
4420
</a>
45-
</div>
21+
.
22+
</p>
4623
) : null
4724
}
4825
}

0 commit comments

Comments
 (0)