Skip to content

Commit

Permalink
Placeholders now appear in empty sections
Browse files Browse the repository at this point in the history
For example if there are no unsaved sessions then a placeholder appears with image and text as per material design's 'empty state' guidelines.
  • Loading branch information
homostellaris committed Nov 12, 2021
1 parent 6598924 commit 06cd693
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/ui/SessionManager/createSessionCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import SessionManager from './index.js'
const unsavedSessionsHeader = document.getElementById('unsaved')
const unshelvedSessionsHeader = document.getElementById('unshelved')
const shelvedSessionsHeader = document.getElementById('shelved')
const sessionHeaders = {
'unsaved': unsavedSessionsHeader,
'unshelved': unshelvedSessionsHeader,
'shelved': shelvedSessionsHeader,
}

async function createSessionCards () {
await createUnsavedSessionCards()
Expand All @@ -25,6 +30,8 @@ async function createUnsavedSessionCards () {
)
unsavedSessionsHeader.after(sessionCard)
})

if (!unsavedSessions.length) createPlaceholder('unsaved')
}

async function createUnshelvedSessionCards () {
Expand All @@ -41,6 +48,8 @@ async function createUnshelvedSessionCards () {
)
unshelvedSessionsHeader.after(sessionCard)
})

if (!unshelvedSessions.length) createPlaceholder('unshelved')
}

async function createShelvedSessionCards () {
Expand All @@ -56,6 +65,8 @@ async function createShelvedSessionCards () {
)
shelvedSessionsHeader.after(sessionCard)
})

if (!shelvedSessions.length) createPlaceholder('shelved')
}

async function addTabIndex () {
Expand Down Expand Up @@ -121,4 +132,14 @@ function getSessionInnerHtml (name, tabsCount, thumbnailUrl) {
return innerHtml
}

function createPlaceholder (type) {
const placeholder = document.createElement('div')
placeholder.classList.add('placeholder')
placeholder.innerHTML = `
<img src="/ui/status/${type}.png" width="60px"><span>You have no ${type} sessions.</span>
`
const sessionHeader = sessionHeaders[type]
sessionHeader.after(placeholder)
}

export default createSessionCards
1 change: 1 addition & 0 deletions src/ui/SessionManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class UnshelvedSessionManager extends OpenSessionManager {
async remove () {
await chrome.windows.remove(this.windowId)
// Event listener in worker will remove window ID from storage to stop tracking as an open saved session.
await bookmarks.removeFolder(this.bookmarkFolderId)
this.sessionCard.remove()
}

Expand Down
15 changes: 15 additions & 0 deletions src/ui/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ a {
height: auto !important;
width: 100%; /* Allows full width text input. */
}

.placeholder {
align-items: center;
color: grey;
display: flex;
height: 60px;
justify-content: center;
text-align: center;
}

.placeholder img {
width: 25px;
height: 25px;
margin: 0 5px;
}
2 changes: 1 addition & 1 deletion src/ui/status/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function saved () {
chrome.action.setIcon({path: '../ui/status/saved.png'})
chrome.action.setIcon({path: '../ui/status/unshelved.png'})
}

function saving () {
Expand Down
Binary file added src/ui/status/shelved.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
24 changes: 24 additions & 0 deletions test/sessionPersistence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ test('Saving, re-opening, then deleting sessions', async t => {
const sessionManagerTitle = await playwrightPage.title()
// This is breaking the fourth wall a bit because its actually a window with the session manager that we're making assertions against.
await tester.assertUnsavedSessions([sessionManagerTitle])
await tester.assertUnshelvedPlaceholderExists()
await tester.assertShelvedPlaceholderExists()

const [page, window] = await tester.createWindow()
await playwrightPage.reload() // TODO: Try replacing with page.waitForSelector(selector[, options])
Expand All @@ -78,6 +80,7 @@ test('Saving, re-opening, then deleting sessions', async t => {
await playwrightPage.reload()
await tester.assertUnsavedSessions([sessionManagerTitle])
await tester.assertUnshelvedSessions([])
await tester.assertUnshelvedPlaceholderExists()
await tester.assertShelvedSessions([savedSessionName])

const updatedSessionName = 'Test session updated'
Expand All @@ -95,6 +98,7 @@ test('Saving, re-opening, then deleting sessions', async t => {
await tester.assertUnsavedSessions([sessionManagerTitle])
await tester.assertUnshelvedSessions([updatedSessionName])
await tester.assertShelvedSessions([])
await tester.assertShelvedPlaceholderExists()
const unshelvedSessionWindow = await tester.getCurrentWindow()
await tester.assertWindowTabUrls(unshelvedSessionWindow, urls)

Expand All @@ -106,9 +110,12 @@ test('Saving, re-opening, then deleting sessions', async t => {
await playwrightPage.waitForTimeout(1000) // TODO: Find out how to properly wait for resumed session ID to be added to mapping.
t.is((await tester.getWindows()).length, 1)

await playwrightPage.reload()
await tester.assertUnsavedSessions([sessionManagerTitle])
await tester.assertUnshelvedSessions([])
await tester.assertShelvedSessions([])
await tester.assertUnshelvedPlaceholderExists()
await tester.assertShelvedPlaceholderExists()
})

test.todo('Saving, re-opening, then deleting sessions (with keyboard shortcuts)')
Expand Down Expand Up @@ -142,6 +149,23 @@ class SessionManagerTester {
this.avaExecutionContext.deepEqual(actualSessionNames, expectedSessionNames)
}

async assertUnsavedPlaceholderExists () {
await this.assertPlaceholderExists('unsaved')
}

async assertUnshelvedPlaceholderExists () {
await this.assertPlaceholderExists('unshelved')
}

async assertShelvedPlaceholderExists () {
await this.assertPlaceholderExists('shelved')
}

async assertPlaceholderExists (sessionType) {
const placeholder = await this.playwrightPage.$(`text=You have no ${sessionType} sessions.`)
this.avaExecutionContext.not(placeholder, null)
}

async createWindow() {
const [page, window] = await Promise.all([
this.avaExecutionContext.context.browserContext.waitForEvent('page'),
Expand Down

0 comments on commit 06cd693

Please sign in to comment.