This repository has been archived by the owner on May 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (67 loc) · 2.68 KB
/
index.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Profile Viewer</title>
<script src="scripts/main.js"></script>
<script src="scripts/solid-auth-client.bundle.js"></script>
<script src="scripts/rdflib.min.js"></script>
</head>
<body>
<h1>Profile viewer</h1>
<div id="elm"></div>
<script>
const app = Elm.Main.init({
node: document.getElementById('elm')
});
solid.auth.trackSession(session => {
console.log('solid::trackSession', session);
app.ports.trackSession.send(session && session.webId);
});
app.ports.authRequest.subscribe(() => {
console.log('solid::popupLogin');
const popupUri = 'popup.html';
solid.auth.popupLogin({ popupUri });
});
app.ports.logout.subscribe(() => {
console.log('solid::logout');
solid.auth.logout();
});
app.ports.fetchProfile.subscribe(async function fetchProfile(person) {
console.log('solid::fetchProfile (person)', person);
// Set up a local data store and associated data fetcher
const store = $rdf.graph();
const fetcher = new $rdf.Fetcher(store);
// Load the person's data into the store
await fetcher.load(person);
// Display their details
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/');
const fullName = store.any($rdf.sym(person), FOAF('name'));
console.log('solid::fetchProfile (fullName)', fullName);
const friends = store.each($rdf.sym(person), FOAF('knows'));
const friendsPromises = friends.map(friend =>
fetcher.load(friend)
.then(response => {
const name = store.any(friend, FOAF('name'));
return {
name: name && name.value || '',
webId: friend.value
};
})
.catch(err => { console.error('err', err); return false; })
);
console.log('solid::fetchProfile (friendsPromises)', friendsPromises);
Promise.all(friendsPromises)
.then(results => {
const finalFriends = results.filter(x => !!x);
const profile = {
fullName: fullName && fullName.value || '',
friends: finalFriends
};
console.log('solid::fetchProfile (profile)', profile);
app.ports.loadProfile.send(profile);
});
});
</script>
</body>
</html>