Skip to content

Commit 6c2c9ed

Browse files
committed
implemneted code review feedback & updated logic
1 parent 6d61d9d commit 6c2c9ed

16 files changed

Lines changed: 201 additions & 98 deletions

File tree

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060
"jss": "^10.9.0",
6161
"jss-preset-default": "^10.9.0",
6262
"mime-types": "^2.1.34",
63-
"pane-registry": "^2.4.6-d45208e6",
63+
"pane-registry": "^2.4.6-07d72540",
6464
"path-browserify": "^1.0.1",
6565
"postcss-flexbugs-fixes": "^5.0.2",
6666
"rdflib": "^2.2.17",
67-
"solid-logic": "^1.3.13-2e3e7417",
67+
"solid-logic": "^1.3.13-438dc3ae",
6868
"solid-namespace": "^0.5.2",
6969
"stream-browserify": "^3.0.0",
7070
"uuid": "^8.3.2"

src/acl/add-agent-buttons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NamedNode, Store } from 'rdflib'
77
import { AuthenticationContext } from 'solid-logic'
88
import * as debug from '../debug'
99
import { icons } from '../iconBase'
10-
import { logInLoadProfile } from '../login/login'
10+
import { ensureLoadedProfile } from '../login/login'
1111
import * as ns from '../ns'
1212
import * as utils from '../utils'
1313
import * as widgets from '../widgets'
@@ -184,7 +184,7 @@ export class AddAgentButtons {
184184
}
185185

186186
private async renderAppsTable (eventContext: AuthenticationContext): Promise<string> {
187-
await logInLoadProfile(eventContext)
187+
await ensureLoadedProfile(eventContext)
188188
const trustedApps = (this.groupList.store as Store).each(eventContext.me, ns.acl('trustedApp')) as Array<NamedNode> // @@ TODO fix as
189189
const trustedOrigins = trustedApps.flatMap(app => (this.groupList.store as Store).each(app, ns.acl('origin'))) // @@ TODO fix as
190190

src/create/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DataBrowserContext, NewPaneOptions, PaneDefinition } from 'pane-registr
66
import { solidLogicSingleton } from 'solid-logic'
77
import * as debug from '../debug'
88
import { icons } from '../iconBase'
9-
import { logInLoadProfile, selectWorkspace } from '../login/login'
9+
import { ensureLoadedProfile, selectWorkspace } from '../login/login'
1010
import * as ns from '../ns'
1111
import * as utils from '../utils'
1212
import * as widgets from '../widgets'
@@ -78,7 +78,7 @@ export function newThingUI (
7878
return new Promise(function (resolve, reject) {
7979
let selectUI // , selectUIParent
8080
function callbackWS (ws, newBase) {
81-
logInLoadProfile(createContext).then(
81+
ensureLoadedProfile(createContext).then(
8282
_context => {
8383
const newPaneOptions: NewPaneOptions = Object.assign({
8484
newBase: newBase,

src/index.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,13 @@ https://github.com/solid/solid
3131
* @main solidUi.js
3232
*/
3333

34-
/**
35-
* @class SolidUi
36-
* @static
37-
*/
38-
3934
// REMOVE @ts-ignore as you migrate files to TypeScript
4035
import * as rdf from 'rdflib' // pull in first avoid cross-refs
4136
// @ts-ignore
4237
import * as ns from './ns'
4338
import { acl, aclControl } from './acl/index'
4439
import { create } from './create/index'
4540
// @ts-ignore
46-
// import * as debug from '../debug'
47-
// @ts-ignore
4841
import { icons } from './iconBase'
4942
import * as language from './widgets/forms/autocomplete/language'
5043
import * as log from './log'
@@ -61,7 +54,6 @@ import * as participation from './participation'
6154
// @ts-ignore
6255
import * as preferences from './preferences'
6356
// @ts-ignore
64-
// @ts-ignore
6557
import * as style from './style'
6658
// @ts-ignore
6759
import { renderTableViewPane as table } from './table'
@@ -74,13 +66,15 @@ import versionInfo from './versionInfo'
7466
import { initHeader } from './header'
7567
import { initFooter } from './footer'
7668
import * as createTypes from './create/types'
77-
import * as solidLogicLib from 'solid-logic'
69+
import { authn, store, authSession } from 'solid-logic'
7870

7971
const dom = window ? window.document : null // Idea that UI.dom can be adapted in non-browser environments
8072

8173
if (typeof window !== 'undefined') {
8274
;(<any>window).UI = {
83-
solidLogicLib,
75+
authn,
76+
store,
77+
authSession,
8478
ns,
8579
rdf,
8680
acl,
@@ -111,7 +105,6 @@ if (typeof window !== 'undefined') {
111105
}
112106

113107
export {
114-
solidLogicLib,
115108
ns,
116109
rdf,
117110
acl,

src/login/login.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import * as widgets from '../widgets'
3737
*
3838
* @param context
3939
*/
40-
export function loggedInContext (context: AuthenticationContext): Promise<AuthenticationContext> {
40+
// used to be logIn
41+
export function ensureLoggedIn (context: AuthenticationContext): Promise<AuthenticationContext> {
4142
const me = authn.currentUser()
4243
if (me) {
4344
authn.saveUser(me, context)
@@ -71,8 +72,8 @@ export function loggedInContext (context: AuthenticationContext): Promise<Authen
7172
*
7273
* @param context
7374
*/
74-
export async function logInLoadPreferences (context: AuthenticationContext): Promise<AuthenticationContext> {
75-
// console.log('Solid UI logInLoadPreferences')
75+
// used to be logInLoadPreferences
76+
export async function ensureLoadedPreferences (context: AuthenticationContext): Promise<AuthenticationContext> {
7677
if (context.preferencesFile) return Promise.resolve(context) // already done
7778

7879
const statusArea = context.statusArea || context.div || null
@@ -89,7 +90,7 @@ export async function logInLoadPreferences (context: AuthenticationContext): Pro
8990
// reject(new Error(message))
9091
}
9192
try {
92-
context = await logInLoadProfile(context)
93+
context = await ensureLoadedProfile(context)
9394

9495
// console.log('back in Solid UI after logInLoadProfile', context)
9596
const preferencesFile = await solidLogicSingleton.loadPreferences(context.me as NamedNode)
@@ -140,13 +141,13 @@ export async function logInLoadPreferences (context: AuthenticationContext): Pro
140141
*
141142
* @returns Resolves with the context after login / fetch
142143
*/
143-
export async function logInLoadProfile (context: AuthenticationContext): Promise<AuthenticationContext> {
144-
// console.log('Solid UI logInLoadProfile')
144+
// used to be logInLoadProfile
145+
export async function ensureLoadedProfile (context: AuthenticationContext): Promise<AuthenticationContext> {
145146
if (context.publicProfile) {
146147
return context
147148
} // already done
148149
try {
149-
const logInContext = await loggedInContext(context)
150+
const logInContext = await ensureLoggedIn(context)
150151
if (!logInContext.me) {
151152
throw new Error('Could not log in')
152153
}
@@ -188,8 +189,8 @@ export async function findAppInstances (
188189
try {
189190
// console.log('calling logInLoad', isPublic)
190191
await (isPublic
191-
? logInLoadProfile(context)
192-
: logInLoadPreferences(context))
192+
? ensureLoadedProfile(context)
193+
: ensureLoadedPreferences(context))
193194
// console.log('called logInLoad', isPublic)
194195
} catch (err) {
195196
widgets.complain(context, `loadIndex: login and load problem ${err}`)
@@ -972,7 +973,7 @@ export function selectWorkspace (
972973
} // displayOptions
973974

974975
// console.log('kicking off async operation')
975-
logInLoadPreferences(context) // kick off async operation
976+
ensureLoadedPreferences(context) // kick off async operation
976977
.then(displayOptions)
977978
.catch(err => {
978979
// console.log("err from async op")
@@ -1028,7 +1029,7 @@ export async function getUserRoles (): Promise<Array<NamedNode>> {
10281029
me,
10291030
preferencesFile,
10301031
preferencesFileError
1031-
} = await logInLoadPreferences({})
1032+
} = await ensureLoadedPreferences({})
10321033
if (!preferencesFile || preferencesFileError) {
10331034
throw new Error(preferencesFileError)
10341035
}

src/messageArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function messageArea (dom, kb, subject, messageStore, options) {
171171
}
172172

173173
const context = { div: middle, dom: dom }
174-
login.loggedInContext(context).then(context => {
174+
login.ensureLoggedIn(context).then(context => {
175175
me = context.me
176176
turnOnInput()
177177
})

src/preferences.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as $rdf from 'rdflib' // pull in first avoid cross-refs
66
import { store } from 'solid-logic'
77
import * as debug from './debug'
8-
import { logInLoadPreferences } from './login/login'
8+
import { ensureLoadedPreferences } from './login/login'
99
import * as ns from './ns'
1010
import * as participation from './participation' // @ts-ignore
1111
import * as widgets from './widgets'
@@ -65,7 +65,7 @@ export function recordSharedPreferences (subject, context) {
6565
//
6666
export function recordPersonalDefaults (theClass, context) {
6767
return new Promise(function (resolve, reject) {
68-
logInLoadPreferences(context).then(
68+
ensureLoadedPreferences(context).then(
6969
context => {
7070
if (!context.preferencesFile) {
7171
debug.log(

src/widgets/forms/autocomplete/language.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function addDefaults (array) {
3333

3434
export async function getPreferredLanguagesFor (person: NamedNode) {
3535
const doc = person.doc()
36-
await store.fetcher.load(doc)
36+
await store.fetcher?.load(doc)
3737
const list = store.any(person, ns.schema('knowsLanguage'), null, doc) as Collection | undefined
3838
if (!list) {
3939
// console.log(`User ${person} has not set their languages in their profile.`)

src/widgets/forms/autocomplete/publicData.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ export async function queryESCODataByName (filter: string, theClass:NamedNode, q
283283
.replace('$(targetClass)', theClass.toNT())
284284
debug.log('Querying ESCO data - uri: ' + queryURI)
285285

286-
const response = await store.fetcher.webOperation('GET', queryURI, fetcherOptionsJsonPublicData)
287-
const text = response.responseText || ''
286+
const response = await store.fetcher?.webOperation('GET', queryURI, fetcherOptionsJsonPublicData)
287+
const text = response?.responseText || ''
288288
debug.log(' Query result text' + text.slice(0, 500) + '...')
289289
if (text.length === 0) throw new Error('Wot no text back from ESCO query ' + queryURI)
290290
const json = JSON.parse(text)
@@ -336,7 +336,7 @@ export async function queryPublicDataByName (
336336
const queryURI = substituteStrings(queryTarget.searchByNameURI)
337337
let response
338338
try {
339-
response = await store.fetcher.webOperation('GET', queryURI, fetcherOptionsJsonPublicData)
339+
response = await store.fetcher?.webOperation('GET', queryURI, fetcherOptionsJsonPublicData)
340340
} catch (err) {
341341
throw new Error(`Exception when trying to fetch ${queryURI} \n ${err}`)
342342
}
@@ -377,7 +377,7 @@ export async function queryPublicDataSelect (sparql: string, queryTarget: QueryP
377377
headers: headers
378378
}
379379

380-
const response = await store.fetcher.webOperation('GET', queryURI, options)
380+
const response = await store.fetcher?.webOperation('GET', queryURI, options)
381381

382382
const text = response?.responseText || ''
383383
if (text.length === 0) throw new Error('No text back from query ' + queryURI)
@@ -403,8 +403,8 @@ export async function queryPublicDataConstruct (sparql: string, pubicId: NamedNo
403403
credentials: 'omit' as 'include' | 'omit' | undefined, // CORS // @tsc pain
404404
headers: headers // ({ Accept: 'text/turtle' } as Headers)
405405
}
406-
const response = await store.fetcher.webOperation('GET', queryURI, options)
407-
const text = response.responseText || 'No response text?'
406+
const response = await store.fetcher?.webOperation('GET', queryURI, options)
407+
const text = response?.responseText || 'No response text?'
408408
const report = text.length > 500 ? text.slice(0, 200) + ' ... ' + text.slice(-200) : text
409409
debug.log(' queryPublicDataConstruct result text:' + report)
410410
if (text.length === 0) throw new Error('queryPublicDataConstruct: No text back from construct query:' + queryURI)

0 commit comments

Comments
 (0)