Skip to content

Commit dafb3ad

Browse files
committed
fix the logged in profile display from header menu
1 parent e9194a5 commit dafb3ad

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

src/mainPage/header.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ function attachHeaderListeners (header: ManagedHeader) {
124124
// Do not navigate to the profile after logout.
125125
} else if (detail?.action === 'show-profile') {
126126
// TODO see if this can be consolidated
127-
if (authn.currentUser()) {
128-
outliner.showDashboard({ pane: 'profile' })
127+
const currentUser = authn.currentUser()
128+
if (currentUser) {
129+
outliner.showDashboard(currentUser, { pane: 'profile' })
129130
}
130131
}
131132
})

src/outline/manager.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -491,30 +491,42 @@ export default function (context) {
491491
* @param {string} [options.pane] To open a specific dashboard pane
492492
* @returns {Promise<void>}
493493
*/
494-
async function showDashboard (subject, options = {}) {
494+
function closeDashboard () {
495495
const dashboardContainer = getDashboardContainer()
496496
const outlineContainer = getOutlineContainer()
497+
dashboardContainer.innerHTML = ''
498+
hideGlobalContainer(dashboardContainer)
499+
showGlobalContainer(outlineContainer)
500+
}
497501

498-
function showContainer (container) {
499-
container.removeAttribute('hidden')
500-
container.style.display = ''
501-
}
502+
// Register the closeDashboard listener only once
503+
authSession.events.on('logout', closeDashboard)
502504

503-
function hideContainer (container) {
504-
container.setAttribute('hidden', '')
505-
container.style.display = 'none'
506-
}
505+
function showGlobalContainer (container) {
506+
container.removeAttribute('hidden')
507+
container.style.display = ''
508+
}
509+
510+
function hideGlobalContainer (container) {
511+
container.setAttribute('hidden', '')
512+
container.style.display = 'none'
513+
}
507514

508-
// reuse existing dashboard if already rendered for the requested pane
515+
async function showDashboard (subject, options = {}) {
516+
const dashboardContainer = getDashboardContainer()
517+
const outlineContainer = getOutlineContainer()
518+
519+
// reuse existing dashboard if already rendered for the same pane and subject
509520
if (dashboardContainer.childNodes.length > 0) {
510521
const existingDashboard = dashboardContainer.firstElementChild
511522
if (
512523
existingDashboard &&
513524
options.pane &&
514-
existingDashboard.dataset.globalPaneName === options.pane
525+
existingDashboard.dataset.globalPaneName === options.pane &&
526+
existingDashboard.dataset.subject === (subject && subject.value || '')
515527
) {
516-
hideContainer(outlineContainer)
517-
showContainer(dashboardContainer)
528+
hideGlobalContainer(outlineContainer)
529+
showGlobalContainer(dashboardContainer)
518530
return
519531
}
520532
dashboardContainer.innerHTML = ''
@@ -529,18 +541,15 @@ export default function (context) {
529541
}
530542
)
531543

532-
// close the dashboard if user log out
533544
authSession.events.on('logout', closeDashboard)
545+
if (subject && subject.value) {
546+
dashboard.dataset.subject = subject.value
547+
}
534548

535549
// finally - switch to showing dashboard
536-
hideContainer(outlineContainer)
537-
showContainer(dashboardContainer)
550+
hideGlobalContainer(outlineContainer)
551+
showGlobalContainer(dashboardContainer)
538552
dashboardContainer.appendChild(dashboard)
539-
540-
function closeDashboard () {
541-
hideContainer(dashboardContainer)
542-
showContainer(outlineContainer)
543-
}
544553
}
545554
this.showDashboard = showDashboard
546555

0 commit comments

Comments
 (0)