@@ -150,6 +150,7 @@ export function logIn (context: AuthenticationContext): Promise<AuthenticationCo
150150 * @returns Resolves with the context after login / fetch
151151 */
152152export async function logInLoadProfile ( context : AuthenticationContext ) : Promise < AuthenticationContext > {
153+ // console.log('Solid UI logInLoadProfile')
153154 if ( context . publicProfile ) {
154155 return context
155156 } // already done
@@ -158,7 +159,7 @@ export async function logInLoadProfile (context: AuthenticationContext): Promise
158159 if ( ! loggedInContext . me ) {
159160 throw new Error ( 'Could not log in' )
160161 }
161- context . publicProfile = solidLogicSingleton . loadProfile ( loggedInContext . me )
162+ context . publicProfile = await solidLogicSingleton . loadProfile ( loggedInContext . me )
162163 } catch ( err ) {
163164 if ( context . div && context . dom ) {
164165 context . div . appendChild (
@@ -178,67 +179,66 @@ export async function logInLoadProfile (context: AuthenticationContext): Promise
178179 *
179180 * @param context
180181 */
181- export function logInLoadPreferences ( context : AuthenticationContext ) : Promise < AuthenticationContext > {
182+ export async function logInLoadPreferences ( context : AuthenticationContext ) : Promise < AuthenticationContext > {
183+ // console.log('Solid UI logInLoadPreferences')
182184 if ( context . preferencesFile ) return Promise . resolve ( context ) // already done
183185
184186 const statusArea = context . statusArea || context . div || null
185187 let progressDisplay
186- return new Promise ( function ( resolve , reject ) {
187- function complain ( message ) {
188- message = `logInLoadPreferences: ${ message } `
189- if ( statusArea ) {
190- // statusArea.innerHTML = ''
191- statusArea . appendChild (
192- widgets . errorMessageBlock ( context . dom , message )
188+ function complain ( message ) {
189+ message = `logInLoadPreferences: ${ message } `
190+ if ( statusArea ) {
191+ // statusArea.innerHTML = ''
192+ statusArea . appendChild (
193+ widgets . errorMessageBlock ( context . dom , message )
194+ )
195+ }
196+ debug . log ( message )
197+ // reject(new Error(message))
198+ }
199+ try {
200+ context = await logInLoadProfile ( context )
201+
202+ // console.log('back in Solid UI after logInLoadProfile', context)
203+ const preferencesFile = await solidLogicSingleton . loadPreferences ( context . me )
204+ if ( progressDisplay ) {
205+ progressDisplay . parentNode . removeChild ( progressDisplay )
206+ }
207+ context . preferencesFile = preferencesFile
208+ } catch ( err ) {
209+ let m2 : string
210+ if ( err instanceof UnauthorizedError ) {
211+ m2 = 'Strange - you are not authenticated (properly logged in) to read preference file.'
212+ alert ( m2 )
213+ } else if ( err instanceof CrossOriginForbiddenError ) {
214+ m2 = `Unauthorized: Assuming preference file blocked for origin ${ window . location . origin } `
215+ context . preferencesFileError = m2
216+ return context
217+ } else if ( err instanceof SameOriginForbiddenError ) {
218+ m2 = 'You are not authorized to read your preference file. This may be because you are using an untrusted web app.'
219+ debug . warn ( m2 )
220+ } else if ( err instanceof NotFoundError ) {
221+ if (
222+ confirm ( `You do not currently have a preference file. OK for me to create an empty one? ${ ( err as any ) . preferencesFile || '' } ` )
223+ ) {
224+ // @@@ code me ... weird to have a name of the file but no file
225+ alert ( `Sorry; I am not prepared to do this. Please create an empty file at ${ ( err as any ) . preferencesFile || '(?)' } ` )
226+ complain (
227+ new Error ( 'Sorry; no code yet to create a preference file at ' )
228+ )
229+ } else {
230+ throw (
231+ new Error ( `User declined to create a preference file at ${ ( err as any ) . preferencesFile || '(?)' } ` )
193232 )
194233 }
195- debug . log ( message )
196- reject ( new Error ( message ) )
234+ } else if ( err instanceof FetchError ) {
235+ m2 = `Strange: Error ${ err . status } trying to read your preference file.${ err . message } `
236+ alert ( m2 )
237+ } else {
238+ throw new Error ( `(via loadPrefs) ${ err } ` )
197239 }
198- return logInLoadProfile ( context )
199- . then ( context => {
200- return solidLogicSingleton . loadPreferences ( context . me ) . then ( function ( preferencesFile ) {
201- if ( progressDisplay ) {
202- progressDisplay . parentNode . removeChild ( progressDisplay )
203- }
204- context . preferencesFile = preferencesFile
205- return resolve ( context )
206- } )
207- } )
208- . catch ( err => {
209- let m2 : string
210- if ( err instanceof UnauthorizedError ) {
211- m2 = 'Strange - you are not authenticated (properly logged in) to read preference file.'
212- alert ( m2 )
213- } else if ( err instanceof CrossOriginForbiddenError ) {
214- m2 = `Unauthorized: Assuming preference file blocked for origin ${ window . location . origin } `
215- context . preferencesFileError = m2
216- return resolve ( context )
217- } else if ( err instanceof SameOriginForbiddenError ) {
218- m2 = 'You are not authorized to read your preference file. This may be because you are using an untrusted web app.'
219- debug . warn ( m2 )
220- } else if ( err instanceof NotFoundError ) {
221- if (
222- confirm ( `You do not currently have a preference file. OK for me to create an empty one? ${ ( err as any ) . preferencesFile || '' } ` )
223- ) {
224- // @@@ code me ... weird to have a name of the file but no file
225- alert ( `Sorry; I am not prepared to do this. Please create an empty file at ${ ( err as any ) . preferencesFile || '(?)' } ` )
226- return complain (
227- new Error ( 'Sorry; no code yet to create a preference file at ' )
228- )
229- } else {
230- reject (
231- new Error ( `User declined to create a preference file at ${ ( err as any ) . preferencesFile || '(?)' } ` )
232- )
233- }
234- } else if ( err instanceof FetchError ) {
235- m2 = `Strange: Error ${ err . status } trying to read your preference file.${ err . message } `
236- alert ( m2 )
237- } else {
238- reject ( new Error ( `(via loadPrefs) ${ err } ` ) )
239- }
240- } )
241- } )
240+ }
241+ return context
242242}
243243
244244/**
@@ -372,22 +372,28 @@ export async function findAppInstances (
372372 theClass : NamedNode ,
373373 isPublic ?: boolean
374374) : Promise < AuthenticationContext > {
375+ // console.log('findAppInstances', { context, theClass, isPublic })
375376 if ( isPublic === undefined ) {
376377 // Then both public and private
378+ // console.log('finding public app instance')
377379 await findAppInstances ( context , theClass , true )
380+ // console.log('finding private app instance')
378381 await findAppInstances ( context , theClass , false )
382+ // console.log('found public & private app instance', context)
379383 return context
380384 }
381385
382386 // Loading preferences is more than loading profile
383387 try {
388+ // console.log('calling logInLoad', isPublic)
384389 await ( isPublic
385390 ? logInLoadProfile ( context )
386391 : logInLoadPreferences ( context ) )
392+ // console.log('called logInLoad', isPublic)
387393 } catch ( err ) {
388394 widgets . complain ( context , `loadIndex: login and load problem ${ err } ` )
389395 }
390-
396+ // console.log('awaited LogInLoad!', context)
391397 const visibility = isPublic ? 'public' : 'private'
392398 try {
393399 await loadIndex ( context , isPublic )
@@ -1102,6 +1108,7 @@ export function selectWorkspace (
11021108 }
11031109
11041110 function displayOptions ( context ) {
1111+ // console.log('displayOptions!', context)
11051112 async function makeNewWorkspace ( _event ) {
11061113 const row = table . appendChild ( dom . createElement ( 'tr' ) )
11071114 const cell = row . appendChild ( dom . createElement ( 'td' ) )
@@ -1269,9 +1276,11 @@ export function selectWorkspace (
12691276 table . appendChild ( trLast )
12701277 } // displayOptions
12711278
1279+ // console.log('kicking off async operation')
12721280 logInLoadPreferences ( context ) // kick off async operation
12731281 . then ( displayOptions )
12741282 . catch ( err => {
1283+ // console.log("err from async op")
12751284 box . appendChild ( widgets . errorMessageBlock ( context . dom , err ) )
12761285 } )
12771286
0 commit comments