forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboardPane.ts
More file actions
82 lines (75 loc) · 2.29 KB
/
Copy pathdashboardPane.ts
File metadata and controls
82 lines (75 loc) · 2.29 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
import { authn, icons, store } from 'solid-ui'
import { Fetcher, NamedNode } 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 => {
console.log()
if (subject.uri === subject.site().uri) {
return 'Dashboard'
}
return null
},
render: (subject, context) => {
console.log('Dashboard Pane Render')
const dom = context.dom
const container = dom.createElement('div')
const runBuildPage = () => {
container.innerHTML = ''
buildPage(
container,
authn.currentUser() || null,
context,
subject
)
}
authn.authSession.onLogin(() => {
// console.log('On Login')
runBuildPage()
})
authn.authSession.onSessionRestore(() => {
// console.log('On Session Restore')
runBuildPage()
})
// console.log('Initial Load')
runBuildPage()
return container
}
}
function buildPage (
container: HTMLElement,
webId: NamedNode | null,
context: DataBrowserContext,
subject: NamedNode
) {
// if uri then SolidOS is a browse.html web app
const uri = (new URL(window.location.href)).searchParams.get('uri')
if (webId && (uri || webId.site().uri === subject.site().uri)) {
return buildDashboard(container, context)
}
return buildHomePage(container, subject)
}
function buildDashboard (container: HTMLElement, context: DataBrowserContext) {
// console.log('build dashboard')
// @@ 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) {
// console.log('build home page')
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 as Fetcher).then(homepage =>
shadow.appendChild(homepage)
)
}
export default dashboardPane