Permalink
Browse files

Simplify status components.

  • Loading branch information...
RubenVerborgh committed Nov 19, 2018
1 parent 02820a3 commit f832625bd7095e5d25d6dc12e3ec5d1483888e49
Showing with 16 additions and 39 deletions.
  1. +7 −7 demo/components/Copy.js
  2. +9 −32 demo/components/PersonalInfo.js
@@ -1,21 +1,21 @@
// @flow
import React from 'react'

import auth from '../../src/'

export default class Copy extends React.Component<Object, Object> {
constructor(props) {
super(props)
auth.trackSession(session => this.setState({ loggedIn: !!session }))
componentWillMount() {
auth.trackSession(session =>
this.setState({ webId: session && session.webId })
)
}

render() {
const { loggedIn } = this.state
const { webId } = this.state
return (
<p>
This is a simple demo of the Solid Auth Client. You're currently
{loggedIn
? ' logged in.'
: ' anonymous. Click "Log in" to authenticate and see some information about yourself.'}
{webId ? ' logged in' : ' anonymous'}.
</p>
)
}
@@ -3,46 +3,23 @@ import React from 'react'

import auth from '../../src/'

type Profile = {
'foaf:name': ?{ '@value': string }
}

export default class PersonalInfo extends React.Component<Object, Object> {
constructor(props: {}) {
super(props)
auth.trackSession(async session => {
let webId, profile, name
if (session) {
webId = session.webId
profile = await this.fetchProfile(webId)
name = profile['foaf:name'] && profile['foaf:name']['@value']
}
this.setState({ webId, name })
})
}

fetchProfile = (webId: string): Promise<Profile> => {
const query = `
@prefix foaf http://xmlns.com/foaf/0.1/
${webId} { foaf:name }
`
return auth
.fetch('https://databox.me/,query', {
method: 'POST',
body: query
})
.then(resp => resp.json())
componentWillMount() {
auth.trackSession(session =>
this.setState({ webId: session && session.webId })
)
}

render() {
const { webId, name } = this.state
const { webId } = this.state
return webId ? (
<div>
Hey there, <span>{name}</span>! Your WebID is:{' '}
<p>
Your WebID is{' '}
<a href={webId} target="_blank">
<code>{webId}</code>
</a>
</div>
.
</p>
) : null
}
}

0 comments on commit f832625

Please sign in to comment.