-
Notifications
You must be signed in to change notification settings - Fork 42
/
dashboardPane.ts
66 lines (60 loc) · 1.85 KB
/
dashboardPane.ts
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
import { SolidSession } from '../types'
import { authn, icons, store } from 'solid-ui'
import { NamedNode, sym } from 'rdflib'
import { generateHomepage } from './homepage'
import { DataBrowserContext, PaneDefinition } from 'pane-registry'
export const dashboardPane: PaneDefinition = {
icon: icons.iconBase + 'noun_547570.svg',
name: 'dashboard',
label: subject => {
if (subject.uri === subject.site().uri) {
return 'Dashboard'
}
return null
},
render: (subject, context) => {
const dom = context.dom
const container = dom.createElement('div')
authn.solidAuthClient.trackSession(async (session: SolidSession) => {
container.innerHTML = ''
buildPage(
container,
session ? sym(session.webId) : null,
context,
subject
)
})
return container
}
}
function buildPage (
container: HTMLElement,
webId: NamedNode | null,
context: DataBrowserContext,
subject: NamedNode
) {
if (webId && webId.site().uri === subject.site().uri) {
return buildDashboard(container, context)
}
return buildHomePage(container, subject)
}
function buildDashboard (container: HTMLElement, context: DataBrowserContext) {
// @@ TODO get a proper type
const outliner: any = context.getOutliner(context.dom)
outliner
.getDashboard()
.then((dashboard: HTMLElement) => container.appendChild(dashboard))
}
function buildHomePage (container: HTMLElement, subject: NamedNode) {
const wrapper = document.createElement('div')
container.appendChild(wrapper)
const shadow = wrapper.attachShadow({ mode: 'open' })
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = '/common/css/bootstrap.min.css'
shadow.appendChild(link)
generateHomepage(subject, store, store.fetcher).then(homepage =>
shadow.appendChild(homepage)
)
}
export default dashboardPane