Skip to content

Commit c56e9e6

Browse files
authored
Merge pull request #198 from solid/deconstructing-ui
Importing specific parts of solid-ui
2 parents d3cee3e + 8601dd7 commit c56e9e6

9 files changed

Lines changed: 141 additions & 193 deletions

File tree

src/dashboard/basicPreferences.source.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { PaneDefinition } from '../types'
2-
import UI from 'solid-ui'
3-
import namespace from 'solid-namespace'
4-
import { NamedNode, parse, namedNode, IndexedFormula } from 'rdflib'
2+
import { authn, icons, ns, store, widgets } from 'solid-ui'
3+
import { NamedNode, parse, IndexedFormula } from 'rdflib'
54
import { renderTrustedApplicationsOptions } from './trustedApplications/trustedApplicationsPane'
65

76
import preferencesFormText from './preferencesFormText.ttl'
87
import ontologyData from './ontologyData.ttl'
98

10-
const kb = UI.store
11-
const ns = namespace({ namedNode } as any)
12-
139
export const basicPreferencesPane: PaneDefinition = {
14-
icon: UI.icons.iconBase + 'noun_Sliders_341315_000000.svg',
10+
icon: icons.iconBase + 'noun_Sliders_341315_000000.svg',
1511
name: 'basicPreferences',
1612
label: _subject => {
1713
return null
@@ -22,7 +18,7 @@ export const basicPreferencesPane: PaneDefinition = {
2218
render: (subject: NamedNode, dom: HTMLDocument) => {
2319
function complainIfBad (ok: Boolean, mess: any) {
2420
if (ok) return
25-
container.appendChild(UI.widgets.errorMessageBlock(dom, mess, '#fee'))
21+
container.appendChild(widgets.errorMessageBlock(dom, mess, '#fee'))
2622
}
2723

2824
const container = dom.createElement('div')
@@ -31,23 +27,23 @@ export const basicPreferencesPane: PaneDefinition = {
3127

3228
function loadData (doc: NamedNode, turtle: String) {
3329
doc = doc.doc() // remove # from URI if nec
34-
if (!kb.holds(undefined, undefined, undefined, doc)) {
30+
if (!store.holds(undefined, undefined, undefined, doc)) {
3531
// If not loaded already
36-
;(parse as any)(turtle, kb, doc.uri, 'text/turtle', null) // Load form directly
32+
;(parse as any)(turtle, store, doc.uri, 'text/turtle', null) // Load form directly
3733
}
3834
}
39-
const preferencesForm = kb.sym(
35+
const preferencesForm = store.sym(
4036
'urn:uuid:93774ba1-d3b6-41f2-85b6-4ae27ffd2597#this'
4137
)
4238
loadData(preferencesForm, preferencesFormText)
4339

44-
const ontologyExtra = kb.sym(
40+
const ontologyExtra = store.sym(
4541
'urn:uuid:93774ba1-d3b6-41f2-85b6-4ae27ffd2597-ONT'
4642
)
4743
loadData(ontologyExtra, ontologyData)
4844

4945
async function doRender () {
50-
const context = await UI.authn.logInLoadPreferences({
46+
const context = await authn.logInLoadPreferences({
5147
dom,
5248
div: container
5349
})
@@ -59,8 +55,8 @@ export const basicPreferencesPane: PaneDefinition = {
5955
)
6056
return
6157
}
62-
addDeletionLinks(container, kb, context.me)
63-
const appendedForm = UI.widgets.appendForm(
58+
addDeletionLinks(container, store, context.me)
59+
const appendedForm = widgets.appendForm(
6460
dom,
6561
formArea,
6662
{},

src/dashboard/dashboardPane.source.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { PaneDefinition, SolidSession } from '../types'
2-
import UI from 'solid-ui'
2+
import { authn, icons, store } from 'solid-ui'
33
import panes from 'pane-registry'
44
import { NamedNode, sym } from 'rdflib'
55
import { generateHomepage } from './homepage'
66

77
export const dashboardPaneSource: PaneDefinition = {
8-
icon: UI.icons.iconBase + 'noun_547570.svg',
8+
icon: icons.iconBase + 'noun_547570.svg',
99
name: 'dashboard',
1010
label: subject => {
1111
if (subject.uri === subject.site().uri) {
@@ -15,7 +15,7 @@ export const dashboardPaneSource: PaneDefinition = {
1515
},
1616
render: (subject, dom) => {
1717
const container = dom.createElement('div')
18-
UI.authn.solidAuthClient.trackSession(async (session: SolidSession) => {
18+
authn.solidAuthClient.trackSession(async (session: SolidSession) => {
1919
container.innerHTML = ''
2020
buildPage(container, session ? sym(session.webId) : null, dom, subject)
2121
})
@@ -51,7 +51,7 @@ function buildHomePage (container: HTMLElement, subject: NamedNode) {
5151
link.rel = 'stylesheet'
5252
link.href = '/common/css/bootstrap.min.css'
5353
shadow.appendChild(link)
54-
generateHomepage(subject, UI.store, UI.store.fetcher).then(homepage =>
54+
generateHomepage(subject, store, store.fetcher).then(homepage =>
5555
shadow.appendChild(homepage)
5656
)
5757
}

src/dashboard/homepage.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Fetcher, IndexedFormula, NamedNode, sym } from 'rdflib'
2-
import UI from 'solid-ui'
3-
4-
const ns = UI.ns
2+
import { ns } from 'solid-ui'
53

64
export async function generateHomepage (
75
subject: NamedNode,

src/dashboard/trustedApplications/trustedApplicationsPane.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import UI from 'solid-ui'
2-
import { NamedNode, IndexedFormula, sym } from 'rdflib'
3-
4-
import { Namespaces } from 'solid-namespace'
1+
import { authn, ns, store, widgets } from 'solid-ui'
2+
import { NamedNode, sym } from 'rdflib'
53

64
import {
75
getStatementsToAdd,
86
getStatementsToDelete
97
} from './trustedApplicationsUtils'
108

11-
const kb: IndexedFormula = UI.store
12-
const ns: Namespaces = UI.ns
13-
149
const thisColor = '#418d99'
1510

1611
interface FormElements {
@@ -38,18 +33,18 @@ export function renderTrustedApplicationsOptions (dom: HTMLDocument) {
3833
statusArea.setAttribute('style', 'padding: 0.7em;')
3934

4035
const context = { dom: dom, div: main, statusArea: statusArea, me: null }
41-
UI.authn.logInLoadProfile(context).then(
36+
authn.logInLoadProfile(context).then(
4237
(context: any) => {
4338
let subject: NamedNode = context.me
4439

4540
const profile = subject.doc()
46-
const editable = UI.store.updater.editable(profile.uri, kb)
41+
const editable = store.updater.editable(profile.uri, store)
4742

4843
main.appendChild(createText('h3', 'Manage your trusted applications'))
4944

5045
if (!editable) {
5146
main.appendChild(
52-
UI.widgets.errorMessageBlock(
47+
widgets.errorMessageBlock(
5348
dom,
5449
`Your profile ${
5550
subject.doc().uri
@@ -91,7 +86,7 @@ export function renderTrustedApplicationsOptions (dom: HTMLDocument) {
9186
)
9287
},
9388
(err: any) => {
94-
statusArea.appendChild(UI.widgets.errorMessageBlock(dom, err))
89+
statusArea.appendChild(widgets.errorMessageBlock(dom, err))
9590
}
9691
)
9792
return div
@@ -111,12 +106,12 @@ function createApplicationTable (subject: NamedNode) {
111106
applicationsTable.appendChild(header)
112107

113108
// creating rows
114-
;(kb.each(subject, ns.acl('trustedApp'), undefined, undefined) as any)
109+
;(store.each(subject, ns.acl('trustedApp'), undefined, undefined) as any)
115110
.flatMap((app: any) => {
116-
return kb
111+
return store
117112
.each(app, ns.acl('origin'), undefined, undefined)
118113
.map(origin => ({
119-
appModes: kb.each(app, ns.acl('mode'), undefined, undefined),
114+
appModes: store.each(app, ns.acl('mode'), undefined, undefined),
120115
origin
121116
}))
122117
})
@@ -242,7 +237,7 @@ function createApplicationEntry (
242237
const deletions = getStatementsToDelete(
243238
trustedApplicationState.origin || origin,
244239
subject,
245-
kb,
240+
store,
246241
ns
247242
)
248243
const additions = getStatementsToAdd(
@@ -252,7 +247,7 @@ function createApplicationEntry (
252247
subject,
253248
ns
254249
)
255-
;(kb as any).updater.update(deletions, additions, handleUpdateResponse)
250+
;(store as any).updater.update(deletions, additions, handleUpdateResponse)
256251
}
257252

258253
function removeApplication (event: Event) {
@@ -266,8 +261,8 @@ function createApplicationEntry (
266261
)
267262
}
268263

269-
const deletions = getStatementsToDelete(origin, subject, kb, ns)
270-
;(kb as any).updater.update(deletions, [], handleUpdateResponse)
264+
const deletions = getStatementsToDelete(origin, subject, store, ns)
265+
;(store as any).updater.update(deletions, [], handleUpdateResponse)
271266
}
272267

273268
function handleUpdateResponse (uri: any, success: boolean, errorBody: any) {

src/home/homePane.source.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
*/
1010

1111
import { PaneDefinition } from '../types'
12-
import * as UI from 'solid-ui'
12+
import { authn, create, icons } from 'solid-ui'
1313
import * as panes from 'pane-registry'
1414

1515
const HomePaneSource: PaneDefinition = {
16-
icon: UI.icons.iconBase + 'noun_547570.svg', // noun_25830
16+
icon: icons.iconBase + 'noun_547570.svg', // noun_25830
1717

1818
global: true,
1919

@@ -48,28 +48,26 @@ const HomePaneSource: PaneDefinition = {
4848
statusArea: div,
4949
me: me
5050
}
51-
const relevantPanes = await UI.authn.filterAvailablePanes(panes.list)
52-
UI.create.newThingUI(creationContext, relevantPanes) // newUI Have to pass panes down
51+
const relevantPanes = await authn.filterAvailablePanes(panes.list)
52+
create.newThingUI(creationContext, relevantPanes) // newUI Have to pass panes down
5353

5454
div.appendChild(dom.createElement('h4')).textContent = 'Private things'
5555
// TODO: Replace by a common, representative interface
5656
type AuthContext = unknown
57-
UI.authn
57+
authn
5858
.registrationList(context, { private: true })
5959
.then(function (context: AuthContext) {
6060
div.appendChild(dom.createElement('h4')).textContent = 'Public things'
6161
div.appendChild(dom.createElement('p')).textContent =
6262
'Things in this list are visible to others.'
63-
UI.authn
64-
.registrationList(context, { public: true })
65-
.then(function () {
66-
// done
67-
})
63+
authn.registrationList(context, { public: true }).then(function () {
64+
// done
65+
})
6866
})
6967
}
7068

7169
var div = dom.createElement('div')
72-
var me = UI.authn.currentUser()
70+
var me = authn.currentUser()
7371

7472
showContent()
7573

0 commit comments

Comments
 (0)