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 36
/
Copy pathmain.js
46 lines (40 loc) · 1.48 KB
/
main.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
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/');
// Log the user in and out on click
const popupUri = 'popup.html';
$('#login button').click(() => solid.auth.popupLogin({ popupUri }));
$('#logout button').click(() => solid.auth.logout());
// Update components to match the user's login status
solid.auth.trackSession(session => {
const loggedIn = !!session;
$('#login').toggle(!loggedIn);
$('#logout').toggle(loggedIn);
if (loggedIn) {
$('#user').text(session.webId);
// Use the user's WebID as default profile
if (!$('#profile').val())
$('#profile').val(session.webId);
}
});
$('#view').click(async function loadProfile() {
// 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
const person = $('#profile').val();
await fetcher.load(person);
// Display their details
const fullName = store.any($rdf.sym(person), FOAF('name'));
$('#fullName').text(fullName && fullName.value);
// Display their friends
const friends = store.each($rdf.sym(person), FOAF('knows'));
$('#friends').empty();
friends.forEach(async (friend) => {
await fetcher.load(friend);
const fullName = store.any(friend, FOAF('name'));
$('#friends').append(
$('<li>').append(
$('<a>').text(fullName && fullName.value || friend.value)
.click(() => $('#profile').val(friend.value))
.click(loadProfile)));
});
});