This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
App.js
53 lines (49 loc) · 1.63 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react';
import { LoggedIn, LoggedOut, AuthButton, Value, List, withWebId } from '@solid/react';
import './App.css';
class App extends React.Component {
state = { profileInput: '', activeProfile: '' };
componentDidUpdate(prevProps) {
const { webId } = this.props;
if (webId && webId !== prevProps.webId)
this.setState({ profileInput: webId });
}
viewProfile(profile) {
this.setState({ profileInput: profile, activeProfile: profile });
}
render() {
const { profileInput, activeProfile } = this.state;
return (
<div>
<h1>Profile viewer</h1>
<p>
<LoggedOut>You are not logged in.</LoggedOut>
<LoggedIn>You are logged in as <Value src="user.name"/>.</LoggedIn>
<AuthButton popup="popup.html"/>
</p>
<p>
<label htmlFor="profile">Profile:</label>
<input id="profile" value={profileInput}
onChange={e => this.setState({ profileInput: e.target.value })}/>
<button onClick={() => this.viewProfile(profileInput)}>View</button>
</p>
{activeProfile &&
<dl>
<dt>Full name</dt>
<dd><Value src={`[${activeProfile}].name`}/></dd>
<dt>Friends</dt>
<dd>
<List src={`[${activeProfile}].friends`}>{friend =>
<li key={friend}>
<button onClick={() => this.viewProfile(friend)}>
<Value src={`[${friend}].name`}>{`${friend}`}</Value>
</button>
</li>}
</List>
</dd>
</dl>}
</div>
);
}
}
export default withWebId(App);