Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions ui-packages/web/src/data/project-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ export const touchProject = async (id: string) => {
}

// A project is deleted by the page that opens after the request, before it opens any library, so
// only another tab can hold the library open. The library goes first: if it cannot be deleted,
// the project stays listed and can be retried.
// only another tab can hold the library open. The project leaves the registry first, so nothing
// opens it while its library waits for those tabs: an open would queue behind the deletion and
// never finish. Deleting the library is cleanup; if it never completes, an unlisted library is
// left taking space and nothing else.
export const deleteProject = async (project: Project, onBlocked: () => void) => {
await deleteIndexedDatabase(project.databaseName, onBlocked)
const database = await openRegistry()
await database.delete('projects', project.id)
Object.values(workspaceStorageBases).forEach(base => {
localStorage.removeItem(workspaceStorageKey(base, project.databaseName))
})
const database = await openRegistry()
await database.delete('projects', project.id)
await deleteIndexedDatabase(project.databaseName, onBlocked)
}

const pendingDeletionKey = 'gamma-reader.pending-deletion'
Expand Down
22 changes: 20 additions & 2 deletions ui-packages/web/src/shell/projects.integration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, within } from '@testing-library/react'
import { cleanup, render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { openDB } from 'idb'
import { beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -94,7 +94,8 @@ describe('projects', () => {
it('deletes only what this tab asked for, once other tabs let go of it', async () => {
const birds = await createProject('Bird notes')
const page = visit(projectDeletionPath(birds.id))
await screen.findByRole('list', { name: 'Files' })
// Which project opens depends on recency, and a new one is empty, so wait for the panel only.
await screen.findByRole('complementary', { name: 'Files' })
expect(await getProject(birds.id)).not.toBeNull()
page.unmount()
await closeWorkspaceDatabase()
Expand All @@ -110,6 +111,23 @@ describe('projects', () => {
expect(await getProject(birds.id)).toBeNull()
})

it('opens another project when the address names one whose deletion is still waiting', async () => {
const birds = await createProject('Bird notes')
// Another tab holds the library, so its deletion waits.
const otherTab = await openDB(birds.databaseName)
schedulePendingDeletion(birds.id)
visit(projectDeletionPath(birds.id))
expect(
await screen.findByText('Waiting for other tabs that have Bird notes open to close.'),
).toBeVisible()

// The project is already gone, so its address leads elsewhere instead of to a blank page.
cleanup()
visit(`/p/${birds.id}`)
expect(await screen.findByRole('button', { name: 'My reading' })).toBeInTheDocument()
otherTab.close()
})

it('waits for an older tab to let go before upgrading the library, then opens it', async () => {
const birds = await createProject('Bird notes')
// An older page still holds the version-six library and does not know to let go.
Expand Down