@@ -278,45 +278,21 @@ module.exports = function (doc) {
278278 console . log ( 'globalAppTabs @@' )
279279 const div = dom . createElement ( 'div' )
280280 const me = UI . authn . currentUser ( )
281- var items = [ // {paneName: 'folder', label: 'Your files', subject: me.site()}, // replaced with storages
282- { paneName : 'home' , label : 'Your stuff' , icon : UI . icons . iconBase + 'noun_547570.svg' } ,
283- { paneName : 'basicPreferences' , label : 'Preferences' , icon : UI . icons . iconBase + 'noun_Sliders_341315_00000.svg' } ,
284- { paneName : 'trustedApplications' , label : 'Trusted Apps' , icon : UI . icons . iconBase + 'noun_15177.svg.svg' } ,
285- { paneName : 'editProfile' , label : 'Edit your profile' , icon : UI . icons . iconBase + 'noun_492246.svg' }
286- ]
287-
288281 if ( ! me ) {
289282 alert ( 'Must be logged in for this' )
290283 throw new Error ( 'Not logged in' )
291284 }
292- var context = { me, div, dom}
293- try {
294- context = await UI . authn . findAppInstances ( context , ns . vcard ( 'AddressBook' ) )
295- if ( context . instances ) {
296- for ( var book of context . instances ) {
297- items . push ( { paneName : 'contact' , label : 'Contacts' , subject : book , icon : UI . icons . iconBase + 'noun_15695.svg' } )
298- console . log ( ` Adding address book ${ book } to dashboard` )
299- }
300- }
301- } catch ( err ) {
302- console . error ( 'oops in globalAppTabs AddressBook' )
303- }
304-
305- const storages = kb . each ( me , ns . space ( 'storage' ) , null , me . doc ( ) )
306- for ( var pod of storages ) {
307- var label = storages . length > 1 ? pod . uri . split ( '//' ) [ 1 ] . slice ( 0 , - 1 ) : 'Your storage'
308- items . push ( { paneName : 'folder' , label : label , subject : pod , icon : UI . icons . iconBase + 'noun_Cabinet_251723.svg' } )
309- }
285+ const items = await getDashboardItems ( )
310286
311287 function renderTab ( div , item ) {
312- div . dataset . name = item . paneName
288+ div . dataset . name = item . tabName || item . paneName
313289 div . textContent = item . label
314290 }
315291
316292 function renderMain ( containerDiv , item ) { // Items are pane names
317293 const pane = panes . byName ( item . paneName ) // 20190701
318294 containerDiv . innerHTML = ''
319- var table = containerDiv . appendChild ( dom . createElement ( 'table' ) )
295+ const table = containerDiv . appendChild ( dom . createElement ( 'table' ) )
320296 const me = UI . authn . currentUser ( )
321297 thisOutline . GotoSubject ( item . subject || me , true , pane , false , undefined , table )
322298 }
@@ -335,6 +311,50 @@ module.exports = function (doc) {
335311 return div
336312 }
337313
314+ async function getDashboardItems ( ) {
315+ const me = UI . authn . currentUser ( )
316+ const div = dom . createElement ( 'div' )
317+ return [
318+ { paneName : 'home' , label : 'Your stuff' , icon : UI . icons . iconBase + 'noun_547570.svg' } ,
319+ { paneName : 'basicPreferences' , label : 'Preferences' , icon : UI . icons . iconBase + 'noun_Sliders_341315_00000.svg' } ,
320+ { paneName : 'trustedApplications' , label : 'Trusted Apps' , icon : UI . icons . iconBase + 'noun_15177.svg.svg' } ,
321+ { paneName : 'editProfile' , label : 'Edit your profile' , icon : UI . icons . iconBase + 'noun_492246.svg' }
322+ ]
323+ . concat ( await getAddressBooks ( ) )
324+ . concat ( getPods ( ) )
325+
326+ function getPods ( ) {
327+ const pods = kb . each ( me , ns . space ( 'storage' ) , null , me . doc ( ) )
328+ return pods . map ( ( pod , index ) => {
329+ let label = pods . length > 1 ? pod . uri . split ( '//' ) [ 1 ] . slice ( 0 , - 1 ) : 'Your storage'
330+ return {
331+ paneName : 'folder' ,
332+ tabName : `folder-${ index } ` ,
333+ label,
334+ subject : pod ,
335+ icon : UI . icons . iconBase + 'noun_Cabinet_251723.svg'
336+ }
337+ } )
338+ }
339+
340+ async function getAddressBooks ( ) {
341+ try {
342+ const context = await UI . authn . findAppInstances ( { me, div, dom} , ns . vcard ( 'AddressBook' ) )
343+ return ( context . instances || [ ] ) . map ( ( book , index ) => ( {
344+ paneName : 'contact' ,
345+ tabName : `contact-${ index } ` ,
346+ label : 'Contacts' ,
347+ subject : book ,
348+ icon : UI . icons . iconBase + 'noun_15695.svg'
349+ } ) )
350+ } catch ( err ) {
351+ console . error ( 'oops in globalAppTabs AddressBook' )
352+ }
353+ return [ ]
354+ }
355+ }
356+ this . getDashboardItems = getDashboardItems
357+
338358 async function showDashboard ( container , unselectCurrentPane , globalPaneToSelect ) {
339359 container . innerHTML = ''
340360 // console.log(container)
0 commit comments