forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
91 lines (78 loc) · 3.42 KB
/
Copy pathindex.ts
File metadata and controls
91 lines (78 loc) · 3.42 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
This file was copied from mashlib/src/global/footer.ts file. It is modified to
work in solid-ui by adjusting where imported functions are found.
*/
import { LiveStore, NamedNode } from 'rdflib'
import { authn, authSession } from 'solid-logic-jss'
import { style } from '../style'
import { getName, getPod, getPodOwner } from '../utils/headerFooterHelpers'
const DEFAULT_SOLID_PROJECT_URL = 'https://solidproject.org'
const DEFAULT_SOLID_PROJECT_NAME = 'solidproject.org'
/*
FooterOptions allow for customizing the link and name of the link part of the footer.
*/
export type FooterOptions = {
solidProjectUrl?: string,
solidProjectName?: string
}
/**
* Initialize footer component, the footer object returned depends on whether the user is authenticated.
* @param store the data store
* @returns the footer
*/
export async function initFooter (store: LiveStore, options?: FooterOptions) {
const footer = document.getElementById('PageFooter')
if (!footer) {
return
}
const pod = getPod()
const podOwner = await getPodOwner(pod, store)
rebuildFooter(footer, store, pod, podOwner, options)()
authSession.events.on('login', rebuildFooter(footer, store, pod, podOwner, options))
authSession.events.on('logout', rebuildFooter(footer, store, pod, podOwner, options))
}
/**
* @ignore exporting this only for the unit test
*/
export function rebuildFooter (footer: HTMLElement, store: LiveStore, pod: NamedNode | null, podOwner: NamedNode | null, options?: FooterOptions) {
return async () => {
const user = authn.currentUser()
footer.innerHTML = ''
footer.appendChild(await createControllerInfoBlock(store, user, pod, podOwner, options))
}
}
/**
* @ignore exporting this only for the unit test
*/
export function createControllerInfoBlock (store: LiveStore, user: NamedNode | null, pod: NamedNode | null, podOwner: NamedNode | null, options?: FooterOptions): HTMLElement {
const profileLinkContainer = document.createElement('div')
if (!pod || !podOwner || (user && user.equals(podOwner))) {
return profileLinkContainer
}
profileLinkContainer.setAttribute('style', style.footer)
const podLinkPre = document.createElement('span')
podLinkPre.innerText = 'You\'re visiting '
const podLink = document.createElement('a')
podLink.href = pod.uri
podLink.innerText = 'the Pod'
const profileLinkPre = document.createElement('span')
profileLinkPre.innerText = ' controlled by '
const profileLink = document.createElement('a')
profileLink.href = podOwner.uri
profileLink.innerText = getName(store, podOwner)
const solidProjectLinkPre = document.createElement('span')
solidProjectLinkPre.innerText = '. For more info, check out '
const solidProjectLink = document.createElement('a')
solidProjectLink.href = options && options.solidProjectUrl ? options.solidProjectUrl : DEFAULT_SOLID_PROJECT_URL
solidProjectLink.innerText = options && options.solidProjectName ? options.solidProjectName : DEFAULT_SOLID_PROJECT_NAME
const solidProjectLinkPost = document.createElement('span')
solidProjectLinkPost.innerText = '.'
profileLinkContainer.appendChild(podLinkPre)
profileLinkContainer.appendChild(podLink)
profileLinkContainer.appendChild(profileLinkPre)
profileLinkContainer.appendChild(profileLink)
profileLinkContainer.appendChild(solidProjectLinkPre)
profileLinkContainer.appendChild(solidProjectLink)
profileLinkContainer.appendChild(solidProjectLinkPost)
return profileLinkContainer
}