Skip to content

Commit 16fb724

Browse files
committed
Handle empty recent activity via central dispatcher
Refactored recent activity notification to use TPEN.eventDispatcher for signaling no recent projects. ProjectsListNavigation now listens for this event and displays the welcome/empty state message accordingly. Improved rendering logic to ensure correct display of welcome message and project list.
1 parent 0b32728 commit 16fb724

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

components/continue-working/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ class ContinueWorking extends HTMLElement {
7676

7777
// If there are no recent projects, notify parent via custom event
7878
if (recentProjects.length === 0) {
79-
this.dispatchEvent(new CustomEvent('tpen-no-recent-activity', {
80-
bubbles: true,
81-
composed: true
82-
}))
79+
TPEN.eventDispatcher.dispatch('tpen-no-recent-activity')
8380
return
8481
}
8582

components/projects/list-navigation.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ export default class ProjectsListNavigation extends HTMLElement {
123123
this.shadowRoot.getElementById('projectsListView').innerHTML = `No projects found`
124124
}
125125
})
126+
127+
// Handle empty recent activity signal from other components via central dispatcher
128+
TPEN.eventDispatcher.on('tpen-no-recent-activity', () => {
129+
// Show the welcome/empty state message
130+
this.projects = []
131+
})
126132
}
127133
async connectedCallback() {
128134
TPEN.attachAuthentication(this)
@@ -135,22 +141,39 @@ export default class ProjectsListNavigation extends HTMLElement {
135141
return this.#projects
136142
}
137143
async render() {
138-
let list = this.shadowRoot.getElementById('projectsListView')
144+
const root = this.shadowRoot
145+
let list = root.getElementById('projectsListView')
139146
if (!this.#projects?.length) {
140-
list.innerHTML = `
141-
<section class="welcome-message">
147+
const welcome = document.createElement('section')
148+
welcome.className = 'welcome-message'
149+
welcome.innerHTML = `
142150
<p><strong>Welcome to TPEN!</strong></p>
143151
<p>Get started by creating your first project or importing a manuscript.</p>
144152
<ul class="welcome-list">
145153
<li aria-label="View Tutorials"><span aria-hidden="true">📚</span> <a href="https://three.t-pen.org/category/tutorials/" target="_blank" rel="noopener noreferrer">View Tutorials</a></li>
146154
<li aria-label="Frequently Asked Questions"><span aria-hidden="true">❓</span> <a href="https://three.t-pen.org/faq/" target="_blank" rel="noopener noreferrer">Frequently Asked Questions</a></li>
147155
<li aria-label="Find IIIF Resources"><span aria-hidden="true">🖼️</span> <a href="https://iiif.io/guides/finding_resources/" target="_blank" rel="noopener noreferrer">Find IIIF Resources</a></li>
148156
</ul>
149-
</section>
150157
`
158+
if (list) list.replaceWith(welcome)
159+
else {
160+
const existingWelcome = root.querySelector('section.welcome-message')
161+
if (existingWelcome) existingWelcome.replaceWith(welcome)
162+
else root.appendChild(welcome)
163+
}
151164
return
152165
}
153-
list.innerHTML = ""
166+
// Ensure the list element exists when we have projects
167+
if (!list) {
168+
list = document.createElement('ol')
169+
list.id = 'projectsListView'
170+
if (this.classList.contains('unbounded')) list.classList.add('unbounded')
171+
const existingWelcome = root.querySelector('section.welcome-message')
172+
if (existingWelcome) existingWelcome.replaceWith(list)
173+
else root.appendChild(list)
174+
} else {
175+
list.innerHTML = ""
176+
}
154177
for (const project of this.#projects) {
155178
await(new Project(project._id).fetch())
156179
const isManageProjectPermission = await CheckPermissions.checkEditAccess('PROJECT')

0 commit comments

Comments
 (0)